public boolean isSpecified(Element e) { if (specifiedVisitor == null) { specifiedVisitor = new SimpleElementVisitor9<Boolean, Void>() { @Override public Boolean visitModule(ModuleElement e, Void p) { return configuration.getSpecifiedModuleElements().contains(e); } @Override public Boolean visitPackage(PackageElement e, Void p) { return configuration.getSpecifiedPackageElements().contains(e); } @Override public Boolean visitType(TypeElement e, Void p) { return configuration.getSpecifiedTypeElements().contains(e); } @Override protected Boolean defaultAction(Element e, Void p) { return false; } }; } return specifiedVisitor.visit(e); }
public boolean shouldDocument(Element e) { if (shouldDocumentVisitor == null) { shouldDocumentVisitor = new SimpleElementVisitor9<Boolean, Void>() { @Override @DefinedBy(Api.LANGUAGE_MODEL) public Boolean visitType(TypeElement e, Void p) { return shouldDocument((ClassSymbol)e); } @Override @DefinedBy(Api.LANGUAGE_MODEL) public Boolean visitVariable(VariableElement e, Void p) { return shouldDocument((VarSymbol)e); } @Override @DefinedBy(Api.LANGUAGE_MODEL) public Boolean visitExecutable(ExecutableElement e, Void p) { return shouldDocument((MethodSymbol)e); } }; } return shouldDocumentVisitor.visit(e); }
/** * Returns true if the element is selected, by applying * the access filter checks. Special treatment is applied to * types, for a top level type the access filter applies completely, * however if is a nested type then it is allowed either if * the enclosing is a static or the enclosing is also selected. * * @param e the element to be checked * @return true if the element is visible */ public boolean isSelected(Element e) { if (toolEnv.isSynthetic((Symbol) e)) { return false; } if (visibleElementVisitor == null) { visibleElementVisitor = new SimpleElementVisitor9<Boolean, Void>() { @Override public Boolean visitType(TypeElement e, Void p) { if (!accessFilter.checkModifier(e)) { return false; // it is not allowed } Element encl = e.getEnclosingElement(); // check if nested if (encl.getKind() == ElementKind.PACKAGE) return true; // top-level class, allow it // is enclosed static if (encl.getModifiers().contains(Modifier.STATIC)) return true; // allowed // check the enclosing return visit(encl); } @Override protected Boolean defaultAction(Element e, Void p) { return accessFilter.checkModifier(e); } @Override public Boolean visitUnknown(Element e, Void p) { throw new AssertionError("unkown element: " + p); } }; } return visibleElementVisitor.visit(e); }
private boolean shouldDocument(Element e) { if (shouldDocumentVisitor == null) { shouldDocumentVisitor = new SimpleElementVisitor9<Boolean, Void>() { private boolean hasSource(TypeElement e) { return configuration.docEnv.getFileKind(e) == javax.tools.JavaFileObject.Kind.SOURCE; } // handle types @Override public Boolean visitType(TypeElement e, Void p) { return configuration.docEnv.isSelected(e) && hasSource(e); } // handle everything else @Override protected Boolean defaultAction(Element e, Void p) { return configuration.docEnv.isSelected(e); } @Override public Boolean visitUnknown(Element e, Void p) { throw new AssertionError("unkown element: " + p); } }; } return shouldDocumentVisitor.visit(e); }
private String getSimpleName0(Element e) { if (snvisitor == null) { snvisitor = new SimpleElementVisitor9<String, Void>() { @Override public String visitModule(ModuleElement e, Void p) { return e.getQualifiedName().toString(); // temp fix for 8182736 } @Override public String visitType(TypeElement e, Void p) { StringBuilder sb = new StringBuilder(e.getSimpleName()); Element enclosed = e.getEnclosingElement(); while (enclosed != null && (enclosed.getKind().isClass() || enclosed.getKind().isInterface())) { sb.insert(0, enclosed.getSimpleName() + "."); enclosed = enclosed.getEnclosingElement(); } return sb.toString(); } @Override public String visitExecutable(ExecutableElement e, Void p) { if (e.getKind() == CONSTRUCTOR || e.getKind() == STATIC_INIT) { return e.getEnclosingElement().getSimpleName().toString(); } return e.getSimpleName().toString(); } @Override protected String defaultAction(Element e, Void p) { return e.getSimpleName().toString(); } }; } return snvisitor.visit(e); }
private String getSimpleName0(Element e) { if (snvisitor == null) { snvisitor = new SimpleElementVisitor9<String, Void>() { @Override @DefinedBy(Api.LANGUAGE_MODEL) public String visitType(TypeElement e, Void p) { StringBuilder sb = new StringBuilder(e.getSimpleName()); Element enclosed = e.getEnclosingElement(); while (enclosed != null && (enclosed.getKind().isClass() || enclosed.getKind().isInterface())) { sb.insert(0, enclosed.getSimpleName() + "."); enclosed = enclosed.getEnclosingElement(); } return sb.toString(); } @Override @DefinedBy(Api.LANGUAGE_MODEL) public String visitExecutable(ExecutableElement e, Void p) { if (e.getKind() == CONSTRUCTOR || e.getKind() == STATIC_INIT) { return e.getEnclosingElement().getSimpleName().toString(); } return e.getSimpleName().toString(); } @Override @DefinedBy(Api.LANGUAGE_MODEL) protected String defaultAction(Element e, Void p) { return e.getSimpleName().toString(); } }; } return snvisitor.visit(e); }
public boolean isIncluded(Element e) { if (e == null) { return false; } if (includedVisitor == null) { includedVisitor = new SimpleElementVisitor9<Boolean, Void>() { @Override @DefinedBy(Api.LANGUAGE_MODEL) public Boolean visitType(TypeElement e, Void p) { if (includedSet.contains(e)) { return true; } if (shouldDocument(e)) { // Class is nameable from top-level and // the class and all enclosing classes // pass the modifier filter. PackageElement pkg = elements.getPackageOf(e); if (includedSet.contains(pkg)) { setIncluded(e); return true; } Element enclosing = e.getEnclosingElement(); if (enclosing != null && includedSet.contains(enclosing)) { setIncluded(e); return true; } } return false; } @Override @DefinedBy(Api.LANGUAGE_MODEL) public Boolean visitPackage(PackageElement e, Void p) { return includedSet.contains(e); } @Override @DefinedBy(Api.LANGUAGE_MODEL) public Boolean visitUnknown(Element e, Void p) { throw new AssertionError("unknown element: " + e); } @Override @DefinedBy(Api.LANGUAGE_MODEL) public Boolean defaultAction(Element e, Void p) { return visit(e.getEnclosingElement()) && shouldDocument(e); } }; } return includedVisitor.visit(e); }