com.sun.tools.javac.code.Symbol Java Examples

The following examples show how to use com.sun.tools.javac.code.Symbol. 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: RestrictiveAnnotationHandler.java    From NullAway with MIT License 6 votes vote down vote up
@Override
public boolean onOverrideMayBeNullExpr(
    NullAway analysis, ExpressionTree expr, VisitorState state, boolean exprMayBeNull) {
  if (expr.getKind().equals(Tree.Kind.METHOD_INVOCATION)) {
    Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol((MethodInvocationTree) expr);
    if (NullabilityUtil.isUnannotated(methodSymbol, config)) {
      // with the generated-as-unannotated option enabled, we want to ignore
      // annotations in generated code
      if (config.treatGeneratedAsUnannotated() && NullabilityUtil.isGenerated(methodSymbol)) {
        return exprMayBeNull;
      } else {
        return Nullness.hasNullableAnnotation(methodSymbol, config) || exprMayBeNull;
      }
    } else {
      return exprMayBeNull;
    }
  }
  return exprMayBeNull;
}
 
Example #2
Source File: BasicAnnoTests.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public Void scan(Element elem, Void ignore) {
    AnnotationMirror test = getAnnotation(elem, Test.class.getName().replace('$', '.'));
    if (test != null) {
        out.println("Test: " + elem + " " + test);
        TestTypeScanner s = new TestTypeScanner(elem, test);
        s.scan(elem.asType(), null);
        if (getPosn(test) >= s.count)
            error(elem, "position " + getPosn(test) + " not found");
        if (!s.found) {
            dprinter.printSymbol("element", (Symbol) elem);
            dprinter.printType("type", (Type) elem.asType());
        }
        out.println();
    }
    return super.scan(elem, ignore);
}
 
Example #3
Source File: RichDiagnosticFormatter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Preprocess a diagnostic argument. A type/symbol argument is
 * preprocessed by specialized type/symbol preprocessors.
 *
 * @param arg the argument to be translated
 */
protected void preprocessArgument(Object arg) {
    if (arg instanceof Type) {
        preprocessType((Type)arg);
    }
    else if (arg instanceof Symbol) {
        preprocessSymbol((Symbol)arg);
    }
    else if (arg instanceof JCDiagnostic) {
        preprocessDiagnostic((JCDiagnostic)arg);
    }
    else if (arg instanceof Iterable<?>) {
        for (Object o : (Iterable<?>)arg) {
            preprocessArgument(o);
        }
    }
}
 
Example #4
Source File: ManResolve.java    From manifold with Apache License 2.0 6 votes vote down vote up
/**
 * Allow @Jailbreak to expose otherwise inaccessible features
 */
@Override
public boolean isAccessible( Env<AttrContext> env, Type site, Symbol sym, boolean checkInner )
{
  boolean accessible = super.isAccessible( env, site, sym, checkInner );
  if( accessible )
  {
    return true;
  }

  if( isJailbreak( sym ) )
  {
    return true;
  }
  return isJailbreak( env.tree );
}
 
Example #5
Source File: CheckAttributedTree.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
Field checkFields(JCTree t) {
    List<Field> fieldsToCheck = treeUtil.getFieldsOfType(t,
            excludedFields,
            Symbol.class,
            Type.class);
    for (Field f : fieldsToCheck) {
        try {
            if (f.get(t) == null) {
                return f;
            }
        }
        catch (IllegalAccessException e) {
            System.err.println("Cannot read field: " + f);
            //swallow it
        }
    }
    return null;
}
 
Example #6
Source File: TestInvokeDynamic.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
    super.visitMethodInvocation(node, p);
    JCMethodInvocation apply = (JCMethodInvocation)node;
    JCIdent ident = (JCIdent)apply.meth;
    Symbol oldSym = ident.sym;
    if (!oldSym.isConstructor()) {
        Object[] staticArgs = new Object[arity.arity];
        for (int i = 0; i < arity.arity ; i++) {
            staticArgs[i] = saks[i].getValue(syms, names, types);
        }
        ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
                oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
    }
    return null;
}
 
Example #7
Source File: RichDiagnosticFormatter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Preprocess a diagnostic argument. A type/symbol argument is
 * preprocessed by specialized type/symbol preprocessors.
 *
 * @param arg the argument to be translated
 */
protected void preprocessArgument(Object arg) {
    if (arg instanceof Type) {
        preprocessType((Type)arg);
    }
    else if (arg instanceof Symbol) {
        preprocessSymbol((Symbol)arg);
    }
    else if (arg instanceof JCDiagnostic) {
        preprocessDiagnostic((JCDiagnostic)arg);
    }
    else if (arg instanceof Iterable<?>) {
        for (Object o : (Iterable<?>)arg) {
            preprocessArgument(o);
        }
    }
}
 
Example #8
Source File: JavaCompiler.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Resolve an identifier.
 * @param msym      The module in which the search should be performed
 * @param name      The identifier to resolve
 */
public Symbol resolveIdent(ModuleSymbol msym, String name) {
    if (name.equals(""))
        return syms.errSymbol;
    JavaFileObject prev = log.useSource(null);
    try {
        JCExpression tree = null;
        for (String s : name.split("\\.", -1)) {
            if (!SourceVersion.isIdentifier(s)) // TODO: check for keywords
                return syms.errSymbol;
            tree = (tree == null) ? make.Ident(names.fromString(s))
                                  : make.Select(tree, names.fromString(s));
        }
        JCCompilationUnit toplevel =
            make.TopLevel(List.nil());
        toplevel.modle = msym;
        toplevel.packge = msym.unnamedPackage;
        return attr.attribIdent(tree, toplevel);
    } finally {
        log.useSource(prev);
    }
}
 
Example #9
Source File: ClassDocImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds all inner classes of this class, and their
 * inner classes recursively, to the list l.
 */
void addAllClasses(ListBuffer<ClassDocImpl> l, boolean filtered) {
    try {
        if (isSynthetic()) return;
        // sometimes synthetic classes are not marked synthetic
        if (!JavadocTool.isValidClassName(tsym.name.toString())) return;
        if (filtered && !env.shouldDocument(tsym)) return;
        if (l.contains(this)) return;
        l.append(this);
        List<ClassDocImpl> more = List.nil();
        for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) {
            if (sym != null && sym.kind == TYP) {
                ClassSymbol s = (ClassSymbol)sym;
                ClassDocImpl c = env.getClassDoc(s);
                if (c.isSynthetic()) continue;
                if (c != null) more = more.prepend(c);
            }
        }
        // this extra step preserves the ordering from oldjavadoc
        for (; more.nonEmpty(); more=more.tail) {
            more.head.addAllClasses(l, filtered);
        }
    } catch (CompletionFailure e) {
        // quietly ignore completion failures
    }
}
 
Example #10
Source File: RichDiagnosticFormatter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Preprocess a diagnostic argument. A type/symbol argument is
 * preprocessed by specialized type/symbol preprocessors.
 *
 * @param arg the argument to be translated
 */
protected void preprocessArgument(Object arg) {
    if (arg instanceof Type) {
        preprocessType((Type)arg);
    }
    else if (arg instanceof Symbol) {
        preprocessSymbol((Symbol)arg);
    }
    else if (arg instanceof JCDiagnostic) {
        preprocessDiagnostic((JCDiagnostic)arg);
    }
    else if (arg instanceof Iterable<?> && !(arg instanceof Path)) {
        for (Object o : (Iterable<?>)arg) {
            preprocessArgument(o);
        }
    }
}
 
Example #11
Source File: ResolveHarness.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
void process(Diagnostic<? extends JavaFileObject> diagnostic) {
    Element siteSym = getSiteSym(diagnostic);
    if (siteSym.getSimpleName().length() != 0 &&
            ((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) {
        return;
    }
    int candidateIdx = 0;
    for (JCDiagnostic d : subDiagnostics(diagnostic)) {
        boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic);
        VerboseCandidateSubdiagProcessor subProc =
                new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic));
        if (subProc.matches(d)) {
            subProc.process(d);
        } else {
            throw new AssertionError("Bad subdiagnostic: " + d.getCode());
        }
    }
}
 
Example #12
Source File: NullAway.java    From NullAway with MIT License 6 votes vote down vote up
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
  if (methodSymbol == null) {
    throw new RuntimeException("not expecting unresolved method here");
  }
  List<? extends ExpressionTree> actualParams = tree.getArguments();
  if (tree.getClassBody() != null && actualParams.size() > 0) {
    // passing parameters to constructor of anonymous class
    // this constructor just invokes the constructor of the superclass, and
    // in the AST does not have the parameter nullability annotations from the superclass.
    // so, treat as if the superclass constructor is being invoked directly
    // see https://github.com/uber/NullAway/issues/102
    methodSymbol = getSymbolOfSuperConstructor(methodSymbol, state);
  }
  return handleInvocation(tree, state, methodSymbol, actualParams);
}
 
Example #13
Source File: JavacBinder.java    From manifold with Apache License 2.0 6 votes vote down vote up
private Symbol.MethodSymbol resolveOperatorMethod( Type left, Type right, Tag operator )
{
  // Handle operator overloading

  boolean swapped = false;
  Symbol.MethodSymbol overloadOperator = ManAttr.resolveOperatorMethod( _types, operator, left, right );
  if( overloadOperator == null && ManAttr.isCommutative( operator ) )
  {
    overloadOperator = ManAttr.resolveOperatorMethod( _types, operator, right, left );
    swapped = true;
  }
  if( overloadOperator != null )
  {
    return new OverloadOperatorSymbol( overloadOperator, swapped );
  }

  return null;
}
 
Example #14
Source File: RichDiagnosticFormatter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected String className(ClassType t, boolean longform, Locale locale) {
    Symbol sym = t.tsym;
    if (sym.name.length() == 0 ||
            !getConfiguration().isEnabled(RichFormatterFeature.SIMPLE_NAMES)) {
        return super.className(t, longform, locale);
    }
    else if (longform)
        return nameSimplifier.simplify(sym).toString();
    else
        return sym.name.toString();
}
 
Example #15
Source File: ManAttr.java    From manifold with Apache License 2.0 5 votes vote down vote up
default boolean handleOperatorOverloading( JCBinary tree, Type left, Type right )
{
  // Handle operator overloading
  boolean swapped = false;
  Symbol.MethodSymbol overloadOperator = ManAttr.resolveOperatorMethod( types(), tree.getTag(), left, right );
  if( overloadOperator == null && ManAttr.isCommutative( tree.getTag() ) )
  {
    overloadOperator = ManAttr.resolveOperatorMethod( types(), tree.getTag(), right, left );
    swapped = true;
  }
  if( overloadOperator != null )
  {
    if( overloadOperator.name.toString().equals( COMPARE_TO ) )
    {
      // pose with boolean return to satisfy type checker, this call will be transformed in ext transformer
      Type.MethodType typePoseWithBooleanReturn = new Type.MethodType( overloadOperator.type.getParameterTypes(), syms().booleanType,
        overloadOperator.type.getThrownTypes(), syms().methodClass );
      overloadOperator = new OverloadOperatorSymbol( overloadOperator, typePoseWithBooleanReturn, swapped );
    }
    else
    {
      overloadOperator = new OverloadOperatorSymbol( overloadOperator, swapped );
    }
    IDynamicJdk.instance().setOperator( tree, (Symbol.OperatorSymbol)overloadOperator );
    Type owntype = overloadOperator.type.isErroneous()
                   ? overloadOperator.type
                   : swapped
                     ? types().memberType( right, overloadOperator ).getReturnType()
                     : types().memberType( left, overloadOperator ).getReturnType();
    setResult( tree, owntype );
    return true;
  }
  return false;
}
 
Example #16
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
LambdaTranslationContext(JCLambda tree) {
    super(tree);
    Frame frame = frameStack.head;
    switch (frame.tree.getTag()) {
        case VARDEF:
            assignedTo = self = ((JCVariableDecl) frame.tree).sym;
            break;
        case ASSIGN:
            self = null;
            assignedTo = TreeInfo.symbol(((JCAssign) frame.tree).getVariable());
            break;
        default:
            assignedTo = self = null;
            break;
     }

    // This symbol will be filled-in in complete
    this.translatedSym = makePrivateSyntheticMethod(0, null, null, owner.enclClass());

    translatedSymbols = new EnumMap<>(LambdaSymbolKind.class);

    translatedSymbols.put(PARAM, new LinkedHashMap<Symbol, Symbol>());
    translatedSymbols.put(LOCAL_VAR, new LinkedHashMap<Symbol, Symbol>());
    translatedSymbols.put(CAPTURED_VAR, new LinkedHashMap<Symbol, Symbol>());
    translatedSymbols.put(CAPTURED_THIS, new LinkedHashMap<Symbol, Symbol>());
    translatedSymbols.put(CAPTURED_OUTER_THIS, new LinkedHashMap<Symbol, Symbol>());
    translatedSymbols.put(TYPE_VAR, new LinkedHashMap<Symbol, Symbol>());

    freeVarProcessedLocalClasses = new HashSet<>();
}
 
Example #17
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private static Symbol.MethodSymbol resolveMethod( JCDiagnostic.DiagnosticPosition pos, Context ctx, JCTree.JCCompilationUnit compUnit, Name name, Type qual, List<Type> args )
{
  Resolve rs = Resolve.instance( ctx );
  AttrContext attrContext = new AttrContext();
  Env<AttrContext> env = new AttrContextEnv( pos.getTree(), attrContext );
  env.toplevel = compUnit;
  return rs.resolveInternalMethod( pos, env, qual, name, args, null );
}
 
Example #18
Source File: LambdaToMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the declaration corresponding to a symbol in the enclosing
 * scope; the depth parameter is used to filter out symbols defined
 * in nested scopes (which do not need to undergo capture).
 */
private JCTree capturedDecl(int depth, Symbol sym) {
    int currentDepth = frameStack.size() - 1;
    for (Frame block : frameStack) {
        switch (block.tree.getTag()) {
            case CLASSDEF:
                ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
                if (clazz.isSubClass(sym, types) || sym.isMemberOf(clazz, types)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case VARDEF:
                if (((JCVariableDecl)block.tree).sym == sym &&
                        sym.owner.kind == MTH) { //only locals are captured
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            case BLOCK:
            case METHODDEF:
            case LAMBDA:
                if (block.locals != null && block.locals.contains(sym)) {
                    return currentDepth > depth ? null : block.tree;
                }
                break;
            default:
                Assert.error("bad decl kind " + block.tree.getTag());
        }
        currentDepth--;
    }
    return null;
}
 
Example #19
Source File: FilteredMemberList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Symbol get(int index) {
    for (Scope.Entry e = scope.elems; e != null; e = e.sibling) {
        if (!unwanted(e.sym) && (index-- == 0))
            return e.sym;
    }
    throw new IndexOutOfBoundsException();
}
 
Example #20
Source File: FilteredMemberList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Iterator<Symbol> iterator() {
    return new Iterator<Symbol>() {

        /** The next entry to examine, or null if none. */
        private Scope.Entry nextEntry = scope.elems;

        private boolean hasNextForSure = false;

        public boolean hasNext() {
            if (hasNextForSure) {
                return true;
            }
            while (nextEntry != null && unwanted(nextEntry.sym)) {
                nextEntry = nextEntry.sibling;
            }
            hasNextForSure = (nextEntry != null);
            return hasNextForSure;
        }

        public Symbol next() {
            if (hasNext()) {
                Symbol result = nextEntry.sym;
                nextEntry = nextEntry.sibling;
                hasNextForSure = false;
                return result;
            } else {
                throw new NoSuchElementException();
            }
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #21
Source File: UStaticIdent.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void getTypesToCompile( JCTree.JCAnnotation precompileAnno, Map<String, Set<String>> typeNames )
{
  Attribute.Compound attribute = precompileAnno.attribute;
  if( attribute == null )
  {
    return;
  }

  String typeManifoldClassName = null;
  String regex = ".*";
  String ext = "*";
  for( com.sun.tools.javac.util.Pair<Symbol.MethodSymbol, Attribute> pair: attribute.values )
  {
    Name argName = pair.fst.getSimpleName();
    switch( argName.toString() )
    {
      case "typeManifold":
        typeManifoldClassName = pair.snd.getValue().toString();
        break;
      case "fileExtension":
        ext = pair.snd.getValue().toString();
        break;
      case "typeNames":
        regex = pair.snd.getValue().toString();
        break;
    }
  }

  addToPrecompile( typeNames, typeManifoldClassName, ext, regex );
}
 
Example #23
Source File: ClassSymbols.java    From manifold with Apache License 2.0 5 votes vote down vote up
private Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> getClassSymbol( Context ctx, Object moduleCtx, String fqn )
  {
    Symbol.ClassSymbol typeElement = IDynamicJdk.instance().getTypeElement( ctx, moduleCtx, fqn );
    if( typeElement == null )
    {
      // For the case where the class is generated from a type manifold esp. from a IExtensionClassProducer
      return getClassSymbolForProducedClass( fqn, new BasicJavacTask[1] );

//## want this instead, but the typeElement is not complete in this case, investigate this
//      if( JavacPlugin.instance() != null )
//      {
//        typeElement = IDynamicJdk.instance().getTypeElement( JavacPlugin.instance().getContext(), moduleCtx, fqn );
//        typeElement.complete();
//      }
    }

    JavacTrees trees = JavacTrees.instance( ctx );
    TreePath path = trees.getPath( typeElement );
    if( path != null )
    {
      return new Pair<>( typeElement, (JCTree.JCCompilationUnit)path.getCompilationUnit() );
    }
    else
    {
      // TreePath is only applicable to a source file;
      // if fqn is not a source file, there is no compilation unit available
      return new Pair<>( typeElement, null );
    }
  }
 
Example #24
Source File: RichDiagnosticFormatter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Preprocess a diagnostic argument. A type/symbol argument is
 * preprocessed by specialized type/symbol preprocessors.
 *
 * @param arg the argument to be translated
 */
protected void preprocessArgument(Object arg) {
    if (arg instanceof Type) {
        preprocessType((Type) arg);
    } else if (arg instanceof Symbol) {
        preprocessSymbol((Symbol) arg);
    } else if (arg instanceof JCDiagnostic) {
        preprocessDiagnostic((JCDiagnostic) arg);
    } else if (arg instanceof Iterable<?>) {
        for (Object o : (Iterable<?>) arg) {
            preprocessArgument(o);
        }
    }
}
 
Example #25
Source File: PackageGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void processTopLevel(Element tlTag) {
    String kind = tlTag.getTagName();

    if (kind.equals("annodecl")) {
        // decls stored separately, does not affect bases
        String declId = tlTag.getAttribute("id");
        if (!declId.startsWith("@"))
            declId = "@" + declId;
        idAnnos.put(declId, processAnnoDecl(tlTag));
        return;
    }

    ListBuffer<JCTree>[] bases = processBases(tlTag, null);

    for (JCTree base : bases[0]) { // [0] - bases namely
        JCPackageDecl pkg = make.PackageDecl(
                                List.<JCAnnotation>nil(),
                                make.QualIdent(
                                    new Symbol.PackageSymbol(
                                        names.fromString(packageName),
                                        null)));
        ListBuffer<JCTree> topLevelParts = new ListBuffer<>();
        topLevelParts.append(pkg);
        topLevelParts.appendList(bases[1]); // [1] imports
        topLevelParts.append(base);

        JCCompilationUnit topLevel = make.TopLevel(topLevelParts.toList());
        documentifier.documentify(topLevel, fx);
        topLevels.add(topLevel);
    }
}
 
Example #26
Source File: Pool.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public boolean equals(Object other) {
    if (!(other instanceof MethodHandle)) return false;
    MethodHandle mr = (MethodHandle) other;
    if (mr.refKind != refKind)  return false;
    Symbol o = mr.refSym;
    return
        o.name == refSym.name &&
        o.owner == refSym.owner &&
        ((MethodHandle)other).uniqueType.equals(uniqueType);
}
 
Example #27
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void getIncrementalCompileDrivers( JCTree.JCAnnotation anno, Set<Object> drivers )
{
  Attribute.Compound attribute = anno.attribute;
  if( attribute == null )
  {
    return;
  }

  String fqnDriver = null;
  Integer driverId = null;
  for( com.sun.tools.javac.util.Pair<Symbol.MethodSymbol, Attribute> pair: attribute.values )
  {
    Name argName = pair.fst.getSimpleName();
    if( argName.toString().equals( "driverInstance" ) )
    {
      driverId = (int)pair.snd.getValue();
    }
    else if( argName.toString().equals( "driverClass" ) )
    {
      fqnDriver = (String)pair.snd.getValue();
    }
  }

  if( driverId != null )
  {
    Object driver = ReflectUtil.method( fqnDriver, "getInstance", int.class ).invokeStatic( driverId );
    drivers.add( driver );
  }
}
 
Example #28
Source File: DPrinter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void printSymbol(String label, Symbol sym, Details details) {
    if (sym == null) {
        printNull(label);
    } else {
        switch (details) {
        case SUMMARY:
            printString(label, toString(sym));
            break;

        case FULL:
            indent();
            out.print(label);
            out.println(": " +
                    info(sym.getClass(),
                        String.format("0x%x--%s", sym.kind, Kinds.kindName(sym)),
                        sym.getKind())
                    + " " + sym.name
                    + " " + hashString(sym));

            indent(+1);
            if (showSrc) {
                JCTree tree = (JCTree) trees.getTree(sym);
                if (tree != null)
                    printSource("src", tree);
            }
            printString("flags", String.format("0x%x--%s",
                    sym.flags_field, Flags.toString(sym.flags_field)));
            printObject("completer", sym.completer, Details.SUMMARY); // what if too long?
            printSymbol("owner", sym.owner, Details.SUMMARY);
            printType("type", sym.type, Details.SUMMARY);
            printType("erasure", sym.erasure_field, Details.SUMMARY);
            sym.accept(symVisitor, null);
            printAnnotations("annotations", sym.getAnnotations(), Details.SUMMARY);
            indent(-1);
        }
    }
}
 
Example #29
Source File: LambdaToMethod.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void captureLocalClassDefs(Symbol csym, final LambdaTranslationContext lambdaContext) {
        JCClassDecl localCDef = localClassDefs.get(csym);
        if (localCDef != null && lambdaContext.freeVarProcessedLocalClasses.add(csym)) {
            BasicFreeVarCollector fvc = lower.new BasicFreeVarCollector() {
                @Override
                void addFreeVars(ClassSymbol c) {
                    captureLocalClassDefs(c, lambdaContext);
                }
                @Override
                void visitSymbol(Symbol sym) {
                    if (sym.kind == VAR &&
                            sym.owner.kind == MTH &&
                            ((VarSymbol)sym).getConstValue() == null) {
                        TranslationContext<?> localContext = context();
                        while (localContext != null) {
                            if (localContext.tree.getTag() == LAMBDA) {
                                JCTree block = capturedDecl(localContext.depth, sym);
                                if (block == null) break;
                                ((LambdaTranslationContext)localContext).addSymbol(sym, CAPTURED_VAR);
                            }
                            localContext = localContext.prev;
                        }
                    }
                }
            };
            fvc.scan(localCDef);
        }
}
 
Example #30
Source File: DoNotCreateSecureRandomDirectly.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
public Description matchNewClass(final NewClassTree tree, final VisitorState state) {
  final Symbol sym = ASTHelpers.getSymbol(tree.getIdentifier());
  if (sym != null && sym.toString().equals("java.security.SecureRandom")) {
    return describeMatch(tree);
  }

  return Description.NO_MATCH;
}