Java Code Examples for com.sun.tools.javac.code.Symbol#getEnclosingElement()
The following examples show how to use
com.sun.tools.javac.code.Symbol#getEnclosingElement() .
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: SourceAnalyzerFactory.java From netbeans with Apache License 2.0 | 6 votes |
@Override @CheckForNull public Void visitNewClass(@NonNull final NewClassTree node, @NonNull final Map<Pair<BinaryName,String>, UsagesData<String>> p) { final Symbol sym = ((JCTree.JCNewClass)node).constructor; if (sym != null) { final Symbol owner = sym.getEnclosingElement(); if (owner != null && owner.getKind().isClass()) { addUsage( owner, activeClass.peek(), p, ClassIndexImpl.UsageType.METHOD_REFERENCE); } } return super.visitNewClass (node,p); }
Example 2
Source File: RClassScanner.java From convalida with Apache License 2.0 | 5 votes |
@Override public void visitSelect(JCTree.JCFieldAccess jcFieldAccess) { Symbol symbol = jcFieldAccess.sym; if (symbol != null && symbol.getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement().enclClass() != null) { Set<String> rClassSet = rClasses.get(currentPackageName); if (rClassSet == null) { rClassSet = new HashSet<>(); rClasses.put(currentPackageName, rClassSet); } rClassSet.add(symbol.getEnclosingElement().getEnclosingElement().enclClass().className()); } }
Example 3
Source File: SourceAnalyzerFactory.java From netbeans with Apache License 2.0 | 5 votes |
private boolean hasErrorName (@NullAllowed Symbol cs) { while (cs != null) { if (cs.name == names.error) { return true; } cs = cs.getEnclosingElement(); } return false; }
Example 4
Source File: UStaticIdent.java From Refaster with Apache License 2.0 | 5 votes |
@Override @Nullable protected Unifier defaultAction(Tree node, @Nullable Unifier unifier) { Symbol symbol = ASTHelpers.getSymbol(node); if (symbol != null && symbol.getEnclosingElement() != null && symbol.getEnclosingElement().getQualifiedName() .contentEquals(classIdent().getQualifiedName()) && symbol.getSimpleName().contentEquals(member())) { return memberType().unify(symbol.asType(), unifier); } return null; }
Example 5
Source File: ButterKnifeProcessor.java From butterknife with Apache License 2.0 | 5 votes |
@Nullable private Id parseId(Symbol symbol) { Id id = null; if (symbol.getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement() != null && symbol.getEnclosingElement().getEnclosingElement().enclClass() != null) { try { int value = (Integer) requireNonNull(((Symbol.VarSymbol) symbol).getConstantValue()); id = new Id(value, symbol); } catch (Exception ignored) { } } return id; }
Example 6
Source File: StrictJavaDepsPlugin.java From bazel with Apache License 2.0 | 4 votes |
/** * Marks the provided dependency as a direct/explicit dependency. Additionally, if * strict_java_deps is enabled, it emits a [strict] compiler warning/error. */ private void collectExplicitDependency(Path jarPath, JCTree node, Symbol sym) { // Does it make sense to emit a warning/error for this pair of (type, owner)? // We want to emit only one error/warning per owner. if (!directJars.contains(jarPath) && seenStrictDepsViolatingJars.add(jarPath)) { // IO cost here is fine because we only hit this path for an explicit dependency // _not_ in the direct jars, i.e. an error JarOwner owner = readJarOwnerFromManifest(jarPath); if (seenTargets.add(owner)) { // owner is of the form "//label/of:rule <Aspect name>" where <Aspect name> is // optional. Optional<String> canonicalTargetName = owner.label().map(label -> canonicalizeTarget(label)); missingTargets.add(owner); String toolInfo = owner.aspect().isPresent() ? String.format( "%s wrapped in %s", canonicalTargetName.get(), owner.aspect().get()) : canonicalTargetName.isPresent() ? canonicalTargetName.get() : owner.jar().toString(); String used = sym.getSimpleName().contentEquals("package-info") ? "package " + sym.getEnclosingElement() : "type " + sym; String message = String.format( "[strict] Using %s from an indirect dependency (TOOL_INFO: \"%s\").%s", used, toolInfo, (owner.label().isPresent() ? " See command below **" : "")); diagnostics.add(SjdDiagnostic.create(node.pos, message, source)); } } if (!directDependenciesMap.containsKey(jarPath)) { // Also update the dependency proto Dependency dep = Dependency.newBuilder() // Path.toString uses the platform separator (`\` on Windows) which may not // match the format in params files (which currently always use `/`, see // bazelbuild/bazel#4108). JavaBuilder should always parse Path strings into // java.nio.file.Paths before comparing them. .setPath(jarPath.toString()) .setKind(Dependency.Kind.EXPLICIT) .build(); directDependenciesMap.put(jarPath, dep); } }