public void genericTypeCannotExtendThrowable(TypeDeclaration typeDecl) { ASTNode location = typeDecl.binding.isAnonymousType() ? typeDecl.allocation.type : typeDecl.superclass; this.handle( IProblem.GenericTypeCannotExtendThrowable, new String[]{ new String(typeDecl.binding.readableName()) }, new String[]{ new String(typeDecl.binding.shortReadableName()) }, location.sourceStart, location.sourceEnd); } // use this private API when the compilation unit result can be found through the
private String computeAnonymousName(SourceTypeBinding binding) { final String poolName = String.valueOf(binding.constantPoolName()); final int lastIndexSeparator = poolName.lastIndexOf(CtType.INNERTTYPE_SEPARATOR); return poolName.substring(lastIndexSeparator + 1, lastIndexSeparator + 2); }
public ReferenceBinding[] superInterfaces() { if (!isPrototype()) return this.superInterfaces = this.prototype.superInterfaces(); return this.superInterfaces != null ? this.superInterfaces : isAnnotationType() ? this.superInterfaces = new ReferenceBinding [] { this.scope.getJavaLangAnnotationAnnotation() } : null; }
boolean mustImplementAbstractMethods() { return !this.type.isInterface() && !this.type.isAbstract(); }
((CtClass) type).setSuperclass(jdtTreeBuilder.references.buildTypeReference(typeDeclaration.superclass, typeDeclaration.scope)); if (typeDeclaration.binding.isAnonymousType() || (typeDeclaration.binding instanceof LocalTypeBinding && typeDeclaration.binding.enclosingMethod() != null)) { type.setSimpleName(computeAnonymousName(typeDeclaration.binding.constantPoolName())); } else { type.setSimpleName(new String(typeDeclaration.name));
void faultInTypesForFieldsAndMethods() { // check @Deprecated annotation getAnnotationTagBits(); // marks as deprecated by side effect ReferenceBinding enclosingType = enclosingType(); if (enclosingType != null && enclosingType.isViewedAsDeprecated() && !isDeprecated()) this.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; fields(); methods(); for (int i = 0, length = this.memberTypes.length; i < length; i++) ((SourceTypeBinding) this.memberTypes[i]).faultInTypesForFieldsAndMethods(); } // NOTE: the type of each field of a source type is resolved when needed
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo, boolean isReadAccess) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) return; //If inlinable field, forget the access emulation, the code gen will directly target it if (this.constant != Constant.NotAConstant) return; if ((this.bits & Binding.FIELD) != 0) { FieldBinding fieldBinding = (FieldBinding) this.binding; FieldBinding codegenField = fieldBinding.original(); if (((this.bits & ASTNode.DepthMASK) != 0) && (codegenField.isPrivate() // private access || (codegenField.isProtected() // implicit protected access && codegenField.declaringClass.getPackage() != currentScope.enclosingSourceType().getPackage()))) { if (this.syntheticAccessors == null) this.syntheticAccessors = new MethodBinding[2]; this.syntheticAccessors[isReadAccess ? SingleNameReference.READ : SingleNameReference.WRITE] = ((SourceTypeBinding)currentScope.enclosingSourceType(). enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT)).addSyntheticMethod(codegenField, isReadAccess, false /*not super access*/); currentScope.problemReporter().needToEmulateFieldAccess(codegenField, this, isReadAccess); return; } } }
private void checkAnnotationsInType() { // check @Deprecated annotation getAnnotationTagBits(); // marks as deprecated by side effect ReferenceBinding enclosingType = enclosingType(); if (enclosingType != null && enclosingType.isViewedAsDeprecated() && !isDeprecated()) this.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; for (int i = 0, length = this.memberTypes.length; i < length; i++) ((SourceTypeBinding) this.memberTypes[i]).checkAnnotationsInType(); }
void checkForMissingHashCodeMethod() { MethodBinding[] choices = this.type.getMethods(TypeConstants.EQUALS); boolean overridesEquals = false; for (int i = choices.length; !overridesEquals && --i >= 0;) overridesEquals = choices[i].parameters.length == 1 && choices[i].parameters[0].id == TypeIds.T_JavaLangObject; if (overridesEquals) { MethodBinding hashCodeMethod = this.type.getExactMethod(TypeConstants.HASHCODE, Binding.NO_PARAMETERS, null); if (hashCodeMethod != null && hashCodeMethod.declaringClass.id == TypeIds.T_JavaLangObject) this.problemReporter().shouldImplementHashcode(this.type); } }
public void shouldImplementHashcode(SourceTypeBinding type) { this.handle( IProblem.ShouldImplementHashcode, new String[] {new String(type.readableName())}, new String[] {new String(type.shortReadableName())}, type.sourceStart(), type.sourceEnd()); } public void shouldReturn(TypeBinding returnType, ASTNode location) {
public FieldBinding getField(char[] fieldName, boolean needResolve) { if (!isPrototype()) return this.prototype.getField(fieldName, needResolve); FieldBinding result = null; try { result = resolveTypeFor(field); return result; } finally { setFields(Binding.NO_FIELDS); } else { FieldBinding[] newFields = new FieldBinding[newSize]; newFields[index++] = f; setFields(newFields);
public void noMoreAvailableSpaceInConstantPool(TypeDeclaration typeDeclaration) { this.handle( IProblem.TooManyConstantsInConstantPool, new String[]{ new String(typeDeclaration.binding.readableName())}, new String[]{ new String(typeDeclaration.binding.shortReadableName())}, ProblemSeverities.Abort | ProblemSeverities.Error | ProblemSeverities.Fatal, typeDeclaration.sourceStart, typeDeclaration.sourceEnd); }
@Override public boolean visit(TypeParameter typeParameter, BlockScope scope) { Annotation[] annotations = typeParameter.annotations; if (annotations != null) { TypeVariableBinding binding = typeParameter.binding; if (binding == null) { return false; } // when we get here, it is guaranteed that class type parameters are connected, but method type parameters may not be. MethodBinding methodBinding = (MethodBinding) binding.declaringElement; ((SourceTypeBinding) methodBinding.declaringClass).resolveTypesFor(methodBinding); this.resolveAnnotations(scope, annotations, binding); } return false; }
@Override public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { Annotation[] annotations = fieldDeclaration.annotations; if (annotations != null) { FieldBinding fieldBinding = fieldDeclaration.binding; if (fieldBinding == null) { return false; } ((SourceTypeBinding) fieldBinding.declaringClass).resolveTypeFor(fieldBinding); this.resolveAnnotations(scope, annotations, fieldBinding); } return false; }
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo, boolean isReadAccess) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) return; //If inlinable field, forget the access emulation, the code gen will directly target it if (this.constant != Constant.NotAConstant) return; if ((this.bits & Binding.FIELD) != 0) { FieldBinding fieldBinding = (FieldBinding) this.binding; FieldBinding codegenField = fieldBinding.original(); if (((this.bits & ASTNode.DepthMASK) != 0) && ((codegenField.isPrivate() // private access && !currentScope.enclosingSourceType().isNestmateOf(codegenField.declaringClass) ) || (codegenField.isProtected() // implicit protected access && codegenField.declaringClass.getPackage() != currentScope.enclosingSourceType().getPackage()))) { if (this.syntheticAccessors == null) this.syntheticAccessors = new MethodBinding[2]; this.syntheticAccessors[isReadAccess ? SingleNameReference.READ : SingleNameReference.WRITE] = ((SourceTypeBinding)currentScope.enclosingSourceType(). enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT)).addSyntheticMethod(codegenField, isReadAccess, false /*not super access*/); currentScope.problemReporter().needToEmulateFieldAccess(codegenField, this, isReadAccess); return; } } }
private void cleanUp(TypeDeclaration type) { if (type.memberTypes != null) { for (int i = 0, max = type.memberTypes.length; i < max; i++){ cleanUp(type.memberTypes[i]); } } if (type.binding != null && type.binding.isAnnotationType()) this.compilationResult.hasAnnotations = true; if (type.binding != null) { // null out the type's scope backpointers type.binding.scope = null; } }
public String toString() { StringBuffer buffer = new StringBuffer(10); buffer.append("MethodVerifier for type: "); //$NON-NLS-1$ buffer.append(this.type.readableName()); buffer.append('\n'); buffer.append("\t-inherited methods: "); //$NON-NLS-1$ buffer.append(this.inheritedMethods); return buffer.toString(); } }
void faultInTypesForFieldsAndMethods() { // check @Deprecated annotation getAnnotationTagBits(); // marks as deprecated by side effect ReferenceBinding enclosingType = enclosingType(); if (enclosingType != null && enclosingType.isViewedAsDeprecated() && !isDeprecated()) this.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; fields(); methods(); for (int i = 0, length = this.memberTypes.length; i < length; i++) ((SourceTypeBinding) this.memberTypes[i]).faultInTypesForFieldsAndMethods(); } // NOTE: the type of each field of a source type is resolved when needed
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo, boolean isReadAccess) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) return; //If inlinable field, forget the access emulation, the code gen will directly target it if (this.constant != Constant.NotAConstant) return; if ((this.bits & Binding.FIELD) != 0) { FieldBinding fieldBinding = (FieldBinding) this.binding; FieldBinding codegenField = fieldBinding.original(); if (((this.bits & ASTNode.DepthMASK) != 0) && (codegenField.isPrivate() // private access || (codegenField.isProtected() // implicit protected access && codegenField.declaringClass.getPackage() != currentScope.enclosingSourceType().getPackage()))) { if (this.syntheticAccessors == null) this.syntheticAccessors = new MethodBinding[2]; this.syntheticAccessors[isReadAccess ? SingleNameReference.READ : SingleNameReference.WRITE] = ((SourceTypeBinding)currentScope.enclosingSourceType(). enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT)).addSyntheticMethod(codegenField, isReadAccess, false /*not super access*/); currentScope.problemReporter().needToEmulateFieldAccess(codegenField, this, isReadAccess); return; } } }
private void checkAnnotationsInType() { // check @Deprecated annotation getAnnotationTagBits(); // marks as deprecated by side effect ReferenceBinding enclosingType = enclosingType(); if (enclosingType != null && enclosingType.isViewedAsDeprecated() && !isDeprecated()) { this.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly; this.tagBits |= (enclosingType.tagBits & TagBits.AnnotationTerminallyDeprecated); } for (int i = 0, length = this.memberTypes.length; i < length; i++) ((SourceTypeBinding) this.memberTypes[i]).checkAnnotationsInType(); }