本文整理汇总了Java中org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader类的典型用法代码示例。如果您正苦于以下问题:Java ClassFileReader类的具体用法?Java ClassFileReader怎么用?Java ClassFileReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassFileReader类属于org.eclipse.jdt.internal.compiler.classfmt包,在下文中一共展示了ClassFileReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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 });
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
}