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

The following examples show how to use org.eclipse.jdt.core.dom.ASTNode#ANNOTATION_TYPE_MEMBER_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: 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: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static boolean isStatic(BodyDeclaration bodyDeclaration) {
	if (isNestedInterfaceOrAnnotation(bodyDeclaration)) {
		return true;
	}
	int nodeType= bodyDeclaration.getNodeType();
	if (!(nodeType == ASTNode.METHOD_DECLARATION || nodeType == ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION) &&
			isInterfaceOrAnnotationMember(bodyDeclaration)) {
		return true;
	}
	if (bodyDeclaration instanceof EnumConstantDeclaration) {
		return true;
	}
	if (bodyDeclaration instanceof EnumDeclaration && bodyDeclaration.getParent() instanceof AbstractTypeDeclaration) {
		return true;
	}
	return Modifier.isStatic(bodyDeclaration.getModifiers());
}
 
Example 3
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 4
Source File: ASTNodes.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static int getOrderPreference(BodyDeclaration member, MembersOrderPreferenceCache store) {
	int memberType= member.getNodeType();
	int modifiers= member.getModifiers();

	switch (memberType) {
		case ASTNode.TYPE_DECLARATION:
		case ASTNode.ENUM_DECLARATION :
		case ASTNode.ANNOTATION_TYPE_DECLARATION :
			return store.getCategoryIndex(MembersOrderPreferenceCache.TYPE_INDEX) * 2;
		case ASTNode.FIELD_DECLARATION:
			if (Modifier.isStatic(modifiers)) {
				int index= store.getCategoryIndex(MembersOrderPreferenceCache.STATIC_FIELDS_INDEX) * 2;
				if (Modifier.isFinal(modifiers)) {
					return index; // first final static, then static
				}
				return index + 1;
			}
			return store.getCategoryIndex(MembersOrderPreferenceCache.FIELDS_INDEX) * 2;
		case ASTNode.INITIALIZER:
			if (Modifier.isStatic(modifiers)) {
				return store.getCategoryIndex(MembersOrderPreferenceCache.STATIC_INIT_INDEX) * 2;
			}
			return store.getCategoryIndex(MembersOrderPreferenceCache.INIT_INDEX) * 2;
		case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
			return store.getCategoryIndex(MembersOrderPreferenceCache.METHOD_INDEX) * 2;
		case ASTNode.METHOD_DECLARATION:
			if (Modifier.isStatic(modifiers)) {
				return store.getCategoryIndex(MembersOrderPreferenceCache.STATIC_METHODS_INDEX) * 2;
			}
			if (((MethodDeclaration) member).isConstructor()) {
				return store.getCategoryIndex(MembersOrderPreferenceCache.CONSTRUCTORS_INDEX) * 2;
			}
			return store.getCategoryIndex(MembersOrderPreferenceCache.METHOD_INDEX) * 2;
		default:
			return 100;
	}
}
 
Example 5
Source File: JdtFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isStatic(BodyDeclaration bodyDeclaration) {
	if (isNestedInterfaceOrAnnotation(bodyDeclaration))
		return true;
	int nodeType= bodyDeclaration.getNodeType();
	if (!(nodeType == ASTNode.METHOD_DECLARATION || nodeType == ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION) &&
			isInterfaceOrAnnotationMember(bodyDeclaration))
		return true;
	if (bodyDeclaration instanceof EnumConstantDeclaration)
		return true;
	if (bodyDeclaration instanceof EnumDeclaration && bodyDeclaration.getParent() instanceof AbstractTypeDeclaration)
		return true;
	return Modifier.isStatic(bodyDeclaration.getModifiers());
}
 
Example 6
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 7
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;
}