Java Code Examples for org.eclipse.jdt.core.dom.ASTNode#TYPE_DECLARATION
The following examples show how to use
org.eclipse.jdt.core.dom.ASTNode#TYPE_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.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 3
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 4
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 5
Source File: ModifierRewrite.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
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 6
Source File: ModifierRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 7
Source File: ExporterBase.java From txtUML with Eclipse Public License 1.0 | 6 votes |
/** * Creates the appropriate exporter implementation based on the type of the * given node. * * @param <T> * The node type which is parsed by the exporter. */ @SuppressWarnings("unchecked") public static <T extends ASTNode> ExporterBase<T> createExporter(T curElement, PlantUmlCompiler compiler) { switch (curElement.getNodeType()) { case ASTNode.TYPE_DECLARATION: return (ExporterBase<T>) new InteractionExporter(compiler); case ASTNode.METHOD_INVOCATION: return (ExporterBase<T>) MethodInvocationExporter.createExporter(curElement, compiler); case ASTNode.WHILE_STATEMENT: case ASTNode.FOR_STATEMENT: case ASTNode.ENHANCED_FOR_STATEMENT: case ASTNode.DO_STATEMENT: return (ExporterBase<T>) new LoopFragmentExporter(compiler); case ASTNode.IF_STATEMENT: return (ExporterBase<T>) new OptAltFragmentExporter(compiler); } return null; }
Example 8
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 9
Source File: JavaMethodClassCounter.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void postVisit(final ASTNode node) { if (node.getNodeType() == ASTNode.METHOD_DECLARATION) noMethods++; if (node.getNodeType() == ASTNode.TYPE_DECLARATION || node.getNodeType() == ASTNode.ENUM_DECLARATION) noClasses++; }
Example 10
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 11
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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())); } }
Example 12
Source File: JavaMethodClassCounter.java From codemining-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void postVisit(final ASTNode node) { if (node.getNodeType() == ASTNode.METHOD_DECLARATION) noMethods++; if (node.getNodeType() == ASTNode.TYPE_DECLARATION || node.getNodeType() == ASTNode.ENUM_DECLARATION) noClasses++; }
Example 13
Source File: ASTVisitors.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean preVisit2(final ASTNode node) { if (node.getNodeType() == ASTNode.TYPE_DECLARATION || node.getNodeType() == ASTNode.ENUM_DECLARATION) shiftStartPosition(node); preVisit(node); return true; }
Example 14
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 15
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; }
Example 16
Source File: CreateTypeMemberOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException { if (this.createdNode == null) { this.source = removeIndentAndNewLines(this.source, cu); ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(this.source.toCharArray()); parser.setProject(getCompilationUnit().getJavaProject()); parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); ASTNode node = parser.createAST(this.progressMonitor); String createdNodeSource; if (node.getNodeType() != ASTNode.TYPE_DECLARATION) { createdNodeSource = generateSyntaxIncorrectAST(); if (this.createdNode == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); } else { TypeDeclaration typeDeclaration = (TypeDeclaration) node; if ((typeDeclaration.getFlags() & ASTNode.MALFORMED) != 0) { createdNodeSource = generateSyntaxIncorrectAST(); if (this.createdNode == null) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); } else { List bodyDeclarations = typeDeclaration.bodyDeclarations(); if (bodyDeclarations.size() == 0) { throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); } this.createdNode = (ASTNode) bodyDeclarations.iterator().next(); createdNodeSource = this.source; } } if (this.alteredName != null) { SimpleName newName = this.createdNode.getAST().newSimpleName(this.alteredName); SimpleName oldName = rename(this.createdNode, newName); int nameStart = oldName.getStartPosition(); int nameEnd = nameStart + oldName.getLength(); StringBuffer newSource = new StringBuffer(); if (this.source.equals(createdNodeSource)) { newSource.append(createdNodeSource.substring(0, nameStart)); newSource.append(this.alteredName); newSource.append(createdNodeSource.substring(nameEnd)); } else { // syntactically incorrect source int createdNodeStart = this.createdNode.getStartPosition(); int createdNodeEnd = createdNodeStart + this.createdNode.getLength(); newSource.append(createdNodeSource.substring(createdNodeStart, nameStart)); newSource.append(this.alteredName); newSource.append(createdNodeSource.substring(nameEnd, createdNodeEnd)); } this.source = newSource.toString(); } } if (rewriter == null) return this.createdNode; // return a string place holder (instead of the created node) so has to not lose comments and formatting return rewriter.createStringPlaceholder(this.source, this.createdNode.getNodeType()); }
Example 17
Source File: InteractionExporter.java From txtUML with Eclipse Public License 1.0 | 4 votes |
@Override public boolean validElement(ASTNode curElement) { return (curElement.getNodeType() == ASTNode.TYPE_DECLARATION) && (((TypeDeclaration) curElement).getName().toString().equals(compiler.getSeqDiagramName())); }
Example 18
Source File: RefactorProposalUtility.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public MoveTypeInfo(String displayName, String enclosingTypeName, String projectName) { super(displayName, ASTNode.TYPE_DECLARATION, enclosingTypeName, projectName); }
Example 19
Source File: QuickAssistProcessor1.java From codeexamples-eclipse with Eclipse Public License 1.0 | 4 votes |
@Override public boolean hasAssists(IInvocationContext context) throws CoreException { ASTNode coveredNode = context.getCoveredNode(); return coveredNode.getNodeType() == ASTNode.TYPE_DECLARATION; }
Example 20
Source File: SuppressWarningsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * 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; }