@Override public void handle(AnnotationValues<Singleton> annotation, Annotation ast, EclipseNode annotationNode) { //remove annotation EclipseHandlerUtil.unboxAndRemoveAnnotationParameter(ast, "onType", "@Singleton(onType=", annotationNode); //add private constructor EclipseNode singletonClass = annotationNode.up(); TypeDeclaration singletonClassType = (TypeDeclaration) singletonClass.get(); ConstructorDeclaration constructor = addConstructor(singletonClass, singletonClassType); TypeReference singletonTypeRef = EclipseHandlerUtil.cloneSelfType(singletonClass, singletonClassType); //add inner class //add instance field StringBuilder sb = new StringBuilder(); sb.append(singletonClass.getName()); sb.append("Holder"); String innerClassName = sb.toString(); TypeDeclaration innerClass = new TypeDeclaration(singletonClassType.compilationResult); innerClass.modifiers = AccPrivate | AccStatic; innerClass.name = innerClassName.toCharArray(); FieldDeclaration instanceVar = addInstanceVar(constructor, singletonTypeRef, innerClass); FieldDeclaration[] declarations = new FieldDeclaration[]{instanceVar}; innerClass.fields = declarations; EclipseHandlerUtil.injectType(singletonClass, innerClass); addFactoryMethod(singletonClass, singletonClassType, singletonTypeRef, innerClass, instanceVar); }
public StringBuffer print(int indent, StringBuffer output) { if (this.javadoc != null) { this.javadoc.print(indent, output); } if ((this.bits & ASTNode.IsAnonymousType) == 0) { printIndent(indent, output); printHeader(0, output); } return printBody(indent, output); }
protected void consumeAnnotationTypeDeclaration() { int length; if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { //there are length declarations //dispatch according to the type of the declarations dispatchDeclarationInto(length); } TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr]; //convert constructor that do not have the type's name into methods typeDecl.checkConstructors(this); //always add <clinit> (will be remove at code gen time if empty) if (this.scanner.containsAssertKeyword) { typeDecl.bits |= ASTNode.ContainsAssertion; } typeDecl.addClinit(); typeDecl.bodyEnd = this.endStatementPosition; if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) { typeDecl.bits |= ASTNode.UndocumentedEmptyBlock; } typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition); } protected void consumeAnnotationTypeDeclarationHeader() {
if (methodDeclarations != null) { TypeDeclaration currentDeclaration = this.referenceBinding.scope.referenceContext; int typeDeclarationSourceStart = currentDeclaration.sourceStart(); int typeDeclarationSourceEnd = currentDeclaration.sourceEnd(); for (int i = 0, max = methodDeclarations.length; i < max; i++) { MethodDeclaration methodDeclaration = methodDeclarations[i];
/** * @see IType#isEnum() * @since 3.0 */ public boolean isEnum() throws JavaModelException { SourceTypeElementInfo info = (SourceTypeElementInfo) getElementInfo(); return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.ENUM_DECL; }
private void format( TypeDeclaration memberTypeDeclaration, ClassScope scope, boolean isChunkStart, boolean isFirstClassBodyDeclaration) { if (isFirstClassBodyDeclaration) { int newLinesBeforeFirstClassBodyDeclaration = this.preferences.blank_lines_before_first_class_body_declaration; if (newLinesBeforeFirstClassBodyDeclaration > 0) { this.scribe.printEmptyLines(newLinesBeforeFirstClassBodyDeclaration); } } else { int newLineBeforeChunk = isChunkStart ? this.preferences.blank_lines_before_new_chunk : 0; if (newLineBeforeChunk > 0) { this.scribe.printEmptyLines(newLineBeforeChunk); } final int newLinesBeforeMember = this.preferences.blank_lines_before_member_type; if (newLinesBeforeMember > 0) { this.scribe.printEmptyLines(newLinesBeforeMember); } } memberTypeDeclaration.traverse(this, scope); }
/** * Compute the tagbits for standard annotations. For source types, these could require * lazily resolving corresponding annotation nodes, in case of forward references. * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits() */ public long getAnnotationTagBits() { MethodBinding originalMethod = original(); if ((originalMethod.tagBits & TagBits.AnnotationResolved) == 0 && originalMethod.declaringClass instanceof SourceTypeBinding) { ClassScope scope = ((SourceTypeBinding) originalMethod.declaringClass).scope; if (scope != null) { TypeDeclaration typeDecl = scope.referenceContext; AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(originalMethod); if (methodDecl != null) ASTNode.resolveAnnotations(methodDecl.scope, methodDecl.annotations, originalMethod); } } return originalMethod.tagBits; }
void checkAbstractMethod(MethodBinding abstractMethod) { if (mustImplementAbstractMethod(abstractMethod.declaringClass)) { TypeDeclaration typeDeclaration = this.type.scope.referenceContext; if (typeDeclaration != null) { MethodDeclaration missingAbstractMethod = typeDeclaration.addMissingAbstractMethodFor(abstractMethod); missingAbstractMethod.scope.problemReporter().abstractMethodMustBeImplemented(this.type, abstractMethod); } else { problemReporter().abstractMethodMustBeImplemented(this.type, abstractMethod); } } } void checkAgainstInheritedMethods(MethodBinding currentMethod, MethodBinding[] methods, int length, MethodBinding[] allInheritedMethods) {
public void analyseCode() { if (this.ignoreFurtherInvestigation) return; try { if (this.types != null) { for (int i = 0, count = this.types.length; i < count; i++) { this.types[i].analyseCode(this.scope); } } // request inner emulation propagation propagateInnerEmulationForAllLocalTypes(); } catch (AbortCompilationUnit e) { this.ignoreFurtherInvestigation = true; return; } }
@Override public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) { CtConstructor<Object> c = factory.Core().createConstructor(); // if the source start of the class is equals to the source start of the constructor // it means that the constructor is implicit. c.setImplicit(scope.referenceContext.sourceStart() == constructorDeclaration.sourceStart()); if (constructorDeclaration.binding != null) { c.setExtendedModifiers(getModifiers(constructorDeclaration.binding.modifiers, true, true)); } // avoid to add explicit modifier to implicit constructor if (!c.isImplicit()) { for (CtExtendedModifier extendedModifier : getModifiers(constructorDeclaration.modifiers, false, true)) { c.addModifier(extendedModifier.getKind()); // avoid to keep implicit AND explicit modifier of the same kind. } } context.enter(c, constructorDeclaration); // Create block context.enter(factory.Core().createBlock(), constructorDeclaration); context.exit(constructorDeclaration); return true; }
protected void consumeAnnotationTypeDeclaration() { int length; if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { //there are length declarations //dispatch according to the type of the declarations dispatchDeclarationInto(length); } TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr]; //convert constructor that do not have the type's name into methods typeDecl.checkConstructors(this); //always add <clinit> (will be remove at code gen time if empty) if (this.scanner.containsAssertKeyword) { typeDecl.bits |= ASTNode.ContainsAssertion; } typeDecl.addClinit(); typeDecl.bodyEnd = this.endStatementPosition; if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) { typeDecl.bits |= ASTNode.UndocumentedEmptyBlock; } typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition); } protected void consumeAnnotationTypeDeclarationHeader() {
if (methodDeclarations != null) { TypeDeclaration currentDeclaration = this.referenceBinding.scope.referenceContext; int typeDeclarationSourceStart = currentDeclaration.sourceStart(); int typeDeclarationSourceEnd = currentDeclaration.sourceEnd(); for (int i = 0, max = methodDeclarations.length; i < max; i++) { MethodDeclaration methodDeclaration = methodDeclarations[i];
/** * @see IType#isEnum() * @since 3.0 */ public boolean isEnum() throws JavaModelException { IBinaryType info = (IBinaryType) getElementInfo(); return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.ENUM_DECL; }
private void format( TypeDeclaration memberTypeDeclaration, ClassScope scope, boolean isChunkStart, boolean isFirstClassBodyDeclaration) { if (isFirstClassBodyDeclaration) { int newLinesBeforeFirstClassBodyDeclaration = this.preferences.blank_lines_before_first_class_body_declaration; if (newLinesBeforeFirstClassBodyDeclaration > 0) { this.scribe.printEmptyLines(newLinesBeforeFirstClassBodyDeclaration); } } else { int newLineBeforeChunk = isChunkStart ? this.preferences.blank_lines_before_new_chunk : 0; if (newLineBeforeChunk > 0) { this.scribe.printEmptyLines(newLineBeforeChunk); } final int newLinesBeforeMember = this.preferences.blank_lines_before_member_type; if (newLinesBeforeMember > 0) { this.scribe.printEmptyLines(newLinesBeforeMember); } } memberTypeDeclaration.traverse(this, scope); }
/** * Compute the tagbits for standard annotations. For source types, these could require * lazily resolving corresponding annotation nodes, in case of forward references. * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits() */ public long getAnnotationTagBits() { MethodBinding originalMethod = original(); if ((originalMethod.tagBits & TagBits.AnnotationResolved) == 0 && originalMethod.declaringClass instanceof SourceTypeBinding) { ClassScope scope = ((SourceTypeBinding) originalMethod.declaringClass).scope; if (scope != null) { TypeDeclaration typeDecl = scope.referenceContext; AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(originalMethod); if (methodDecl != null) ASTNode.resolveAnnotations(methodDecl.scope, methodDecl.annotations, originalMethod); } } return originalMethod.tagBits; }
void checkAbstractMethod(MethodBinding abstractMethod) { if (mustImplementAbstractMethod(abstractMethod.declaringClass)) { TypeDeclaration typeDeclaration = this.type.scope.referenceContext; if (typeDeclaration != null) { MethodDeclaration missingAbstractMethod = typeDeclaration.addMissingAbstractMethodFor(abstractMethod); missingAbstractMethod.scope.problemReporter().abstractMethodMustBeImplemented(this.type, abstractMethod); } else { problemReporter().abstractMethodMustBeImplemented(this.type, abstractMethod); } } } void checkAgainstInheritedMethods(MethodBinding currentMethod, MethodBinding[] methods, int length, MethodBinding[] allInheritedMethods) {
public void analyseCode() { if (this.ignoreFurtherInvestigation) return; try { if (this.types != null) { for (int i = 0, count = this.types.length; i < count; i++) { this.types[i].analyseCode(this.scope); } } // request inner emulation propagation propagateInnerEmulationForAllLocalTypes(); } catch (AbortCompilationUnit e) { this.ignoreFurtherInvestigation = true; return; } }
public StringBuffer print(int indent, StringBuffer output) { if (this.javadoc != null) { this.javadoc.print(indent, output); } if ((this.bits & ASTNode.IsAnonymousType) == 0) { printIndent(indent, output); printHeader(0, output); } return printBody(indent, output); }
protected void consumeAnnotationTypeDeclaration() { int length; if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) { //there are length declarations //dispatch according to the type of the declarations dispatchDeclarationInto(length); } TypeDeclaration typeDecl = (TypeDeclaration) this.astStack[this.astPtr]; //convert constructor that do not have the type's name into methods typeDecl.checkConstructors(this); //always add <clinit> (will be remove at code gen time if empty) if (this.scanner.containsAssertKeyword) { typeDecl.bits |= ASTNode.ContainsAssertion; } typeDecl.addClinit(); typeDecl.bodyEnd = this.endStatementPosition; if (length == 0 && !containsComment(typeDecl.bodyStart, typeDecl.bodyEnd)) { typeDecl.bits |= ASTNode.UndocumentedEmptyBlock; } typeDecl.declarationSourceEnd = flushCommentsDefinedPriorTo(this.endStatementPosition); } protected void consumeAnnotationTypeDeclarationHeader() {
if (methodDeclarations != null) { TypeDeclaration currentDeclaration = this.referenceBinding.scope.referenceContext; int typeDeclarationSourceStart = currentDeclaration.sourceStart(); int typeDeclarationSourceEnd = currentDeclaration.sourceEnd(); for (int i = 0, max = methodDeclarations.length; i < max; i++) { MethodDeclaration methodDeclaration = methodDeclarations[i];