org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModifierRewrite.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private ListRewrite evaluateListRewrite(ASTRewrite rewrite, ASTNode declNode) {
	switch (declNode.getNodeType()) {
		case ASTNode.METHOD_DECLARATION:
			return rewrite.getListRewrite(declNode, MethodDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.FIELD_DECLARATION:
			return rewrite.getListRewrite(declNode, FieldDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
			return rewrite.getListRewrite(declNode, VariableDeclarationExpression.MODIFIERS2_PROPERTY);
		case ASTNode.VARIABLE_DECLARATION_STATEMENT:
			return rewrite.getListRewrite(declNode, VariableDeclarationStatement.MODIFIERS2_PROPERTY);
		case ASTNode.SINGLE_VARIABLE_DECLARATION:
			return rewrite.getListRewrite(declNode, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.TYPE_DECLARATION:
			return rewrite.getListRewrite(declNode, TypeDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.ENUM_DECLARATION:
			return rewrite.getListRewrite(declNode, EnumDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.ANNOTATION_TYPE_DECLARATION:
			return rewrite.getListRewrite(declNode, AnnotationTypeDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return rewrite.getListRewrite(declNode, EnumConstantDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
			return rewrite.getListRewrite(declNode, AnnotationTypeMemberDeclaration.MODIFIERS2_PROPERTY);
		default:
			throw new IllegalArgumentException("node has no modifiers: " + declNode.getClass().getName()); //$NON-NLS-1$
	}
}
 
Example #2
Source File: ModifierRewrite.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private ListRewrite evaluateListRewrite(ASTRewrite rewrite, ASTNode declNode) {
	switch (declNode.getNodeType()) {
		case ASTNode.METHOD_DECLARATION:
			return rewrite.getListRewrite(declNode, MethodDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.FIELD_DECLARATION:
			return rewrite.getListRewrite(declNode, FieldDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
			return rewrite.getListRewrite(declNode, VariableDeclarationExpression.MODIFIERS2_PROPERTY);
		case ASTNode.VARIABLE_DECLARATION_STATEMENT:
			return rewrite.getListRewrite(declNode, VariableDeclarationStatement.MODIFIERS2_PROPERTY);
		case ASTNode.SINGLE_VARIABLE_DECLARATION:
			return rewrite.getListRewrite(declNode, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.TYPE_DECLARATION:
			return rewrite.getListRewrite(declNode, TypeDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.ENUM_DECLARATION:
			return rewrite.getListRewrite(declNode, EnumDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.ANNOTATION_TYPE_DECLARATION:
			return rewrite.getListRewrite(declNode, AnnotationTypeDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return rewrite.getListRewrite(declNode, EnumConstantDeclaration.MODIFIERS2_PROPERTY);
		case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
			return rewrite.getListRewrite(declNode, AnnotationTypeMemberDeclaration.MODIFIERS2_PROPERTY);
		default:
			throw new IllegalArgumentException("node has no modifiers: " + declNode.getClass().getName()); //$NON-NLS-1$
	}
}
 
Example #3
Source File: UglyMathCommentsExtractor.java    From compiler with Apache License 2.0 6 votes vote down vote up
private static int getNodeStartPosition(final ASTNode node) {
    if (node instanceof MethodDeclaration) {
        MethodDeclaration decl = (MethodDeclaration) node;
        return decl.isConstructor() ? decl.getName().getStartPosition() : decl.getReturnType2().getStartPosition();
    } else if (node instanceof FieldDeclaration) {
        return ((FieldDeclaration) node).getType().getStartPosition();
    } else if (node instanceof AbstractTypeDeclaration) {
        return ((AbstractTypeDeclaration) node).getName().getStartPosition();
    } else if (node instanceof AnnotationTypeMemberDeclaration) {
        return ((AnnotationTypeMemberDeclaration) node).getName().getStartPosition();
    } else if (node instanceof EnumConstantDeclaration) {
        return ((EnumConstantDeclaration) node).getName().getStartPosition();
    } else if (node instanceof PackageDeclaration) {
        return ((PackageDeclaration) node).getName().getStartPosition();
    }
    /* TODO: Initializer */

    return node.getStartPosition();
}
 
Example #4
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean visit(final AnnotationTypeMemberDeclaration node) {
  Javadoc _javadoc = node.getJavadoc();
  boolean _tripleNotEquals = (_javadoc != null);
  if (_tripleNotEquals) {
    node.getJavadoc().accept(this);
  }
  this.appendModifiers(node, node.modifiers());
  node.getType().accept(this);
  this.appendSpaceToBuffer();
  node.getName().accept(this);
  Expression _default = node.getDefault();
  boolean _tripleNotEquals_1 = (_default != null);
  if (_tripleNotEquals_1) {
    this.appendToBuffer(" = ");
    node.getDefault().accept(this);
  }
  this.appendLineWrapToBuffer();
  return false;
}
 
Example #5
Source File: TypeVisitor.java    From repositoryminer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(AnnotationTypeMemberDeclaration node) {
	AbstractAnnotationMember annoMember = new AbstractAnnotationMember(
			node.getType().resolveBinding().getQualifiedName(), node.getName().getIdentifier());
	annoMember.setDefaultExpression(node.getDefault() != null ? node.getDefault().toString() : null);

	annotationMembers.add(annoMember);
	return true;
}
 
Example #6
Source File: JavaParseTreeBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private String getSignature(AnnotationTypeMemberDeclaration node) {
    StringBuffer buffer= new StringBuffer();
    buffer.append(node.getName().toString());
    buffer.append('(');
    buffer.append(')');
    return buffer.toString();
}
 
Example #7
Source File: NewAnnotationMemberProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int evaluateModifiers(AnnotationTypeDeclaration targetTypeDecl) {
	List<BodyDeclaration> methodDecls= targetTypeDecl.bodyDeclarations();
	for (int i= 0; i < methodDecls.size(); i++) {
		Object curr= methodDecls.get(i);
		if (curr instanceof AnnotationTypeMemberDeclaration) {
			return ((AnnotationTypeMemberDeclaration) curr).getModifiers();
		}
	}
	return 0;
}
 
Example #8
Source File: NewAnnotationMemberProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ASTRewrite getRewrite() throws CoreException {
	CompilationUnit astRoot= ASTResolving.findParentCompilationUnit(fInvocationNode);
	ASTNode typeDecl= astRoot.findDeclaringNode(fSenderBinding);
	ASTNode newTypeDecl= null;
	if (typeDecl != null) {
		newTypeDecl= typeDecl;
	} else {
		astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
		newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
	}
	createImportRewrite(astRoot);

	if (newTypeDecl instanceof AnnotationTypeDeclaration) {
		AnnotationTypeDeclaration newAnnotationTypeDecl= (AnnotationTypeDeclaration) newTypeDecl;
		
		ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());

		AnnotationTypeMemberDeclaration newStub= getStub(rewrite, newAnnotationTypeDecl);

		List<BodyDeclaration> members= newAnnotationTypeDecl.bodyDeclarations();
		int insertIndex= members.size();

		ListRewrite listRewriter= rewrite.getListRewrite(newAnnotationTypeDecl, AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY);
		listRewriter.insertAt(newStub, insertIndex, null);

		return rewrite;
	}
	return null;
}
 
Example #9
Source File: JavaTextSelection.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean resolveInVariableInitializer() {
	if (fInVariableInitializerRequested)
		return fInVariableInitializer;
	fInVariableInitializerRequested= true;
	resolveSelectedNodes();
	ASTNode node= getStartNode();
	ASTNode last= null;
	while (node != null) {
		int nodeType= node.getNodeType();
		if (node instanceof AbstractTypeDeclaration) {
			fInVariableInitializer= false;
			break;
		} else if (nodeType == ASTNode.ANONYMOUS_CLASS_DECLARATION) {
			fInVariableInitializer= false;
			break;
		} else if (nodeType == ASTNode.VARIABLE_DECLARATION_FRAGMENT &&
				   ((VariableDeclarationFragment)node).getInitializer() == last) {
			fInVariableInitializer= true;
			break;
		} else if (nodeType == ASTNode.SINGLE_VARIABLE_DECLARATION &&
			       ((SingleVariableDeclaration)node).getInitializer() == last) {
			fInVariableInitializer= true;
			break;
		} else if (nodeType == ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION &&
			       ((AnnotationTypeMemberDeclaration)node).getDefault() == last) {
			fInVariableInitializer= true;
			break;
		}
		last= node;
		node= node.getParent();
	}
	return fInVariableInitializer;
}
 
Example #10
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void endVisit(AnnotationTypeMemberDeclaration node) {
	if (skipNode(node))
		return;
	GenericSequentialFlowInfo info= processSequential(node, node.getType(), node.getDefault());
	info.setNoReturn();
}
 
Example #11
Source File: AstVisitor.java    From jdt2famix with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(AnnotationTypeMemberDeclaration node) {
	AnnotationTypeAttribute attribute = importer.ensureAnnotationTypeAttributeFromDeclaration(node);
	attribute.setIsStub(false);
	importer.ensureCommentFromBodyDeclaration(attribute, node);
	return super.visit(node);
}
 
Example #12
Source File: TestQ18.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public void endVisit(AnnotationTypeMemberDeclaration node) {
	methods++;
	if (maxThis < this2)
		maxThis = this2;
	if (minThis > this2)
		minThis = this2;
	this2 = thisStack.pop();
}
 
Example #13
Source File: TestQ23.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public void endVisit(AnnotationTypeMemberDeclaration node) {
	if (maxFields < condition2)
		maxFields = condition2;
	if (minFields > condition2)
		minFields = condition2;
	condition2 = conditionStack.pop();
}
 
Example #14
Source File: TestQ23.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preVisit2(ASTNode node) {
	if (node instanceof MethodDeclaration || node instanceof Initializer || node instanceof AnnotationTypeMemberDeclaration) {
		classes++;
		conditionStack.push(condition2);
		condition2 = 0;
	}
	return true;
}
 
Example #15
Source File: TestQ28.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public void endVisit(AnnotationTypeMemberDeclaration node) {
	if (maxLocals < locals2)
		maxLocals = locals2;
	if (minLocals > locals2)
		minLocals = locals2;
	locals2 = tryStack.pop();
}
 
Example #16
Source File: TestQ28.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preVisit2(ASTNode node) {
	if (node instanceof MethodDeclaration || node instanceof Initializer
			|| node instanceof AnnotationTypeMemberDeclaration) {
		classes++;
		tryStack.push(locals2);
		locals2 = 0;
	}
	return true;
}
 
Example #17
Source File: TestQ25.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preVisit2(ASTNode node) {
	if (node instanceof MethodDeclaration || node instanceof Initializer || node instanceof AnnotationTypeMemberDeclaration) {
		classes++;
		tryStack.push(try2);
		try2 = 0;
	}
	return true;
}
 
Example #18
Source File: TestQ26.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public void endVisit(AnnotationTypeMemberDeclaration node) {
	if (maxThrow < throw2)
		maxThrow = throw2;
	if (minThrow > throw2)
		minThrow = throw2;
	throw2 = tryStack.pop();
}
 
Example #19
Source File: TestQ26.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean preVisit2(ASTNode node) {
	if (node instanceof MethodDeclaration || node instanceof Initializer || node instanceof AnnotationTypeMemberDeclaration) {
		classes++;
		tryStack.push(throw2);
		throw2 = 0;
	}
	return true;
}
 
Example #20
Source File: NewAnnotationMemberProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private int evaluateModifiers(AnnotationTypeDeclaration targetTypeDecl) {
	List<BodyDeclaration> methodDecls= targetTypeDecl.bodyDeclarations();
	for (int i= 0; i < methodDecls.size(); i++) {
		Object curr= methodDecls.get(i);
		if (curr instanceof AnnotationTypeMemberDeclaration) {
			return ((AnnotationTypeMemberDeclaration) curr).getModifiers();
		}
	}
	return 0;
}
 
Example #21
Source File: TestQ25.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public void endVisit(AnnotationTypeMemberDeclaration node) {
	if (maxTry < try2)
		maxTry = try2;
	if (minTry > try2)
		minTry = try2;
	try2 = tryStack.pop();
}
 
Example #22
Source File: NewAnnotationMemberProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ASTRewrite getRewrite() throws CoreException {
	CompilationUnit astRoot= ASTResolving.findParentCompilationUnit(fInvocationNode);
	ASTNode typeDecl= astRoot.findDeclaringNode(fSenderBinding);
	ASTNode newTypeDecl= null;
	if (typeDecl != null) {
		newTypeDecl= typeDecl;
	} else {
		astRoot= ASTResolving.createQuickFixAST(getCompilationUnit(), null);
		newTypeDecl= astRoot.findDeclaringNode(fSenderBinding.getKey());
	}
	createImportRewrite(astRoot);

	if (newTypeDecl instanceof AnnotationTypeDeclaration) {
		AnnotationTypeDeclaration newAnnotationTypeDecl= (AnnotationTypeDeclaration) newTypeDecl;

		ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());

		AnnotationTypeMemberDeclaration newStub= getStub(rewrite, newAnnotationTypeDecl);

		List<BodyDeclaration> members= newAnnotationTypeDecl.bodyDeclarations();
		int insertIndex= members.size();

		ListRewrite listRewriter= rewrite.getListRewrite(newAnnotationTypeDecl, AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY);
		listRewriter.insertAt(newStub, insertIndex, null);

		return rewrite;
	}
	return null;
}
 
Example #23
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private Method convert(AnnotationTypeMemberDeclaration memberDeclaration) {
  MethodDescriptor methodDescriptor =
      JdtUtils.createMethodDescriptor(memberDeclaration.resolveBinding());

  return newMethodBuilder(methodDescriptor)
      .setSourcePosition(getSourcePosition(memberDeclaration))
      .build();
}
 
Example #24
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(AnnotationTypeMemberDeclaration node) {
	if (skipNode(node)) {
		return;
	}
	GenericSequentialFlowInfo info = processSequential(node, node.getType(), node.getDefault());
	info.setNoReturn();
}
 
Example #25
Source File: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean consumes(SemanticToken token) {
	StructuralPropertyDescriptor location= token.getNode().getLocationInParent();
	return location == MethodDeclaration.NAME_PROPERTY || location == AnnotationTypeMemberDeclaration.NAME_PROPERTY;
}
 
Example #26
Source File: UtilTools.java    From apidiff with MIT License 4 votes vote down vote up
public static boolean isEqualAnnotationMember(AnnotationTypeMemberDeclaration member1, AnnotationTypeMemberDeclaration member2){
	if(!member1.getName().toString().equals(member2.getName().toString())){
		return false;
	}
	return true;
}
 
Example #27
Source File: SuppressWarningsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Adds a SuppressWarnings proposal if possible and returns whether parent nodes should be processed or not (and with what relevance).
 * 
 * @param cu the compilation unit
 * @param node the node on which to add a SuppressWarning token
 * @param warningToken the warning token to add
 * @param relevance the proposal's relevance
 * @param proposals collector to which the proposal should be added
 * @return <code>0</code> if no further proposals should be added to parent nodes, or the relevance of the next proposal
 * 
 * @since 3.6
 */
private static int addSuppressWarningsProposalIfPossible(ICompilationUnit cu, ASTNode node, String warningToken, int relevance, Collection<ICommandAccess> proposals) {

	ChildListPropertyDescriptor property;
	String name;
	boolean isLocalVariable= false;
	switch (node.getNodeType()) {
		case ASTNode.SINGLE_VARIABLE_DECLARATION:
			property= SingleVariableDeclaration.MODIFIERS2_PROPERTY;
			name= ((SingleVariableDeclaration) node).getName().getIdentifier();
			isLocalVariable= true;
			break;
		case ASTNode.VARIABLE_DECLARATION_STATEMENT:
			property= VariableDeclarationStatement.MODIFIERS2_PROPERTY;
			name= getFirstFragmentName(((VariableDeclarationStatement) node).fragments());
			isLocalVariable= true;
			break;
		case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
			property= VariableDeclarationExpression.MODIFIERS2_PROPERTY;
			name= getFirstFragmentName(((VariableDeclarationExpression) node).fragments());
			isLocalVariable= true;
			break;
		case ASTNode.TYPE_DECLARATION:
			property= TypeDeclaration.MODIFIERS2_PROPERTY;
			name= ((TypeDeclaration) node).getName().getIdentifier();
			break;
		case ASTNode.ANNOTATION_TYPE_DECLARATION:
			property= AnnotationTypeDeclaration.MODIFIERS2_PROPERTY;
			name= ((AnnotationTypeDeclaration) node).getName().getIdentifier();
			break;
		case ASTNode.ENUM_DECLARATION:
			property= EnumDeclaration.MODIFIERS2_PROPERTY;
			name= ((EnumDeclaration) node).getName().getIdentifier();
			break;
		case ASTNode.FIELD_DECLARATION:
			property= FieldDeclaration.MODIFIERS2_PROPERTY;
			name= getFirstFragmentName(((FieldDeclaration) node).fragments());
			break;
		// case ASTNode.INITIALIZER: not used, because Initializer cannot have annotations
		case ASTNode.METHOD_DECLARATION:
			property= MethodDeclaration.MODIFIERS2_PROPERTY;
			name= ((MethodDeclaration) node).getName().getIdentifier() + "()"; //$NON-NLS-1$
			break;
		case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
			property= AnnotationTypeMemberDeclaration.MODIFIERS2_PROPERTY;
			name= ((AnnotationTypeMemberDeclaration) node).getName().getIdentifier() + "()"; //$NON-NLS-1$
			break;
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			property= EnumConstantDeclaration.MODIFIERS2_PROPERTY;
			name= ((EnumConstantDeclaration) node).getName().getIdentifier();
			break;
		default:
			return relevance;
	}

	String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_suppress_warnings_label, new String[] { warningToken, BasicElementLabels.getJavaElementName(name) });
	ASTRewriteCorrectionProposal proposal= new SuppressWarningsProposal(warningToken, label, cu, node, property, relevance);

	proposals.add(proposal);
	return isLocalVariable ? relevance - 1 : 0;
}
 
Example #28
Source File: NewAnnotationMemberProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private AnnotationTypeMemberDeclaration getStub(ASTRewrite rewrite, AnnotationTypeDeclaration targetTypeDecl) {
	AST ast= targetTypeDecl.getAST();

	AnnotationTypeMemberDeclaration decl= ast.newAnnotationTypeMemberDeclaration();

	SimpleName newNameNode= getNewName(rewrite);

	decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, evaluateModifiers(targetTypeDecl)));

	ModifierCorrectionSubProcessor.installLinkedVisibilityProposals(getLinkedProposalModel(), rewrite, decl.modifiers(), true);

	decl.setName(newNameNode);

	Type returnType= getNewType(rewrite);
	decl.setType(returnType);
	return decl;
}
 
Example #29
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private void convertTypeBody(Type type, List<BodyDeclaration> bodyDeclarations) {
  TypeDeclaration currentTypeDeclaration = type.getDeclaration();
  propagateCapturesFromSupertype(currentTypeDeclaration);
  for (BodyDeclaration bodyDeclaration : bodyDeclarations) {
    if (bodyDeclaration instanceof FieldDeclaration) {
      FieldDeclaration fieldDeclaration = (FieldDeclaration) bodyDeclaration;
      type.addFields(convert(fieldDeclaration));
    } else if (bodyDeclaration instanceof MethodDeclaration) {
      MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
      type.addMethod(convert(methodDeclaration));
    } else if (bodyDeclaration instanceof AnnotationTypeMemberDeclaration) {
      AnnotationTypeMemberDeclaration memberDeclaration =
          (AnnotationTypeMemberDeclaration) bodyDeclaration;
      type.addMethod(convert(memberDeclaration));
    } else if (bodyDeclaration instanceof Initializer) {
      Initializer initializer = (Initializer) bodyDeclaration;
      Block block = convert(initializer.getBody());
      if (JdtUtils.isStatic(initializer)) {
        type.addStaticInitializerBlock(block);
      } else {
        type.addInstanceInitializerBlock(block);
      }
    } else if (bodyDeclaration instanceof AbstractTypeDeclaration) {
      // Nested class
      AbstractTypeDeclaration nestedTypeDeclaration = (AbstractTypeDeclaration) bodyDeclaration;
      convert(nestedTypeDeclaration);
    } else {
      throw internalCompilerError(
          "Unexpected type for BodyDeclaration: %s, in type: %s",
          bodyDeclaration.getClass().getName(), type.getDeclaration().getQualifiedSourceName());
    }
  }

  for (Variable capturedVariable : getCapturedVariables(currentTypeDeclaration)) {
    FieldDescriptor fieldDescriptor =
        AstUtils.getFieldDescriptorForCapture(type.getTypeDescriptor(), capturedVariable);
    type.addField(
        Field.Builder.from(fieldDescriptor)
            .setCapturedVariable(capturedVariable)
            .setSourcePosition(type.getSourcePosition())
            .setNameSourcePosition(capturedVariable.getSourcePosition())
            .build());
  }
  if (type.getDeclaration().isCapturingEnclosingInstance()) {
    // add field for enclosing instance.
    type.addField(
        0,
        Field.Builder.from(
                AstUtils.getFieldDescriptorForEnclosingInstance(
                    type.getTypeDescriptor(),
                    type.getEnclosingTypeDeclaration().toUnparameterizedTypeDescriptor()))
            .setSourcePosition(type.getSourcePosition())
            .build());
  }
}
 
Example #30
Source File: JavaParseTreeBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(AnnotationTypeMemberDeclaration node) {
       push(JavaNode.METHOD, getSignature(node), node.getStartPosition(), node.getLength());
       return true;
}