• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ClassFileReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader的典型用法代码示例。如果您正苦于以下问题:Java ClassFileReader类的具体用法?Java ClassFileReader怎么用?Java ClassFileReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClassFileReader类属于org.eclipse.jdt.internal.compiler.classfmt包,在下文中一共展示了ClassFileReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: findType

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
@Override
public NameEnvironmentAnswer findType(final char[][] compoundTypeName) {
  try {
    final Function1<char[], String> _function = (char[] it) -> {
      return String.valueOf(it);
    };
    String _join = IterableExtensions.join(ListExtensions.<char[], String>map(((List<char[]>)Conversions.doWrapArray(compoundTypeName)), _function), "/");
    final String fileName = (_join + ".class");
    boolean _containsKey = this.cache.containsKey(fileName);
    if (_containsKey) {
      return this.cache.get(fileName);
    }
    final URL url = this.classLoader.getResource(fileName);
    if ((url == null)) {
      this.cache.put(fileName, null);
      return null;
    }
    final ClassFileReader reader = ClassFileReader.read(url.openStream(), fileName);
    final NameEnvironmentAnswer result = new NameEnvironmentAnswer(reader, null);
    this.cache.put(fileName, result);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:26,代码来源:InMemoryJavaCompiler.java


示例2: findClass

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
public NameEnvironmentAnswer findClass(
    String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName) {
  if (!isPackage(qualifiedPackageName)) return null; // most common case

  try {
    ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName);
    if (reader != null) {
      if (this.accessRuleSet == null) return new NameEnvironmentAnswer(reader, null);
      String fileNameWithoutExtension =
          qualifiedBinaryFileName.substring(
              0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length);
      return new NameEnvironmentAnswer(
          reader,
          this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()));
    }
  } catch (IOException | ClassFormatException e) { // treat as if class file is missing
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:ClasspathJar.java


示例3: findType

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
private NameEnvironmentAnswer findType(String className)
{
    if (className.equals(this.className))
    {
        return new NameEnvironmentAnswer(this, null);
    }

    String resourceName = className.replace('.', '/') + ".class";

    try (InputStream is = UDFunction.udfClassLoader.getResourceAsStream(resourceName))
    {
        if (is != null)
        {
            byte[] classBytes = ByteStreams.toByteArray(is);
            char[] fileName = className.toCharArray();
            ClassFileReader classFileReader = new ClassFileReader(classBytes, fileName, true);
            return new NameEnvironmentAnswer(classFileReader, null);
        }
    }
    catch (IOException | ClassFormatException exc)
    {
        throw new RuntimeException(exc);
    }
    return null;
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:26,代码来源:JavaBasedUDFunction.java


示例4: getJarBinaryTypeInfo

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException {
	JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
	ZipFile zip = null;
	try {
		zip = root.getJar();
		String entryName = Util.concatWith(pkg.names, getElementName(), '/');
		ZipEntry ze = zip.getEntry(entryName);
		if (ze != null) {
			byte contents[] = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
			String fileName = root.getHandleIdentifier() + IDependent.JAR_FILE_ENTRY_SEPARATOR + entryName;
			return new ClassFileReader(contents, fileName.toCharArray(), fullyInitialize);
		}
	} finally {
		JavaModelManager.getJavaModelManager().closeZipFile(zip);
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:ClassFile.java


示例5: findType

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
private NameEnvironmentAnswer findType(final String name) {
    try {
        byte[] bytecode = classpath.get(name.replace(".", "/") + ".class");
        String source = files.get(name.replace(".", "/") + ".java");
        if (bytecode != null) {
            char[] fileName = name.toCharArray();
            ClassFileReader classFileReader = new ClassFileReader(bytecode, fileName, true);
            return new NameEnvironmentAnswer(classFileReader, null);
        } else if (source != null) {
            ICompilationUnit compilationUnit = new CompilationUnit(source.toCharArray(), name, "UTF-8");
            return new NameEnvironmentAnswer(compilationUnit, null);
        }
        return null;
    } catch (ClassFormatException e) {
        // Something very very bad
        throw new ProjectCompilerException("compiler error", e);
    }
}
 
开发者ID:drxaos,项目名称:jvmvm,代码行数:19,代码来源:NameEnv.java


示例6: gleanNamedType

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
Map<String, String> gleanNamedType(File classfile) throws IOException {
  // use jdt class reader to avoid extra runtime dependency, otherwise could use asm

  try {
    ClassFileReader type = ClassFileReader.read(classfile);
    IBinaryAnnotation[] annotations = type.getAnnotations();
    if (annotations != null) {
      for (IBinaryAnnotation annotation : annotations) {
        if ("Ljavax/inject/Named;".equals(new String(annotation.getTypeName()))) {
          return Collections.singletonMap(new String(type.getName()).replace('/', '.'), null);
        }
      }
    }
  } catch (ClassFormatException e) {
    // silently ignore classes we can't read/parse
  }

  return null;
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:20,代码来源:AbstractSisuIndexMojo.java


示例7: findType

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
private NameEnvironmentAnswer findType(String className) {
    if (className.equals(source.getQualifiedClassName())) {
        return new NameEnvironmentAnswer(new CompilationUnit(source), null);
    }

    InputStream is = null;
    try {
        String resourceName = className.replace('.', '/') + ".class";
        is = classLoader.getResourceAsStream(resourceName);
        if (is != null) {
            byte[] bytes = IoUtils.toByteArray(is);
            char[] fileName = resourceName.toCharArray();
            ClassFileReader classFileReader = new ClassFileReader(bytes, fileName, true);
            return new NameEnvironmentAnswer(classFileReader, null);
        }
    } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) {
        log.error("Compilation error", e);
    } finally {
        IoUtils.closeQuietly(is);
    }
    return null;
}
 
开发者ID:subchen,项目名称:jetbrick-template-1x,代码行数:23,代码来源:JdtCompiler.java


示例8: newClassFileReader

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
public static ClassFileReader newClassFileReader(IResource resource)
    throws CoreException, ClassFormatException, IOException {
  InputStream in = null;
  try {
    in = ((IFile) resource).getContents(true);
    return ClassFileReader.read(in, resource.getFullPath().toString());
  } finally {
    if (in != null) in.close();
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:Util.java


示例9: getClassFileReader

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
public static NameEnvironmentAnswer getClassFileReader(ClassFileReader classFileReader) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
	return new NameEnvironmentAnswer(classFileReader, null);
	// if (constrNameEnvAnsBin2Args != null)
	// return constrNameEnvAnsBin2Args.newInstance(new Object[] {
	// classFileReader, null });
	// return constrNameEnvAnsBin.newInstance(new Object[] { classFileReader });
}
 
开发者ID:OpenSoftwareSolutions,项目名称:PDFReporter-Studio,代码行数:8,代码来源:NameEnvironmentAnswerFactory.java


示例10: createBinaryMethodHandle

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
IMethod createBinaryMethodHandle(IType type, char[] methodSelector, char[][] argumentTypeNames) {
	ClassFileReader reader = MatchLocator.classFileReader(type);
	if (reader != null) {
		IBinaryMethod[] methods = reader.getMethods();
		if (methods != null) {
			int argCount = argumentTypeNames == null ? 0 : argumentTypeNames.length;
			nextMethod : for (int i = 0, methodsLength = methods.length; i < methodsLength; i++) {
				IBinaryMethod binaryMethod = methods[i];
				char[] selector = binaryMethod.isConstructor() ? type.getElementName().toCharArray() : binaryMethod.getSelector();
				if (CharOperation.equals(selector, methodSelector)) {
					char[] signature = binaryMethod.getGenericSignature();
					if (signature == null) signature = binaryMethod.getMethodDescriptor();
					char[][] parameterTypes = Signature.getParameterTypes(signature);
					if (argCount != parameterTypes.length) continue nextMethod;
					if (argumentTypeNames != null) {
						for (int j = 0; j < argCount; j++) {
							char[] parameterTypeName = ClassFileMatchLocator.convertClassFileFormat(parameterTypes[j]);
							if (!CharOperation.endsWith(Signature.toCharArray(Signature.getTypeErasure(parameterTypeName)), CharOperation.replaceOnCopy(argumentTypeNames[j], '$', '.')))
								continue nextMethod;
							parameterTypes[j] = parameterTypeName;
						}
					}
					return (IMethod) createMethodHandle(type, new String(selector), CharOperation.toStrings(parameterTypes));
				}
			}
		}
	}
	return null;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:30,代码来源:MatchLocator.java


示例11: getSourceFileName

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
private String getSourceFileName() {
	if (this.sourceFileName != null) return this.sourceFileName;

	this.sourceFileName = NO_SOURCE_FILE_NAME;
	if (this.openable.getSourceMapper() != null) {
		BinaryType type = (BinaryType) ((ClassFile) this.openable).getType();
		ClassFileReader reader = MatchLocator.classFileReader(type);
		if (reader != null) {
			String fileName = type.sourceFileName(reader);
			this.sourceFileName = fileName == null ? NO_SOURCE_FILE_NAME : fileName;
		}
	}
	return this.sourceFileName;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:PossibleMatch.java


示例12: buildImports

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
public ImportReference[] buildImports(ClassFileReader reader) {
	// add remaining references to the list of type names
	// (code extracted from BinaryIndexer#extractReferenceFromConstantPool(...))
	int[] constantPoolOffsets = reader.getConstantPoolOffsets();
	int constantPoolCount = constantPoolOffsets.length;
	for (int i = 0; i < constantPoolCount; i++) {
		int tag = reader.u1At(constantPoolOffsets[i]);
		char[] name = null;
		switch (tag) {
			case ClassFileConstants.MethodRefTag :
			case ClassFileConstants.InterfaceMethodRefTag :
				int constantPoolIndex = reader.u2At(constantPoolOffsets[i] + 3);
				int utf8Offset = constantPoolOffsets[reader.u2At(constantPoolOffsets[constantPoolIndex] + 3)];
				name = reader.utf8At(utf8Offset + 3, reader.u2At(utf8Offset + 1));
				break;
			case ClassFileConstants.ClassTag :
				utf8Offset = constantPoolOffsets[reader.u2At(constantPoolOffsets[i] + 1)];
				name = reader.utf8At(utf8Offset + 3, reader.u2At(utf8Offset + 1));
				break;
		}
		if (name == null || (name.length > 0 && name[0] == '['))
			break; // skip over array references
		this.typeNames.add(CharOperation.splitOn('/', name));
	}

	// convert type names into import references
	int typeNamesLength = this.typeNames.size();
	ImportReference[] imports = new ImportReference[typeNamesLength];
	char[][][] set = this.typeNames.set;
	int index = 0;
	for (int i = 0, length = set.length; i < length; i++) {
		char[][] typeName = set[i];
		if (typeName != null) {
			imports[index++] = new ImportReference(typeName, new long[typeName.length]/*dummy positions*/, false/*not on demand*/, 0);
		}
	}
	return imports;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:39,代码来源:BinaryTypeConverter.java


示例13: newClassFileReader

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
public static ClassFileReader newClassFileReader(IResource resource) throws CoreException, ClassFormatException, IOException {
	InputStream in = null;
	try {
		in = ((IFile) resource).getContents(true);
		return ClassFileReader.read(in, resource.getFullPath().toString());
	} finally {
		if (in != null)
			in.close();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:Util.java


示例14: getExtraFlags

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
public static int getExtraFlags(ClassFileReader reader) {
	int extraFlags = 0;
	
	if (reader.isNestedType()) {
		extraFlags |= ExtraFlags.IsMemberType;
	}
	
	if (reader.isLocal()) {
		extraFlags |= ExtraFlags.IsLocalType;
	}
	
	IBinaryNestedType[] memberTypes = reader.getMemberTypes();
	int memberTypeCounter = memberTypes == null ? 0 : memberTypes.length;
	if (memberTypeCounter > 0) {
		done : for (int i = 0; i < memberTypeCounter; i++) {
			int modifiers = memberTypes[i].getModifiers();
			// if the member type is static and not private
			if ((modifiers & ClassFileConstants.AccStatic) != 0 && (modifiers & ClassFileConstants.AccPrivate) == 0) {
				extraFlags |= ExtraFlags.HasNonPrivateStaticMemberTypes;
				break done;
			}
		}
		
	}
	
	return extraFlags;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:28,代码来源:ExtraFlags.java


示例15: findType

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
private NameEnvironmentAnswer findType(String type) {
    try {
        byte[] bytes;
        Source source;
        if (Act.isDev()) {
            source = classLoader.source(type);
            if (null != source) {
                return new NameEnvironmentAnswer(source.compilationUnit(), null);
            }
        }
        bytes = classLoader.enhancedBytecode(type);
        if (bytes != null) {
            ClassFileReader classFileReader = new ClassFileReader(bytes, type.toCharArray(), true);
            return new NameEnvironmentAnswer(classFileReader, null);
        } else {
            if (type.startsWith("org.osgl") || type.startsWith("java.") || type.startsWith("javax.")) {
                return null;
            }
        }
        if (Act.isDev()) {
            return null;
        }
        source = classLoader.source(type);
        if (null == source) {
            return null;
        } else {
            return new NameEnvironmentAnswer(source.compilationUnit(), null);
        }
    } catch (ClassFormatException e) {
        throw E.unexpected(e);
    }
}
 
开发者ID:actframework,项目名称:actframework,代码行数:33,代码来源:AppCompiler.java


示例16: digestClassFile

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
private byte[] digestClassFile(File outputFile, byte[] definition) {
  try {
    ClassFileReader reader = new ClassFileReader(definition, outputFile.getAbsolutePath().toCharArray());
    return digester.digest(reader);
  } catch (ClassFormatException e) {
    // ignore this class
  }
  return null;
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:10,代码来源:CompilerJdt.java


示例17: findType

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
@Override
public NameEnvironmentAnswer findType(String packageName, String typeName, AccessRestriction accessRestriction) {
  try {
    String qualifiedFileName = packageName + "/" + typeName + SUFFIX_STRING_class;
    ClassFileReader reader = ClassFileReader.read(this.zipFile, qualifiedFileName);
    if (reader != null) {
      return new NameEnvironmentAnswer(reader, accessRestriction);
    }
  } catch (ClassFormatException | IOException e) {
    // treat as if class file is missing
  }
  return null;
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:14,代码来源:ClasspathJar.java


示例18: findType

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
@Override
public NameEnvironmentAnswer findType(String packageName, String typeName, AccessRestriction accessRestriction) {
  try {
    Path classFile = getFile(packageName, typeName);
    if (classFile != null) {
      try (InputStream is = Files.newInputStream(classFile)) {
        return new NameEnvironmentAnswer(ClassFileReader.read(is, classFile.getFileName().toString(), false), accessRestriction);
      }
    }
  } catch (ClassFormatException | IOException e) {
    // treat as if type is missing
  }
  return null;
}
 
开发者ID:takari,项目名称:takari-lifecycle,代码行数:15,代码来源:ClasspathDirectory.java


示例19: createFindTypeAnswer

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
protected NameEnvironmentAnswer createFindTypeAnswer(String className, byte[] classBytes) {
	final char[] fileName = className.toCharArray();
	try {
		final ClassFileReader classFileReader = new ClassFileReader(classBytes, fileName, true);
		return new NameEnvironmentAnswer(classFileReader, null);
	} catch (final ClassFormatException e) {
		// Wrong class format
		return null;
	}
}
 
开发者ID:MattiasBuelens,项目名称:junit,代码行数:11,代码来源:EclipseCompiler.java


示例20: findType

import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; //导入依赖的package包/类
public NameEnvironmentAnswer findType(final QualifiedName className) {
  try {
    boolean _containsKey = this.cache.containsKey(className);
    if (_containsKey) {
      return this.cache.get(className);
    }
    final IEObjectDescription candidate = IterableExtensions.<IEObjectDescription>head(this.resourceDescriptions.getExportedObjects(TypesPackage.Literals.JVM_DECLARED_TYPE, className, false));
    NameEnvironmentAnswer result = null;
    if ((candidate != null)) {
      final IResourceDescription resourceDescription = this.resourceDescriptions.getResourceDescription(candidate.getEObjectURI().trimFragment());
      final Resource res = this.resource.getResourceSet().getResource(resourceDescription.getURI(), false);
      String _xifexpression = null;
      if ((res instanceof JavaResource)) {
        _xifexpression = ((JavaResource) res).getOriginalSource();
      } else {
        _xifexpression = this.stubGenerator.getJavaStubSource(candidate, resourceDescription);
      }
      final String source = _xifexpression;
      char[] _charArray = source.toCharArray();
      String _string = className.toString("/");
      String _plus = (_string + ".java");
      CompilationUnit _compilationUnit = new CompilationUnit(_charArray, _plus, null);
      NameEnvironmentAnswer _nameEnvironmentAnswer = new NameEnvironmentAnswer(_compilationUnit, null);
      result = _nameEnvironmentAnswer;
    } else {
      String _string_1 = className.toString("/");
      final String fileName = (_string_1 + ".class");
      final URL url = this.classLoader.getResource(fileName);
      if ((url == null)) {
        this.cache.put(className, null);
        return null;
      }
      final ClassFileReader reader = ClassFileReader.read(url.openStream(), fileName);
      NameEnvironmentAnswer _nameEnvironmentAnswer_1 = new NameEnvironmentAnswer(reader, null);
      result = _nameEnvironmentAnswer_1;
    }
    this.cache.put(className, result);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:43,代码来源:IndexAwareNameEnvironment.java



注:本文中的org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Endpoint类代码示例发布时间:2022-05-21
下一篇:
Java Util类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap