Java Code Examples for org.eclipse.jdt.core.dom.ASTNode#ENUM_CONSTANT_DECLARATION

The following examples show how to use org.eclipse.jdt.core.dom.ASTNode#ENUM_CONSTANT_DECLARATION . 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: Invocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 7 votes vote down vote up
public static Expression getExpression(ASTNode invocation) {
	switch (invocation.getNodeType()) {
		case ASTNode.METHOD_INVOCATION:
			return ((MethodInvocation)invocation).getExpression();
		case ASTNode.SUPER_METHOD_INVOCATION:
			return null;
			
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return null;
		case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
			return ((SuperConstructorInvocation)invocation).getExpression();
			
		case ASTNode.CLASS_INSTANCE_CREATION:
			return ((ClassInstanceCreation)invocation).getExpression();
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return null;
			
		default:
			throw new IllegalArgumentException(invocation.toString());
	}
}
 
Example 2
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 3
Source File: Invocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static List<Expression> getArguments(ASTNode invocation) {
	switch (invocation.getNodeType()) {
		case ASTNode.METHOD_INVOCATION:
			return ((MethodInvocation)invocation).arguments();
		case ASTNode.SUPER_METHOD_INVOCATION:
			return ((SuperMethodInvocation)invocation).arguments();
			
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return ((ConstructorInvocation)invocation).arguments();
		case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
			return ((SuperConstructorInvocation)invocation).arguments();
			
		case ASTNode.CLASS_INSTANCE_CREATION:
			return ((ClassInstanceCreation)invocation).arguments();
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return ((EnumConstantDeclaration)invocation).arguments();
			
		default:
			throw new IllegalArgumentException(invocation.toString());
	}
}
 
Example 4
Source File: Invocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ChildListPropertyDescriptor getArgumentsProperty(ASTNode invocation) {
	switch (invocation.getNodeType()) {
		case ASTNode.METHOD_INVOCATION:
			return MethodInvocation.ARGUMENTS_PROPERTY;
		case ASTNode.SUPER_METHOD_INVOCATION:
			return SuperMethodInvocation.ARGUMENTS_PROPERTY;
			
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return ConstructorInvocation.ARGUMENTS_PROPERTY;
		case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
			return SuperConstructorInvocation.ARGUMENTS_PROPERTY;
			
		case ASTNode.CLASS_INSTANCE_CREATION:
			return ClassInstanceCreation.ARGUMENTS_PROPERTY;
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return EnumConstantDeclaration.ARGUMENTS_PROPERTY;
			
		default:
			throw new IllegalArgumentException(invocation.toString());
	}
}
 
Example 5
Source File: Invocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isInvocationWithArguments(ASTNode node) {
	switch (node.getNodeType()) {
		case ASTNode.METHOD_INVOCATION:
		case ASTNode.SUPER_METHOD_INVOCATION:
			
		case ASTNode.CONSTRUCTOR_INVOCATION:
		case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
			
		case ASTNode.CLASS_INSTANCE_CREATION:
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return true;
			
		default:
			return false;
	}
}
 
Example 6
Source File: Invocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static IMethodBinding resolveBinding(ASTNode invocation) {
	switch (invocation.getNodeType()) {
		case ASTNode.METHOD_INVOCATION:
			return ((MethodInvocation)invocation).resolveMethodBinding();
		case ASTNode.SUPER_METHOD_INVOCATION:
			return ((SuperMethodInvocation)invocation).resolveMethodBinding();
			
		case ASTNode.CONSTRUCTOR_INVOCATION:
			return ((ConstructorInvocation)invocation).resolveConstructorBinding();
		case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
			return ((SuperConstructorInvocation)invocation).resolveConstructorBinding();
			
		case ASTNode.CLASS_INSTANCE_CREATION:
			return ((ClassInstanceCreation)invocation).resolveConstructorBinding();
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			return ((EnumConstantDeclaration)invocation).resolveConstructorBinding();
			
		default:
			throw new IllegalArgumentException(invocation.toString());
	}
}
 
Example 7
Source File: CallInliner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void flowAnalysis() {
	fInvocationScope= fRootScope.findScope(fTargetNode.getStartPosition(), fTargetNode.getLength());
	fInvocationScope.setCursor(fTargetNode.getStartPosition());
	fFlowContext= new FlowContext(0, fNumberOfLocals + 1);
	fFlowContext.setConsiderAccessMode(true);
	fFlowContext.setComputeMode(FlowContext.ARGUMENTS);
	Selection selection= Selection.createFromStartLength(fInvocation.getStartPosition(), fInvocation.getLength());
	switch (fBodyDeclaration.getNodeType()) {
		case ASTNode.INITIALIZER:
		case ASTNode.FIELD_DECLARATION:
		case ASTNode.METHOD_DECLARATION:
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			fFlowInfo= new InputFlowAnalyzer(fFlowContext, selection, true).perform(fBodyDeclaration);
			break;
		default:
			Assert.isTrue(false, "Should not happen");			 //$NON-NLS-1$
	}
}
 
Example 8
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 9
Source File: UnimplementedCodeFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ASTNode getSelectedTypeNode(CompilationUnit root, IProblemLocation problem) {
	ASTNode selectedNode= problem.getCoveringNode(root);
	if (selectedNode == null)
		return null;

	if (selectedNode.getNodeType() == ASTNode.ANONYMOUS_CLASS_DECLARATION) { // bug 200016
		selectedNode= selectedNode.getParent();
	}

	if (selectedNode.getLocationInParent() == EnumConstantDeclaration.NAME_PROPERTY) {
		selectedNode= selectedNode.getParent();
	}
	if (selectedNode.getNodeType() == ASTNode.SIMPLE_NAME && selectedNode.getParent() instanceof AbstractTypeDeclaration) {
		return selectedNode.getParent();
	} else if (selectedNode.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
		return ((ClassInstanceCreation) selectedNode).getAnonymousClassDeclaration();
	} else if (selectedNode.getNodeType() == ASTNode.ENUM_CONSTANT_DECLARATION) {
		EnumConstantDeclaration enumConst= (EnumConstantDeclaration) selectedNode;
		if (enumConst.getAnonymousClassDeclaration() != null)
			return enumConst.getAnonymousClassDeclaration();
		return enumConst;
	} else {
		return null;
	}
}
 
Example 10
Source File: DOMFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(AnonymousClassDeclaration node) {
	ASTNode name;
	ASTNode parent = node.getParent();
	switch (parent.getNodeType()) {
		case ASTNode.CLASS_INSTANCE_CREATION:
			name = ((ClassInstanceCreation) parent).getType();
			if (name.getNodeType() == ASTNode.PARAMETERIZED_TYPE) {
				name = ((ParameterizedType) name).getType();
			}
			break;
		case ASTNode.ENUM_CONSTANT_DECLARATION:
			name = ((EnumConstantDeclaration) parent).getName();
			break;
		default:
			return true;
	}
	if (found(node, name) && this.resolveBinding)
		this.foundBinding = node.resolveBinding();
	return true;
}
 
Example 11
Source File: SortMembersOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isSortPreserved(BodyDeclaration bodyDeclaration) {
	switch (bodyDeclaration.getNodeType()) {
		case ASTNode.FIELD_DECLARATION:
		case ASTNode.ENUM_CONSTANT_DECLARATION:
		case ASTNode.INITIALIZER:
			return true;
		default:
			return false;
	}
}
 
Example 12
Source File: SourceField.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ASTNode findNode(org.eclipse.jdt.core.dom.CompilationUnit ast) {
	// For field declarations, a variable declaration fragment is returned
	// Return the FieldDeclaration instead
	// For enum constant declaration, we return the node directly
	ASTNode node = super.findNode(ast);
	if (node == null) return null;
	if (node.getNodeType() == ASTNode.ENUM_CONSTANT_DECLARATION) {
		return node;
	}
	return node.getParent();
}
 
Example 13
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;
}