org.eclipse.jdt.core.dom.ASTNode#ANNOTATION_TYPE_DECLARATION源码实例Demo

下面列出了org.eclipse.jdt.core.dom.ASTNode#ANNOTATION_TYPE_DECLARATION 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: eclipse.jdt.ls   文件: SemanticHighlightings.java
@Override
public boolean consumes(SemanticToken token) {

	// 1: match types
	SimpleName name = token.getNode();
	ASTNode node = name.getParent();
	int nodeType = node.getNodeType();
	if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.ANNOTATION_TYPE_DECLARATION && nodeType != ASTNode.MARKER_ANNOTATION
			&& nodeType != ASTNode.NORMAL_ANNOTATION && nodeType != ASTNode.SINGLE_MEMBER_ANNOTATION) {
		return false;
	}
	while (nodeType == ASTNode.QUALIFIED_NAME) {
		node = node.getParent();
		nodeType = node.getNodeType();
		if (nodeType == ASTNode.IMPORT_DECLARATION) {
			return false;
		}
	}

	// 2: match annotations
	IBinding binding = token.getBinding();
	return binding instanceof ITypeBinding && ((ITypeBinding) binding).isAnnotation();
}
 
源代码2 项目: eclipse.jdt.ls   文件: ModifierRewrite.java
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$
	}
}
 
private static void insertToCu(ASTRewrite rewrite, ASTNode node, CompilationUnit cuNode) {
	switch (node.getNodeType()) {
		case ASTNode.TYPE_DECLARATION:
		case ASTNode.ENUM_DECLARATION:
		case ASTNode.ANNOTATION_TYPE_DECLARATION:
			rewrite.getListRewrite(cuNode, CompilationUnit.TYPES_PROPERTY).insertAt(node, ASTNodes.getInsertionIndex((AbstractTypeDeclaration) node, cuNode.types()), null);
			break;
		case ASTNode.IMPORT_DECLARATION:
			rewrite.getListRewrite(cuNode, CompilationUnit.IMPORTS_PROPERTY).insertLast(node, null);
			break;
		case ASTNode.PACKAGE_DECLARATION:
			// only insert if none exists
			if (cuNode.getPackage() == null)
				rewrite.set(cuNode, CompilationUnit.PACKAGE_PROPERTY, node, null);
			break;
		default:
			Assert.isTrue(false, String.valueOf(node.getNodeType()));
	}
}
 
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$
	}
}
 
@Override
public boolean consumes(SemanticToken token) {

	// 1: match types
	SimpleName name= token.getNode();
	ASTNode node= name.getParent();
	int nodeType= node.getNodeType();
	if (nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE  && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.ANNOTATION_TYPE_DECLARATION
			&& nodeType != ASTNode.MARKER_ANNOTATION && nodeType != ASTNode.NORMAL_ANNOTATION && nodeType != ASTNode.SINGLE_MEMBER_ANNOTATION)
		return false;
	while (nodeType == ASTNode.QUALIFIED_NAME) {
		node= node.getParent();
		nodeType= node.getNodeType();
		if (nodeType == ASTNode.IMPORT_DECLARATION)
			return false;
	}

	// 2: match annotations
	IBinding binding= token.getBinding();
	return binding instanceof ITypeBinding && ((ITypeBinding) binding).isAnnotation();
}
 
源代码6 项目: j2cl   文件: CompilationUnitBuilder.java
private void convert(AbstractTypeDeclaration typeDeclaration) {
  switch (typeDeclaration.getNodeType()) {
    case ASTNode.ANNOTATION_TYPE_DECLARATION:
    case ASTNode.TYPE_DECLARATION:
      convertAndAddType(typeDeclaration);
      break;
    case ASTNode.ENUM_DECLARATION:
      convert((EnumDeclaration) typeDeclaration);
      break;
    default:
      throw internalCompilerError(
          "Unexpected node type for AbstractTypeDeclaration: %s  type name: %s ",
          typeDeclaration.getClass().getName(), typeDeclaration.getName().toString());
  }
}
 
private static void insertToType(ASTRewrite rewrite, ASTNode node, AbstractTypeDeclaration typeDeclaration) {
	switch (node.getNodeType()) {
		case ASTNode.ANNOTATION_TYPE_DECLARATION:
		case ASTNode.ENUM_DECLARATION:
		case ASTNode.TYPE_DECLARATION:
		case ASTNode.METHOD_DECLARATION:
		case ASTNode.FIELD_DECLARATION:
		case ASTNode.INITIALIZER:
			rewrite.getListRewrite(typeDeclaration, typeDeclaration.getBodyDeclarationsProperty()).insertAt(node, ASTNodes.getInsertionIndex((BodyDeclaration) node, typeDeclaration.bodyDeclarations()), null);
			break;
		default:
			Assert.isTrue(false, String.valueOf(node.getNodeType()));
	}
}
 
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;
	}
}
 
/**
 * Returns the corresponding place holder type for the given element.
 * @return a place holder type (see ASTRewrite) or -1 if there is no corresponding placeholder
 */
static final int getPlaceHolderType(ITypedElement element) {

	if (element instanceof DocumentRangeNode) {
		JavaNode jn= (JavaNode) element;
		switch (jn.getTypeCode()) {

		case JavaNode.PACKAGE:
		    return ASTNode.PACKAGE_DECLARATION;

		case JavaNode.CLASS:
		case JavaNode.INTERFACE:
			return ASTNode.TYPE_DECLARATION;

		case JavaNode.ENUM:
			return ASTNode.ENUM_DECLARATION;

		case JavaNode.ANNOTATION:
			return ASTNode.ANNOTATION_TYPE_DECLARATION;

		case JavaNode.CONSTRUCTOR:
		case JavaNode.METHOD:
			return ASTNode.METHOD_DECLARATION;

		case JavaNode.FIELD:
			return ASTNode.FIELD_DECLARATION;

		case JavaNode.INIT:
			return ASTNode.INITIALIZER;

		case JavaNode.IMPORT:
		case JavaNode.IMPORT_CONTAINER:
			return ASTNode.IMPORT_DECLARATION;

		case JavaNode.CU:
		    return ASTNode.COMPILATION_UNIT;
		}
	}
	return -1;
}
 
/**
 * Returns the corresponding place holder type for the given element.
 * @return a place holder type (see ASTRewrite) or -1 if there is no corresponding placeholder
 */
private int getPlaceHolderType(ITypedElement element) {

	if (element instanceof DocumentRangeNode) {
		JavaNode jn= (JavaNode) element;
		switch (jn.getTypeCode()) {

		case JavaNode.PACKAGE:
		    return ASTNode.PACKAGE_DECLARATION;

		case JavaNode.CLASS:
		case JavaNode.INTERFACE:
			return ASTNode.TYPE_DECLARATION;

		case JavaNode.ENUM:
			return ASTNode.ENUM_DECLARATION;

		case JavaNode.ANNOTATION:
			return ASTNode.ANNOTATION_TYPE_DECLARATION;

		case JavaNode.CONSTRUCTOR:
		case JavaNode.METHOD:
			return ASTNode.METHOD_DECLARATION;

		case JavaNode.FIELD:
			return ASTNode.FIELD_DECLARATION;

		case JavaNode.INIT:
			return ASTNode.INITIALIZER;

		case JavaNode.IMPORT:
		case JavaNode.IMPORT_CONTAINER:
			return ASTNode.IMPORT_DECLARATION;

		case JavaNode.CU:
		    return ASTNode.COMPILATION_UNIT;
		}
	}
	return -1;
}
 
protected StructuralPropertyDescriptor getChildPropertyDescriptor(ASTNode parent) {
	switch (parent.getNodeType()) {
		case ASTNode.COMPILATION_UNIT:
			return CompilationUnit.TYPES_PROPERTY;
		case ASTNode.ENUM_DECLARATION:
			return EnumDeclaration.BODY_DECLARATIONS_PROPERTY;
		case ASTNode.ANNOTATION_TYPE_DECLARATION:
			return AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY;
		default:
			return TypeDeclaration.BODY_DECLARATIONS_PROPERTY;
	}
}
 
/**
 * 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;
}