Java Code Examples for com.sun.source.tree.ClassTree#getExtendsClause()
The following examples show how to use
com.sun.source.tree.ClassTree#getExtendsClause() .
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: CreateElementUtilities.java From netbeans with Apache License 2.0 | 6 votes |
private static List<? extends TypeMirror> computeClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) { ClassTree ct = (ClassTree) parent.getLeaf(); if (ct.getExtendsClause() == error) { types.add(ElementKind.CLASS); return null; } for (Tree t : ct.getImplementsClause()) { if (t == error) { types.add(ElementKind.INTERFACE); return null; } } //XXX: annotation types... return null; }
Example 2
Source File: CreateElementUtilities.java From netbeans with Apache License 2.0 | 6 votes |
private static List<? extends TypeMirror> computeClass(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) { ClassTree ct = (ClassTree) parent.getLeaf(); if (ct.getExtendsClause() == error) { types.add(ElementKind.CLASS); return null; } for (Tree t : ct.getImplementsClause()) { if (t == error) { types.add(ElementKind.INTERFACE); return null; } } //XXX: annotation types... return null; }
Example 3
Source File: DeptectiveTreeVisitor.java From deptective with Apache License 2.0 | 5 votes |
@Override public Void visitClass(ClassTree node, Void p) { Tree extendsClause = node.getExtendsClause(); if (extendsClause != null) { checkPackageAccess(extendsClause, getQualifiedPackageName(extendsClause)); } node.getImplementsClause().forEach( implementsClause -> checkPackageAccess(implementsClause, getQualifiedPackageName(implementsClause)) ); return super.visitClass(node, p); }
Example 4
Source File: DeptectiveTreeVisitor.java From deptective with Apache License 2.0 | 5 votes |
@Override public Void visitClass(ClassTree node, Void p) { Tree extendsClause = node.getExtendsClause(); if (extendsClause != null) { checkPackageAccess(extendsClause, getQualifiedPackageName(extendsClause)); } node.getImplementsClause().forEach( implementsClause -> checkPackageAccess(implementsClause, getQualifiedPackageName(implementsClause)) ); return super.visitClass(node, p); }
Example 5
Source File: JavadocUtilities.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean isInHeader(CompilationInfo info, ClassTree tree, int offset) { CompilationUnitTree cut = info.getCompilationUnit(); SourcePositions sp = info.getTrees().getSourcePositions(); long lastKnownOffsetInHeader = sp.getStartPosition(cut, tree); List<? extends Tree> impls = tree.getImplementsClause(); List<? extends TypeParameterTree> typeparams; if (impls != null && !impls.isEmpty()) { lastKnownOffsetInHeader= sp.getEndPosition(cut, impls.get(impls.size() - 1)); } else if ((typeparams = tree.getTypeParameters()) != null && !typeparams.isEmpty()) { lastKnownOffsetInHeader= sp.getEndPosition(cut, typeparams.get(typeparams.size() - 1)); } else if (tree.getExtendsClause() != null) { lastKnownOffsetInHeader = sp.getEndPosition(cut, tree.getExtendsClause()); } else if (tree.getModifiers() != null) { lastKnownOffsetInHeader = sp.getEndPosition(cut, tree.getModifiers()); } TokenSequence<JavaTokenId> ts = info.getTreeUtilities().tokensFor(tree); ts.move((int) lastKnownOffsetInHeader); while (ts.moveNext()) { if (ts.token().id() == JavaTokenId.LBRACE) { return offset < ts.offset(); } } return false; }
Example 6
Source File: InterfaceValidator.java From buck with Apache License 2.0 | 5 votes |
@Override public void onTypeDeclared(TypeElement type, TreePath path) { if (type.getKind() == ElementKind.ANNOTATION_TYPE && !ruleInfo.ruleIsRequiredForSourceOnlyAbi()) { trees.printMessage( messageKind, String.format( "Annotation definitions must be in rules with required_for_source_only_abi = True.\n" + "For a quick fix, add required_for_source_only_abi = True to %s.\n" + "A better fix is to move %s to a new rule that contains only\n" + "annotations, and mark that rule required_for_source_only_abi.\n", ruleInfo.getRuleName(), type.getSimpleName()), path.getLeaf(), path.getCompilationUnit()); } ClassTree classTree = (ClassTree) path.getLeaf(); // The compiler can handle superclasses and interfaces that are outright missing // (because it is possible for those to be generated by annotation processors). // However, if a superclass or interface is present, the compiler expects // the entire class hierarchy of that class/interface to also be present, and // gives a sketchy error if they are missing. Tree extendsClause = classTree.getExtendsClause(); if (extendsClause != null) { ensureAbsentOrComplete(type.getSuperclass(), new TreePath(path, extendsClause)); } List<? extends Tree> implementsClause = classTree.getImplementsClause(); if (implementsClause != null) { List<? extends TypeMirror> interfaces = type.getInterfaces(); for (int i = 0; i < implementsClause.size(); i++) { ensureAbsentOrComplete(interfaces.get(i), new TreePath(path, implementsClause.get(i))); } } }
Example 7
Source File: JavaInputAstVisitor.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
public void visitClassDeclaration(ClassTree node) { sync(node); List<Op> breaks = visitModifiers(node.getModifiers(), Direction.VERTICAL, Optional.<BreakTag>absent()); boolean hasSuperclassType = node.getExtendsClause() != null; boolean hasSuperInterfaceTypes = !node.getImplementsClause().isEmpty(); builder.addAll(breaks); token(node.getKind() == Tree.Kind.INTERFACE ? "interface" : "class"); builder.space(); visit(node.getSimpleName()); if (!node.getTypeParameters().isEmpty()) { token("<"); } builder.open(plusFour); { if (!node.getTypeParameters().isEmpty()) { typeParametersRest( node.getTypeParameters(), hasSuperclassType || hasSuperInterfaceTypes ? plusFour : ZERO); } if (hasSuperclassType) { builder.breakToFill(" "); token("extends"); builder.space(); scan(node.getExtendsClause(), null); } if (hasSuperInterfaceTypes) { builder.breakToFill(" "); builder.open(node.getImplementsClause().size() > 1 ? plusFour : ZERO); token(node.getKind() == Tree.Kind.INTERFACE ? "extends" : "implements"); builder.space(); boolean first = true; for (Tree superInterfaceType : node.getImplementsClause()) { if (!first) { token(","); builder.breakOp(" "); } scan(superInterfaceType, null); first = false; } builder.close(); } } builder.close(); if (node.getMembers() == null) { token(";"); } else { addBodyDeclarations(node.getMembers(), BracesOrNot.YES, FirstDeclarationsOrNot.YES); } dropEmptyDeclarations(); }
Example 8
Source File: JavaInputAstVisitor.java From javaide with GNU General Public License v3.0 | 4 votes |
public void visitClassDeclaration(ClassTree node) { sync(node); List<Op> breaks = visitModifiers(node.getModifiers(), Direction.VERTICAL, Optional.<BreakTag>absent()); boolean hasSuperclassType = node.getExtendsClause() != null; boolean hasSuperInterfaceTypes = !node.getImplementsClause().isEmpty(); builder.addAll(breaks); token(node.getKind() == Tree.Kind.INTERFACE ? "interface" : "class"); builder.space(); visit(node.getSimpleName()); if (!node.getTypeParameters().isEmpty()) { token("<"); } builder.open(plusFour); { if (!node.getTypeParameters().isEmpty()) { typeParametersRest( node.getTypeParameters(), hasSuperclassType || hasSuperInterfaceTypes ? plusFour : ZERO); } if (hasSuperclassType) { builder.breakToFill(" "); token("extends"); builder.space(); scan(node.getExtendsClause(), null); } if (hasSuperInterfaceTypes) { builder.breakToFill(" "); builder.open(node.getImplementsClause().size() > 1 ? plusFour : ZERO); token(node.getKind() == Tree.Kind.INTERFACE ? "extends" : "implements"); builder.space(); boolean first = true; for (Tree superInterfaceType : node.getImplementsClause()) { if (!first) { token(","); builder.breakOp(" "); } scan(superInterfaceType, null); first = false; } builder.close(); } } builder.close(); if (node.getMembers() == null) { token(";"); } else { addBodyDeclarations(node.getMembers(), BracesOrNot.YES, FirstDeclarationsOrNot.YES); } dropEmptyDeclarations(); }
Example 9
Source File: ExtImplsLocationCriterion.java From annotation-tools with MIT License | 4 votes |
@Override public boolean isSatisfiedBy(TreePath path) { if (path == null) { return false; } Tree leaf = path.getLeaf(); // System.out.printf("ExtImplsLocationCriterion.isSatisfiedBy(%s):%n leaf=%s (%s)%n", path, leaf, leaf.getClass()); TreePath parentPath = path.getParentPath(); if (parentPath == null) { return false; } Tree parent = parentPath.getLeaf(); if (parent == null) { return false; } // System.out.printf("ExtImplsLocationCriterion.isSatisfiedBy(%s):%n leaf=%s (%s)%n parent=%s (%s)%n", path, leaf, leaf.getClass(), parent, parent.getClass()); boolean returnValue = false; if (index == -1 && leaf.getKind() == Tree.Kind.CLASS) { return ((JCTree.JCClassDecl) leaf).getExtendsClause() == null; } if (CommonScanner.hasClassKind(parent)) { ClassTree ct = (ClassTree) parent; if (index==-1) { Tree ext = ct.getExtendsClause(); if (ext == leaf) { returnValue = true; } } else { List<? extends Tree> impls = ct.getImplementsClause(); if (index < impls.size() && impls.get(index) == leaf) { returnValue = true; } } } if (!returnValue) { return this.isSatisfiedBy(parentPath); } else { return true; } }
Example 10
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 4 votes |
public void visitClassDeclaration(ClassTree node) { sync(node); List<Op> breaks = visitModifiers( node.getModifiers(), Direction.VERTICAL, /* declarationAnnotationBreak= */ Optional.empty()); boolean hasSuperclassType = node.getExtendsClause() != null; boolean hasSuperInterfaceTypes = !node.getImplementsClause().isEmpty(); builder.addAll(breaks); token(node.getKind() == Tree.Kind.INTERFACE ? "interface" : "class"); builder.space(); visit(node.getSimpleName()); if (!node.getTypeParameters().isEmpty()) { token("<"); } builder.open(plusFour); { if (!node.getTypeParameters().isEmpty()) { typeParametersRest( node.getTypeParameters(), hasSuperclassType || hasSuperInterfaceTypes ? plusFour : ZERO); } if (hasSuperclassType) { builder.breakToFill(" "); token("extends"); builder.space(); scan(node.getExtendsClause(), null); } if (hasSuperInterfaceTypes) { builder.breakToFill(" "); builder.open(node.getImplementsClause().size() > 1 ? plusFour : ZERO); token(node.getKind() == Tree.Kind.INTERFACE ? "extends" : "implements"); builder.space(); boolean first = true; for (Tree superInterfaceType : node.getImplementsClause()) { if (!first) { token(","); builder.breakOp(" "); } scan(superInterfaceType, null); first = false; } builder.close(); } } builder.close(); if (node.getMembers() == null) { token(";"); } else { addBodyDeclarations(node.getMembers(), BracesOrNot.YES, FirstDeclarationsOrNot.YES); } dropEmptyDeclarations(); }