private int generateAnnotationDefaultAttribute(AnnotationMethodDeclaration declaration, int attributeOffset) { int attributesNumber = 0; // add an annotation default attribute int annotationDefaultNameIndex = this.constantPool.literalIndex(AttributeNamesConstants.AnnotationDefaultName); if (this.contentsOffset + 6 >= this.contents.length) { resizeContents(6); } this.contents[this.contentsOffset++] = (byte) (annotationDefaultNameIndex >> 8); this.contents[this.contentsOffset++] = (byte) annotationDefaultNameIndex; int attributeLengthOffset = this.contentsOffset; this.contentsOffset += 4; generateElementValue(declaration.defaultValue, declaration.binding.returnType, attributeOffset); if (this.contentsOffset != attributeOffset) { int attributeLength = this.contentsOffset - attributeLengthOffset - 4; this.contents[attributeLengthOffset++] = (byte) (attributeLength >> 24); this.contents[attributeLengthOffset++] = (byte) (attributeLength >> 16); this.contents[attributeLengthOffset++] = (byte) (attributeLength >> 8); this.contents[attributeLengthOffset++] = (byte) attributeLength; attributesNumber++; } return attributesNumber; }
protected void consumeMethodHeaderDefaultValue() { // MethodHeaderDefaultValue ::= DefaultValue MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr]; int length = this.expressionLengthStack[this.expressionLengthPtr--]; if (length == 1) { this.intPtr--; // we get rid of the position of the default keyword this.intPtr--; // we get rid of the position of the default keyword if(md.isAnnotationMethod()) { ((AnnotationMethodDeclaration)md).defaultValue = this.expressionStack[this.expressionPtr]; md.modifiers |= ClassFileConstants.AccAnnotationDefault; } this.expressionPtr--; this.recordStringLiterals = true; } if(this.currentElement != null) { if(md.isAnnotationMethod()) { this.currentElement.updateSourceEndIfNecessary(((AnnotationMethodDeclaration)md).defaultValue.sourceEnd); } } }
protected void consumeMethodHeaderExtendedDims() { // MethodHeaderExtendedDims ::= Dimsopt // now we update the returnType of the method MethodDeclaration md = (MethodDeclaration) this.astStack[this.astPtr]; int extendedDimensions = this.intStack[this.intPtr--]; if(md.isAnnotationMethod()) { ((AnnotationMethodDeclaration)md).extendedDimensions = extendedDimensions; } if (extendedDimensions != 0) { md.sourceEnd = this.endPosition; md.returnType = augmentTypeWithAdditionalDimensions(md.returnType, extendedDimensions, getAnnotationsOnDimensions(extendedDimensions), false); md.bits |= (md.returnType.bits & ASTNode.HasTypeAnnotations); if (this.currentToken == TokenNameLBRACE){ md.bodyStart = this.endPosition + 1; } // recovery if (this.currentElement != null){ this.lastCheckPoint = md.bodyStart; } } }
public int generateMethodInfoAttributes(MethodBinding methodBinding, AnnotationMethodDeclaration declaration) { int attributesNumber = generateMethodInfoAttributes(methodBinding); int attributeOffset = this.contentsOffset; if ((declaration.modifiers & ClassFileConstants.AccAnnotationDefault) != 0) { // add an annotation default attribute attributesNumber += generateAnnotationDefaultAttribute(declaration, attributeOffset); } return attributesNumber; }
protected void consumeAnnotationTypeMemberDeclaration() { // AnnotationTypeMemberDeclaration ::= AnnotationTypeMemberDeclarationHeader AnnotationTypeMemberHeaderExtendedDims DefaultValueopt ';' AnnotationMethodDeclaration annotationTypeMemberDeclaration = (AnnotationMethodDeclaration) this.astStack[this.astPtr]; annotationTypeMemberDeclaration.modifiers |= ExtraCompilerModifiers.AccSemicolonBody; // store the this.endPosition (position just before the '}') in case there is // a trailing comment behind the end of the method int declarationEndPosition = flushCommentsDefinedPriorTo(this.endStatementPosition); annotationTypeMemberDeclaration.bodyStart = this.endStatementPosition; annotationTypeMemberDeclaration.bodyEnd = declarationEndPosition; annotationTypeMemberDeclaration.declarationSourceEnd = declarationEndPosition; }
public void annotationMembersCannotHaveParameters(AnnotationMethodDeclaration annotationMethodDeclaration) { this.handle( IProblem.AnnotationMembersCannotHaveParameters, NoArgument, NoArgument, annotationMethodDeclaration.sourceStart, annotationMethodDeclaration.sourceEnd); }
public void annotationMembersCannotHaveTypeParameters(AnnotationMethodDeclaration annotationMethodDeclaration) { this.handle( IProblem.AnnotationMembersCannotHaveTypeParameters, NoArgument, NoArgument, annotationMethodDeclaration.sourceStart, annotationMethodDeclaration.sourceEnd); }
public void illegalExtendedDimensions(AnnotationMethodDeclaration annotationTypeMemberDeclaration) { this.handle( IProblem.IllegalExtendedDimensions, NoArgument, NoArgument, annotationTypeMemberDeclaration.sourceStart, annotationTypeMemberDeclaration.sourceEnd); }
@Override public boolean visit(AnnotationMethodDeclaration node, ClassScope classScope) { fixPositions(setGeneratedBy(node, source)); return super.visit(node, classScope); }
public boolean visit( AnnotationMethodDeclaration annotationTypeMemberDeclaration, ClassScope scope) { /* * Print comments to get proper line number */ this.scribe.printComment(); this.scribe.printModifiers(annotationTypeMemberDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_METHOD); this.scribe.space(); /* * Print the method return type */ final TypeReference returnType = annotationTypeMemberDeclaration.returnType; final MethodScope annotationTypeMemberDeclarationScope = annotationTypeMemberDeclaration.scope; if (returnType != null) { returnType.traverse(this, annotationTypeMemberDeclarationScope); } /* * Print the method name */ this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, true); this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_opening_paren_in_annotation_type_member_declaration); this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_between_empty_parens_in_annotation_type_member_declaration); /* * Check for extra dimensions */ int extraDimensions = annotationTypeMemberDeclaration.extendedDimensions; if (extraDimensions != 0) { if (this.preferences.insert_space_before_opening_bracket_in_array_type_reference) { this.scribe.space(); } for (int i = 0; i < extraDimensions; i++) { this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); if (this.preferences.insert_space_between_brackets_in_array_type_reference) { this.scribe.space(); } this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); } } Expression defaultValue = annotationTypeMemberDeclaration.defaultValue; if (defaultValue != null) { this.scribe.printNextToken(TerminalTokens.TokenNamedefault, true); this.scribe.space(); defaultValue.traverse(this, (BlockScope) null); } this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); return false; }
public boolean visit( AnnotationMethodDeclaration annotationTypeMemberDeclaration, ClassScope scope) { /* * Print comments to get proper line number */ this.scribe.printComment(); this.scribe.printModifiers(annotationTypeMemberDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_METHOD); this.scribe.space(); /* * Print the method return type */ final TypeReference returnType = annotationTypeMemberDeclaration.returnType; final MethodScope annotationTypeMemberDeclarationScope = annotationTypeMemberDeclaration.scope; if (returnType != null) { returnType.traverse(this, annotationTypeMemberDeclarationScope); } /* * Print the method name */ this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, true); this.scribe.printNextToken(TerminalTokens.TokenNameLPAREN, this.preferences.insert_space_before_opening_paren_in_annotation_type_member_declaration); this.scribe.printNextToken(TerminalTokens.TokenNameRPAREN, this.preferences.insert_space_between_empty_parens_in_annotation_type_member_declaration); /* * Check for extra dimensions */ int extraDimensions = annotationTypeMemberDeclaration.extendedDimensions; if (extraDimensions != 0) { for (int i = 0; i < extraDimensions; i++) { this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); } } Expression defaultValue = annotationTypeMemberDeclaration.defaultValue; if (defaultValue != null) { this.scribe.printNextToken(TerminalTokens.TokenNamedefault, true); this.scribe.space(); defaultValue.traverse(this, (BlockScope) null); } this.scribe.printNextToken(TerminalTokens.TokenNameSEMICOLON, this.preferences.insert_space_before_semicolon); this.scribe.printComment(CodeFormatter.K_UNKNOWN, Scribe.BASIC_TRAILING_COMMENT); return false; }
@Override public void endVisit(AnnotationMethodDeclaration x, ClassScope classScope) { endVisit((MethodDeclaration) x, classScope); }
@Override public boolean visit(AnnotationMethodDeclaration x, ClassScope classScope) { return visit((MethodDeclaration) x, classScope); }
@Override public boolean visit(AnnotationMethodDeclaration node, ClassScope classScope) { setGeneratedBy(node, source); applyOffset(node); return super.visit(node, classScope); }