Java Code Examples for org.eclipse.jdt.core.dom.ASTNode#IMPORT_DECLARATION
The following examples show how to use
org.eclipse.jdt.core.dom.ASTNode#IMPORT_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: SemanticHighlightings.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION && nodeType != ASTNode.METHOD_INVOCATION) { return false; } while (nodeType == ASTNode.QUALIFIED_NAME) { node = node.getParent(); nodeType = node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) { return false; } } // 2: match classes IBinding binding = token.getBinding(); return binding instanceof ITypeBinding && ((ITypeBinding) binding).isClass(); }
Example 2
Source File: SemanticHighlightings.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public boolean consumes(SemanticToken token) { // 1: match types SimpleName name = token.getNode(); ASTNode node = name.getParent(); int nodeType = node.getNodeType(); if (nodeType != ASTNode.METHOD_INVOCATION && nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.ENUM_DECLARATION) { return false; } while (nodeType == ASTNode.QUALIFIED_NAME) { node = node.getParent(); nodeType = node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) { return false; } } // 2: match enums IBinding binding = token.getBinding(); return binding instanceof ITypeBinding && ((ITypeBinding) binding).isEnum(); }
Example 3
Source File: SemanticHighlightings.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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.TYPE_DECLARATION) { return false; } while (nodeType == ASTNode.QUALIFIED_NAME) { node = node.getParent(); nodeType = node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) { return false; } } // 2: match interfaces IBinding binding = token.getBinding(); return binding instanceof ITypeBinding && ((ITypeBinding) binding).isInterface(); }
Example 4
Source File: SemanticHighlightings.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@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(); }
Example 5
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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())); } }
Example 6
Source File: SemanticHighlightings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@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.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION && nodeType != ASTNode.METHOD_INVOCATION) return false; while (nodeType == ASTNode.QUALIFIED_NAME) { node= node.getParent(); nodeType= node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) return false; } // 2: match classes IBinding binding= token.getBinding(); return binding instanceof ITypeBinding && ((ITypeBinding) binding).isClass(); }
Example 7
Source File: SemanticHighlightings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean consumes(SemanticToken token) { // 1: match types SimpleName name= token.getNode(); ASTNode node= name.getParent(); int nodeType= node.getNodeType(); if (nodeType != ASTNode.METHOD_INVOCATION && nodeType != ASTNode.SIMPLE_TYPE && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.ENUM_DECLARATION) return false; while (nodeType == ASTNode.QUALIFIED_NAME) { node= node.getParent(); nodeType= node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) return false; } // 2: match enums IBinding binding= token.getBinding(); return binding instanceof ITypeBinding && ((ITypeBinding) binding).isEnum(); }
Example 8
Source File: SemanticHighlightings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@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.TYPE_DECLARATION) return false; while (nodeType == ASTNode.QUALIFIED_NAME) { node= node.getParent(); nodeType= node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) return false; } // 2: match interfaces IBinding binding= token.getBinding(); return binding instanceof ITypeBinding && ((ITypeBinding) binding).isInterface(); }
Example 9
Source File: SemanticHighlightings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@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(); }
Example 10
Source File: SemanticHighlightings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@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.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION && nodeType != ASTNode.METHOD_INVOCATION) return false; while (nodeType == ASTNode.QUALIFIED_NAME) { node= node.getParent(); nodeType= node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) return false; } // 2: match classes IBinding binding= token.getBinding(); if (binding instanceof ITypeBinding) { ITypeBinding typeBinding= (ITypeBinding) binding; // see also ClassHighlighting return typeBinding.isClass() && (typeBinding.getModifiers() & Modifier.ABSTRACT) != 0; } return false; }
Example 11
Source File: ReferencedClassesParser.java From BUILD_file_generator with Apache License 2.0 | 5 votes |
@Override public boolean visit(org.eclipse.jdt.core.dom.QualifiedName node) { if (node.getParent().getNodeType() != ASTNode.IMPORT_DECLARATION) { visitExpressionIfName(node.getQualifier()); } return false; }
Example 12
Source File: SemanticHighlightings.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@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.THIS_EXPRESSION && nodeType != ASTNode.QUALIFIED_TYPE && nodeType != ASTNode.QUALIFIED_NAME && nodeType != ASTNode.TYPE_DECLARATION && nodeType != ASTNode.METHOD_INVOCATION) { return false; } while (nodeType == ASTNode.QUALIFIED_NAME) { node = node.getParent(); nodeType = node.getNodeType(); if (nodeType == ASTNode.IMPORT_DECLARATION) { return false; } } // 2: match classes IBinding binding = token.getBinding(); if (binding instanceof ITypeBinding) { ITypeBinding typeBinding = (ITypeBinding) binding; // see also ClassHighlighting return typeBinding.isClass() && (typeBinding.getModifiers() & Modifier.ABSTRACT) != 0; } return false; }
Example 13
Source File: JavaTextBufferNode.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * 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; }
Example 14
Source File: JavaAddElementFromHistoryImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * 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; }