Refine search
public static ClassFileReader read(InputStream stream, String fileName, boolean fullyInitialize) throws ClassFormatException, IOException { byte classFileBytes[] = Util.getInputStreamAsByteArray(stream, -1); ClassFileReader classFileReader = new ClassFileReader(classFileBytes, fileName.toCharArray()); if (fullyInitialize) { classFileReader.initialize(); } return classFileReader; }
@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; }
public String toString() { java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); java.io.PrintWriter print = new java.io.PrintWriter(out); print.println(getClass().getName() + "{"); //$NON-NLS-1$ print.println(" this.className: " + new String(getName())); //$NON-NLS-1$ print.println(" this.superclassName: " + (getSuperclassName() == null ? "null" : new String(getSuperclassName()))); //$NON-NLS-2$ //$NON-NLS-1$ print.println(" access_flags: " + printTypeModifiers(accessFlags()) + "(" + accessFlags() + ")"); //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-2$ print.flush(); return out.toString(); } }
ClassFileReader reader = null; try { reader = ClassFileReader.read(this.f); } catch (ClassFormatException e) { return null; if (reader.isAnonymous()) { return NestingKind.ANONYMOUS; if (reader.isLocal()) { return NestingKind.LOCAL; if (reader.isMember()) { return NestingKind.MEMBER;
private NameEnvironmentAnswer createNameEnvironmentAnswer(final String pClazzName, final byte[] clazzBytes) throws ClassFormatException { final char[] fileName = pClazzName.toCharArray(); final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true); return new NameEnvironmentAnswer(classFileReader, null); }
protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes) throws CoreException { try { byte[] oldBytes = Util.getResourceContentsAsByteArray(file); notEqual : if (newBytes.length == oldBytes.length) { for (int i = newBytes.length; --i >= 0;) if (newBytes[i] != oldBytes[i]) break notEqual; return false; // bytes are identical so skip them } URI location = file.getLocationURI(); if (location == null) return false; // unable to determine location of this class file String filePath = location.getSchemeSpecificPart(); ClassFileReader reader = new ClassFileReader(oldBytes, filePath.toCharArray()); // ignore local types since they're only visible inside a single method if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) { if (JavaBuilder.DEBUG) System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$ addDependentsOf(new Path(fileName), true); this.newState.wasStructurallyChanged(fileName); } } catch (ClassFormatException e) { addDependentsOf(new Path(fileName), true); this.newState.wasStructurallyChanged(fileName); } return true; }
public char[] getSourceName() { if (this.sourceName != null) return this.sourceName; char[] name = getInnerSourceName(); // member or local scenario if (name == null) { name = getName(); // extract from full name int start; if (isAnonymous()) { start = CharOperation.indexOf('$', name, CharOperation.lastIndexOf('/', name) + 1) + 1; } else { start = CharOperation.lastIndexOf('/', name) + 1; } if (start > 0) { char[] newName = new char[name.length - start]; System.arraycopy(name, start, newName, 0, newName.length); name = newName; } } return this.sourceName = name; }
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; }
public Modifier getAccessLevel() { // cannot express multiple modifier if (getKind() != Kind.CLASS) { return null; } ClassFileReader reader = null; try { reader = ClassFileReader.read(this.f); } catch (ClassFormatException e) { // ignore } catch (IOException e) { // ignore } if (reader == null) { return null; } final int accessFlags = reader.accessFlags(); if ((accessFlags & ClassFileConstants.AccPublic) != 0) { return Modifier.PUBLIC; } if ((accessFlags & ClassFileConstants.AccAbstract) != 0) { return Modifier.ABSTRACT; } if ((accessFlags & ClassFileConstants.AccFinal) != 0) { return Modifier.FINAL; } return null; }
public static ClassFileReader read( java.util.zip.ZipFile zip, String filename) throws ClassFormatException, java.io.IOException { return read(zip, filename, false); }
public ClassFileReader getClassfile(String fileName, IModule module) throws IOException, ClassFormatException { ClassFileReader reader = null; if (module == null) { reader = getClassfile(fileName, (Predicate<String>)null); } else { byte[] content = getClassfileBytes(fileName, new String(module.name())); if (content != null) { reader = new ClassFileReader(content, fileName.toCharArray()); } } return reader; }
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; }
@Override public NestingKind getNestingKind() { switch(getKind()) { case SOURCE : return NestingKind.TOP_LEVEL; case CLASS : ClassFileReader reader = getClassReader(); if (reader == null) { return null; } if (reader.isAnonymous()) { return NestingKind.ANONYMOUS; } if (reader.isLocal()) { return NestingKind.LOCAL; } if (reader.isMember()) { return NestingKind.MEMBER; } return NestingKind.TOP_LEVEL; default: return null; } }
@Override public Modifier getAccessLevel() { // cannot express multiple modifier if (getKind() != Kind.CLASS) { return null; } ClassFileReader reader = getClassReader(); if (reader == null) { return null; } final int accessFlags = reader.accessFlags(); if ((accessFlags & ClassFileConstants.AccPublic) != 0) { return Modifier.PUBLIC; } if ((accessFlags & ClassFileConstants.AccAbstract) != 0) { return Modifier.ABSTRACT; } if ((accessFlags & ClassFileConstants.AccFinal) != 0) { return Modifier.FINAL; } return null; }
NameEnvironmentAnswer getNameEnvironmentAnswer() throws ClassFormatException { if (nameEnvironmentAnswer == null) { ClassFileReader cfr = new ClassFileReader(getBytes(), unit.getResourceLocation().toCharArray(), true); nameEnvironmentAnswer = new NameEnvironmentAnswer(cfr, null); } return nameEnvironmentAnswer; }
protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes) throws CoreException { try { byte[] oldBytes = Util.getResourceContentsAsByteArray(file); notEqual : if (newBytes.length == oldBytes.length) { for (int i = newBytes.length; --i >= 0;) if (newBytes[i] != oldBytes[i]) break notEqual; return false; // bytes are identical so skip them } URI location = file.getLocationURI(); if (location == null) return false; // unable to determine location of this class file String filePath = location.getSchemeSpecificPart(); ClassFileReader reader = new ClassFileReader(oldBytes, filePath.toCharArray()); // ignore local types since they're only visible inside a single method if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) { if (JavaBuilder.DEBUG) System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$ addDependentsOf(new Path(fileName), true); this.newState.wasStructurallyChanged(fileName); } } catch (ClassFormatException e) { addDependentsOf(new Path(fileName), true); this.newState.wasStructurallyChanged(fileName); } return true; }
public char[] getSourceName() { if (this.sourceName != null) return this.sourceName; char[] name = getInnerSourceName(); // member or local scenario if (name == null) { name = getName(); // extract from full name int start; if (isAnonymous()) { start = CharOperation.indexOf('$', name, CharOperation.lastIndexOf('/', name) + 1) + 1; } else { start = CharOperation.lastIndexOf('/', name) + 1; } if (start > 0) { char[] newName = new char[name.length - start]; System.arraycopy(name, start, newName, 0, newName.length); name = newName; } } return this.sourceName = name; }
ClassFileReader reader = null; try { reader = ClassFileReader.read(this.f); } catch (ClassFormatException e) { return null; if (reader.isAnonymous()) { return NestingKind.ANONYMOUS; if (reader.isLocal()) { return NestingKind.LOCAL; if (reader.isMember()) { return NestingKind.MEMBER;
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; }
public Modifier getAccessLevel() { // cannot express multiple modifier if (getKind() != Kind.CLASS) { return null; } ClassFileReader reader = null; try { reader = ClassFileReader.read(this.f); } catch (ClassFormatException e) { // ignore } catch (IOException e) { // ignore } if (reader == null) { return null; } final int accessFlags = reader.accessFlags(); if ((accessFlags & ClassFileConstants.AccPublic) != 0) { return Modifier.PUBLIC; } if ((accessFlags & ClassFileConstants.AccAbstract) != 0) { return Modifier.ABSTRACT; } if ((accessFlags & ClassFileConstants.AccFinal) != 0) { return Modifier.FINAL; } return null; }