private static void compareFields(String contextPrefix, IBinaryField field1, IBinaryField field2) { contextPrefix = contextPrefix + "." + safeString(field1.getName()); //$NON-NLS-1$ compareAnnotations(contextPrefix, field1.getAnnotations(), field2.getAnnotations()); assertEquals(contextPrefix + ": Constants not equal", field1.getConstant(), field2.getConstant()); //$NON-NLS-1$ compareGenericSignatures(contextPrefix + ": The generic signature did not match", field1.getGenericSignature(), //$NON-NLS-1$ field2.getGenericSignature()); assertEquals(contextPrefix + ": The modifiers did not match", field1.getModifiers(), field2.getModifiers()); //$NON-NLS-1$ assertEquals(contextPrefix + ": The tag bits did not match", field1.getTagBits(), field2.getTagBits()); //$NON-NLS-1$ assertEquals(contextPrefix + ": The names did not match", field1.getName(), field2.getName()); //$NON-NLS-1$ compareTypeAnnotations(contextPrefix, field1.getTypeAnnotations(), field2.getTypeAnnotations()); assertEquals(contextPrefix + ": The type names did not match", field1.getTypeName(), field2.getTypeName()); //$NON-NLS-1$ }
/** * Returns the generic signature for the given field. If the field has no generic signature, one is generated * from the type's field descriptor. */ static SignatureWrapper getGenericSignatureFor(IBinaryField nextField) { char[] signature = nextField.getGenericSignature(); if (signature == null) { signature = nextField.getTypeName(); } return new SignatureWrapper(signature); }
public IAnnotation[] getAnnotations() throws JavaModelException { IBinaryField info = (IBinaryField) getElementInfo(); IBinaryAnnotation[] binaryAnnotations = info.getAnnotations(); return getAnnotations(binaryAnnotations, info.getTagBits()); } /*
/** * Creates the handles and infos for the fields of the given binary type. * Adds new handles to the given vector. */ private void generateFieldInfos(IType type, IBinaryType typeInfo, HashMap newElements, ArrayList childrenHandles) { // Make the fields IBinaryField[] fields = typeInfo.getFields(); if (fields == null) { return; } JavaModelManager manager = JavaModelManager.getJavaModelManager(); for (int i = 0, fieldCount = fields.length; i < fieldCount; i++) { IBinaryField fieldInfo = fields[i]; BinaryField field = new BinaryField((JavaElement)type, manager.intern(new String(fieldInfo.getName()))); newElements.put(field, fieldInfo); childrenHandles.add(field); generateAnnotationsInfos(field, fieldInfo.getAnnotations(), fieldInfo.getTagBits(), newElements); } } /**
@Override public ITypeAnnotationWalker enrichWithExternalAnnotationsFor(ITypeAnnotationWalker walker, Object member, LookupEnvironment environment) { if (walker == ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER && this.annotationProvider != null) { if (member == null) { return this.annotationProvider.forTypeHeader(environment); } else if (member instanceof IBinaryField) { IBinaryField field = (IBinaryField) member; char[] fieldSignature = field.getGenericSignature(); if (fieldSignature == null) fieldSignature = field.getTypeName(); return this.annotationProvider.forField(field.getName(), fieldSignature, environment); } else if (member instanceof IBinaryMethod) { IBinaryMethod method = (IBinaryMethod) member; char[] methodSignature = method.getGenericSignature(); if (methodSignature == null) methodSignature = method.getMethodDescriptor(); return this.annotationProvider.forMethod( method.isConstructor() ? TypeConstants.INIT : method.getSelector(), methodSignature, environment); } } return walker; }
private void scanFieldForNullAnnotation(IBinaryField field, FieldBinding fieldBinding, boolean isEnum, ITypeAnnotationWalker externalAnnotationWalker) { if (!isPrototype()) throw new IllegalStateException(); if (isEnum && (field.getModifiers() & ClassFileConstants.AccEnum) != 0) { fieldBinding.tagBits |= TagBits.AnnotationNonNull; return; // we know it's nonnull, no need to look for null *annotations* on enum constants. && (fieldType.tagBits & TagBits.AnnotationNullMASK) == 0 && fieldType.acceptsNonNullDefault()) { int nullDefaultFromField = getNullDefaultFrom(field.getAnnotations()); if (nullDefaultFromField == Binding.NO_NULL_DEFAULT ? hasNonNullDefaultFor(DefaultLocationField, -1) IBinaryAnnotation[] annotations = externalAnnotationWalker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER ? externalAnnotationWalker.getAnnotationsAtCursor(fieldBinding.type.id, false) : field.getAnnotations(); if (annotations != null) { for (int i = 0; i < annotations.length; i++) { this.externalAnnotationStatus = ExternalAnnotationStatus.TYPE_IS_ANNOTATED; if (!explicitNullness) { int nullDefaultFromField = getNullDefaultFrom(field.getAnnotations()); if (nullDefaultFromField == Binding.NO_NULL_DEFAULT ? hasNonNullDefaultFor(DefaultLocationField, -1) : (nullDefaultFromField & DefaultLocationField) != 0) {
boolean matchField(FieldPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) { if (!pattern.findDeclarations) return false; // only relevant when finding declarations if (!(binaryInfo instanceof IBinaryField)) return false; IBinaryField field = (IBinaryField) binaryInfo; if (!pattern.matchesName(pattern.name, field.getName())) return false; if (!checkDeclaringType(enclosingBinaryType, pattern.declaringSimpleName, pattern.declaringQualification, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; char[] fieldTypeSignature = Signature.toCharArray(convertClassFileFormat(field.getTypeName())); return checkTypeName(pattern.typeSimpleName, pattern.typeQualification, fieldTypeSignature, pattern.isCaseSensitive(), pattern.isCamelCase()); } boolean matchMethod(MethodPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) {
public int getFlags() throws JavaModelException { IBinaryField info = (IBinaryField) getElementInfo(); return info.getModifiers(); } /*
public Object getConstant() throws JavaModelException { IBinaryField info = (IBinaryField) getElementInfo(); return convertConstant(info.getConstant()); } /*
if ( CharOperation.equals(binaryFields[j].getName(), field.name)) { if (unresolvedFields == null) { System.arraycopy(binaryFields, 0, unresolvedFields = new IBinaryField[bFieldsLength], 0, bFieldsLength); if (field == null) continue; // impossible match or already reported as accurate if (matchBinary(pattern, field, info)) { String fieldName = new String(field.getName()); IField fieldHandle = binaryType.getField(fieldName); fieldHandle = new ResolvedBinaryField(binaryType, fieldName, fieldHandle.getKey());
/** * Creates the handles and infos for the fields of the given binary type. * Adds new handles to the given vector. */ private void generateFieldInfos(IType type, IBinaryType typeInfo, HashMap newElements, ArrayList childrenHandles) { // Make the fields IBinaryField[] fields = typeInfo.getFields(); if (fields == null) { return; } JavaModelManager manager = JavaModelManager.getJavaModelManager(); for (int i = 0, fieldCount = fields.length; i < fieldCount; i++) { IBinaryField fieldInfo = fields[i]; BinaryField field = new BinaryField((JavaElement)type, manager.intern(new String(fieldInfo.getName()))); newElements.put(field, fieldInfo); childrenHandles.add(field); generateAnnotationsInfos(field, fieldInfo.getAnnotations(), fieldInfo.getTagBits(), newElements); } } /**
@Override public ITypeAnnotationWalker enrichWithExternalAnnotationsFor(ITypeAnnotationWalker walker, Object member, LookupEnvironment environment) { if (walker == ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER && this.annotationProvider != null) { if (member == null) { return this.annotationProvider.forTypeHeader(environment); } else if (member instanceof IBinaryField) { IBinaryField field = (IBinaryField) member; char[] fieldSignature = field.getGenericSignature(); if (fieldSignature == null) fieldSignature = field.getTypeName(); return this.annotationProvider.forField(field.getName(), fieldSignature, environment); } else if (member instanceof IBinaryMethod) { IBinaryMethod method = (IBinaryMethod) member; char[] methodSignature = method.getGenericSignature(); if (methodSignature == null) methodSignature = method.getMethodDescriptor(); return this.annotationProvider.forMethod( method.isConstructor() ? TypeConstants.INIT : method.getSelector(), methodSignature, environment); } } return walker; }
/** * Returns the generic signature for the given field. If the field has no generic signature, one is generated * from the type's field descriptor. */ static SignatureWrapper getGenericSignatureFor(IBinaryField nextField) { char[] signature = nextField.getGenericSignature(); if (signature == null) { signature = nextField.getTypeName(); } return new SignatureWrapper(signature); }
private void scanFieldForNullAnnotation(IBinaryField field, FieldBinding fieldBinding, boolean isEnum, ITypeAnnotationWalker externalAnnotationWalker) { if (!isPrototype()) throw new IllegalStateException(); if (isEnum && (field.getModifiers() & ClassFileConstants.AccEnum) != 0) { fieldBinding.tagBits |= TagBits.AnnotationNonNull; return; // we know it's nonnull, no need to look for null *annotations* on enum constants. && (fieldType.tagBits & TagBits.AnnotationNullMASK) == 0 && fieldType.acceptsNonNullDefault()) { int nullDefaultFromField = getNullDefaultFrom(field.getAnnotations()); if (nullDefaultFromField == Binding.NO_NULL_DEFAULT ? hasNonNullDefaultFor(DefaultLocationField, true, -1) IBinaryAnnotation[] annotations = externalAnnotationWalker != ITypeAnnotationWalker.EMPTY_ANNOTATION_WALKER ? externalAnnotationWalker.getAnnotationsAtCursor(fieldBinding.type.id, false) : field.getAnnotations(); if (annotations != null) { for (int i = 0; i < annotations.length; i++) {
@Override public IAnnotation[] getAnnotations() throws JavaModelException { IBinaryField info = (IBinaryField) getElementInfo(); IBinaryAnnotation[] binaryAnnotations = info.getAnnotations(); return getAnnotations(binaryAnnotations, info.getTagBits()); } /*
boolean matchField(FieldPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) { if (!pattern.findDeclarations) return false; // only relevant when finding declarations if (!(binaryInfo instanceof IBinaryField)) return false; IBinaryField field = (IBinaryField) binaryInfo; if (!pattern.matchesName(pattern.name, field.getName())) return false; if (!checkDeclaringType(enclosingBinaryType, pattern.declaringSimpleName, pattern.declaringQualification, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; char[] fieldTypeSignature = Signature.toCharArray(convertClassFileFormat(field.getTypeName())); return checkTypeName(pattern.typeSimpleName, pattern.typeQualification, fieldTypeSignature, pattern.isCaseSensitive(), pattern.isCamelCase()); } boolean matchMethod(MethodPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) {
@Override public int getFlags() throws JavaModelException { IBinaryField info = (IBinaryField) getElementInfo(); return info.getModifiers(); } /*
public Object getConstant() throws JavaModelException { IBinaryField info = (IBinaryField) getElementInfo(); return convertConstant(info.getConstant()); } /*
if ( CharOperation.equals(binaryFields[j].getName(), field.name)) { if (unresolvedFields == null) { System.arraycopy(binaryFields, 0, unresolvedFields = new IBinaryField[bFieldsLength], 0, bFieldsLength); if (field == null) continue; // impossible match or already reported as accurate if (matchBinary(pattern, field, info)) { String fieldName = new String(field.getName()); IField fieldHandle = binaryType.getField(fieldName); fieldHandle = new ResolvedBinaryField(binaryType, fieldName, fieldHandle.getKey());
private static void compareFields(String contextPrefix, IBinaryField field1, IBinaryField field2) { contextPrefix = contextPrefix + "." + safeString(field1.getName()); //$NON-NLS-1$ compareAnnotations(contextPrefix, field1.getAnnotations(), field2.getAnnotations()); assertEquals(contextPrefix + ": Constants not equal", field1.getConstant(), field2.getConstant()); //$NON-NLS-1$ compareGenericSignatures(contextPrefix + ": The generic signature did not match", field1.getGenericSignature(), //$NON-NLS-1$ field2.getGenericSignature()); assertEquals(contextPrefix + ": The modifiers did not match", field1.getModifiers(), field2.getModifiers()); //$NON-NLS-1$ assertEquals(contextPrefix + ": The tag bits did not match", field1.getTagBits(), field2.getTagBits()); //$NON-NLS-1$ assertEquals(contextPrefix + ": The names did not match", field1.getName(), field2.getName()); //$NON-NLS-1$ compareTypeAnnotations(contextPrefix, field1.getTypeAnnotations(), field2.getTypeAnnotations()); assertEquals(contextPrefix + ": The type names did not match", field1.getTypeName(), field2.getTypeName()); //$NON-NLS-1$ }