Java 类com.sun.tools.javac.tree.JCTree.JCExpression 实例源码

项目:lombok-ianchiu    文件:HandleLog.java   
private static boolean createField(LoggingFramework framework, JavacNode typeNode, JCFieldAccess loggingType, JCTree source, String logFieldName, boolean useStatic, String loggerTopic) {
    JavacTreeMaker maker = typeNode.getTreeMaker();

    // private static final <loggerType> log = <factoryMethod>(<parameter>);
    JCExpression loggerType = chainDotsString(typeNode, framework.getLoggerTypeName());
    JCExpression factoryMethod = chainDotsString(typeNode, framework.getLoggerFactoryMethodName());

    JCExpression loggerName;
    if (loggerTopic == null || loggerTopic.trim().length() == 0) {
        loggerName = framework.createFactoryParameter(typeNode, loggingType);
    } else {
        loggerName = maker.Literal(loggerTopic);
    }

    JCMethodInvocation factoryMethodCall = maker.Apply(List.<JCExpression>nil(), factoryMethod, List.<JCExpression>of(loggerName));

    JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
            maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (useStatic ? Flags.STATIC : 0)),
            typeNode.toName(logFieldName), loggerType, factoryMethodCall), source, typeNode.getContext());

    injectFieldAndMarkGenerated(typeNode, fieldDecl);
    return true;
}
项目:javaide    文件:JavaCompiler.java   
/**
 * Resolve an identifier.
 *
 * @param name The identifier to resolve
 */
public Symbol resolveIdent(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.<JCAnnotation>nil(), null, List.<JCTree>nil());
        toplevel.packge = syms.unnamedPackage;
        return attr.attribIdent(tree, toplevel);
    } finally {
        log.useSource(prev);
    }
}
项目:openjdk-jdk10    文件:JavaCompiler.java   
/** 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);
    }
}
项目:openjdk-jdk10    文件:Corraller.java   
private JCBlock resolutionExceptionBlock() {
    if (resolutionExceptionBlock == null) {
        JCExpression expClass = null;
        // Split the exception class name at dots
        for (String id : SPIResolutionException.class.getName().split("\\.")) {
            Name nm = names.fromString(id);
            if (expClass == null) {
                expClass = make.Ident(nm);
            } else {
                expClass = make.Select(expClass, nm);
            }
        }
        JCNewClass exp = make.NewClass(null,
                null, expClass, List.of(make.Literal(keyIndex)), null);
        resolutionExceptionBlock = make.Block(0L, List.of(make.Throw(exp)));
    }
    return resolutionExceptionBlock;
}
项目:manifold    文件:ExtensionTransformer.java   
private void replaceExtCall( JCTree.JCMethodInvocation tree, Symbol.MethodSymbol method )
{
  JCExpression methodSelect = tree.getMethodSelect();
  if( methodSelect instanceof JCTree.JCFieldAccess )
  {
    JCTree.JCFieldAccess m = (JCTree.JCFieldAccess)methodSelect;
    boolean isStatic = m.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC );
    TreeMaker make = _tp.getTreeMaker();
    JavacElements javacElems = _tp.getElementUtil();
    JCExpression thisArg = m.selected;
    String extensionFqn = method.getEnclosingElement().asType().tsym.toString();
    m.selected = memberAccess( make, javacElems, extensionFqn );
    BasicJavacTask javacTask = ClassSymbols.instance( _sp.getTypeLoader().getModule() ).getJavacTask();
    Symbol.ClassSymbol extensionClassSym = ClassSymbols.instance( _sp.getTypeLoader().getModule() ).getClassSymbol( javacTask, extensionFqn ).getFirst();
    assignTypes( m.selected, extensionClassSym );
    m.sym = method;
    m.type = method.type;

    if( !isStatic )
    {
      ArrayList<JCExpression> newArgs = new ArrayList<>( tree.args );
      newArgs.add( 0, thisArg );
      tree.args = List.from( newArgs );
    }
  }
}
项目:manifold    文件:ExtensionTransformer.java   
private boolean isStructuralMethod( JCTree.JCMethodInvocation tree )
{
  JCExpression methodSelect = tree.getMethodSelect();
  if( methodSelect instanceof JCTree.JCFieldAccess )
  {
    JCTree.JCFieldAccess m = (JCTree.JCFieldAccess)methodSelect;
    if( m.sym != null && !m.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC ) )
    {
      JCExpression thisArg = m.selected;
      if( TypeUtil.isStructuralInterface( _tp, thisArg.type.tsym ) )
      {
        return true;
      }
    }
  }
  return false;
}
项目:lombok-ianchiu    文件:JavacSingularsRecipes.java   
protected JCExpression cloneParamType(int index, JavacTreeMaker maker, List<JCExpression> typeArgs, JavacNode builderType, JCTree source) {
    if (typeArgs == null || typeArgs.size() <= index) {
        return genJavaLangTypeRef(builderType, "Object");
    } else {
        JCExpression originalType = typeArgs.get(index);
        if (originalType.getKind() == Kind.UNBOUNDED_WILDCARD || originalType.getKind() == Kind.SUPER_WILDCARD) {
            return genJavaLangTypeRef(builderType, "Object");
        } else if (originalType.getKind() == Kind.EXTENDS_WILDCARD) {
            try {
                return cloneType(maker, (JCExpression) ((JCWildcard) originalType).inner, source, builderType.getContext());
            } catch (Exception e) {
                return genJavaLangTypeRef(builderType, "Object");
            }
        } else {
            return cloneType(maker, originalType, source, builderType.getContext());
        }
    }
}
项目:openjdk9    文件:JavaCompiler.java   
/** 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.<JCTree>nil());
        toplevel.modle = msym;
        toplevel.packge = msym.unnamedPackage;
        return attr.attribIdent(tree, toplevel);
    } finally {
        log.useSource(prev);
    }
}
项目:lombok-ianchiu    文件:HandleEqualsAndHashCode.java   
public JCExpression createTypeReference(JavacNode type) {
    java.util.List<String> list = new ArrayList<String>();
    list.add(type.getName());
    JavacNode tNode = type.up();
    while (tNode != null && tNode.getKind() == Kind.TYPE) {
        list.add(tNode.getName());
        tNode = tNode.up();
    }
    Collections.reverse(list);

    JavacTreeMaker maker = type.getTreeMaker();
    JCExpression chain = maker.Ident(type.toName(list.get(0)));

    for (int i = 1; i < list.size(); i++) {
        chain = maker.Select(chain, type.toName(list.get(i)));
    }

    return chain;
}
项目:openjdk9    文件:Corraller.java   
private JCBlock resolutionExceptionBlock() {
    if (resolutionExceptionBlock == null) {
        JCExpression expClass = null;
        // Split the exception class name at dots
        for (String id : SPIResolutionException.class.getName().split("\\.")) {
            Name nm = names.fromString(id);
            if (expClass == null) {
                expClass = make.Ident(nm);
            } else {
                expClass = make.Select(expClass, nm);
            }
        }
        JCNewClass exp = make.NewClass(null,
                null, expClass, List.of(make.Literal(keyIndex)), null);
        resolutionExceptionBlock = make.Block(0L, List.<JCStatement>of(
                make.Throw(exp)));
    }
    return resolutionExceptionBlock;
}
项目:lombok-ianchiu    文件:JavacJavaUtilListSetSingularizer.java   
@Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
    if (useGuavaInstead(builderType)) {
        guavaListSetSingularizer.generateMethods(data, builderType, source, fluent, chain);
        return;
    }

    JavacTreeMaker maker = builderType.getTreeMaker();
    Name thisName = builderType.toName("this");

    JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
    JCStatement returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
    generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);

    returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
    returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
    generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);

    returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
    returnStatement = chain ? maker.Return(maker.Ident(thisName)) : null;
    generateClearMethod(maker, returnType, returnStatement, data, builderType, source);
}
项目:lombok-ianchiu    文件:HandleBuilder.java   
private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JCTree source) {
    JavacTreeMaker maker = type.getTreeMaker();
    ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();

    for (BuilderFieldData bfd : builderFields) {
        if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
            bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, type, source, statements);
        }
    }

    statements.append(maker.Exec(maker.Assign(maker.Select(maker.Ident(type.toName("this")), type.toName("$lombokUnclean")), maker.Literal(CTC_BOOLEAN, false))));
    JCBlock body = maker.Block(0, statements.toList());
    return maker.MethodDef(maker.Modifiers(Flags.PUBLIC), type.toName("$lombokClean"), maker.Type(Javac.createVoidType(maker, CTC_VOID)), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null);
    /*
     *      if (shouldReturnThis) {
        methodType = cloneSelfType(field);
    }

    if (methodType == null) {
        //WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6.
        methodType = treeMaker.Type(Javac.createVoidType(treeMaker, CTC_VOID));
        shouldReturnThis = false;
    }

     */
}
项目:lombok-ianchiu    文件:JavacJavaUtilMapSingularizer.java   
@Override public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
    if (useGuavaInstead(builderType)) {
        guavaMapSingularizer.generateMethods(data, builderType, source, fluent, chain);
        return;
    }

    JavacTreeMaker maker = builderType.getTreeMaker();

    JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
    JCStatement returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
    generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);

    returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
    returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
    generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);

    returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(maker, CTC_VOID));
    returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
    generateClearMethod(maker, returnType, returnStatement, data, builderType, source);
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
private boolean suppress(JCTree tree) {
    if (tree instanceof JCBlock) {
        JCBlock block = (JCBlock) tree;
        return (Position.NOPOS == block.pos) && block.stats.isEmpty();
    }

    if (tree instanceof JCExpressionStatement) {
        JCExpression expr = ((JCExpressionStatement)tree).expr;
        if (expr instanceof JCMethodInvocation) {
            JCMethodInvocation inv = (JCMethodInvocation) expr;
            if (!inv.typeargs.isEmpty() || !inv.args.isEmpty()) return false;
            if (!(inv.meth instanceof JCIdent)) return false;
            return ((JCIdent) inv.meth).name.toString().equals("super");
        }
    }

    return false;
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
@Override public void visitTree(JCTree tree) {
    String simpleName = tree.getClass().getSimpleName();
    if ("JCTypeUnion".equals(simpleName)) {
        List<JCExpression> types = readObject(tree, "alternatives", List.<JCExpression>nil());
        print(types, " | ");
        return;
    } else if ("JCTypeIntersection".equals(simpleName)) {
        print(readObject(tree, "bounds", List.<JCExpression>nil()), " & ");
        return;
    } else if ("JCMemberReference".equals(simpleName)) {
        printMemberReference0(tree);
        return;
    } else if ("JCLambda".equals(simpleName)) {
        printLambda0(tree);
        return;
    } else if ("JCAnnotatedType".equals(simpleName)) {
        printAnnotatedType0(tree);
        return;
    }

    throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
}
项目:lombok-ianchiu    文件:HandleBuilder.java   
private static void unpack(StringBuilder sb, JCExpression expr) {
    if (expr instanceof JCIdent) {
        sb.append(((JCIdent) expr).name.toString());
        return;
    }

    if (expr instanceof JCFieldAccess) {
        JCFieldAccess jcfa = (JCFieldAccess) expr;
        unpack(sb, jcfa.selected);
        sb.append(".").append(jcfa.name.toString());
        return;
    }

    if (expr instanceof JCTypeApply) {
        sb.setLength(0);
        sb.append("ERR:");
        sb.append("@Builder(toBuilder=true) is not supported if returning a type with generics applied to an intermediate.");
        sb.append("__ERR__");
        return;
    }

    sb.setLength(0);
    sb.append("ERR:");
    sb.append("Expected a type of some sort, not a " + expr.getClass().getName());
    sb.append("__ERR__");
}
项目:lombok-ianchiu    文件:HandleEqualsAndHashCode.java   
public JCMethodDecl createCanEqual(JavacNode typeNode, JCTree source, List<JCAnnotation> onParam) {
    /* protected boolean canEqual(final java.lang.Object other) {
     *     return other instanceof Outer.Inner.MyType;
     * }
     */
    JavacTreeMaker maker = typeNode.getTreeMaker();

    JCModifiers mods = maker.Modifiers(Flags.PROTECTED, List.<JCAnnotation>nil());
    JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
    Name canEqualName = typeNode.toName("canEqual");
    JCExpression objectType = genJavaLangTypeRef(typeNode, "Object");
    Name otherName = typeNode.toName("other");
    long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
    List<JCVariableDecl> params = List.of(maker.VarDef(maker.Modifiers(flags, onParam), otherName, objectType, null));

    JCBlock body = maker.Block(0, List.<JCStatement>of(
            maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode)))));

    return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source, typeNode.getContext());
}
项目:lombok-ianchiu    文件:JavacJavaUtilListSingularizer.java   
private List<JCStatement> createListCopy(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) {
    List<JCExpression> jceBlank = List.nil();
    Name thisName = builderType.toName("this");

    JCExpression argToUnmodifiable; {
         // new java.util.ArrayList<Generics>(this.pluralName);
        List<JCExpression> constructorArgs = List.nil();
        JCExpression thisDotPluralName = maker.Select(maker.Ident(thisName), data.getPluralName());
        constructorArgs = List.<JCExpression>of(thisDotPluralName);
        JCExpression targetTypeExpr = chainDots(builderType, "java", "util", "ArrayList");
        targetTypeExpr = addTypeArgs(1, false, builderType, targetTypeExpr, data.getTypeArgs(), source);
        argToUnmodifiable = maker.NewClass(null, jceBlank, targetTypeExpr, constructorArgs, null);
    }

    JCStatement unmodifiableStat; {
        // pluralname = Collections.unmodifiableInterfaceType(-newlist-);
        JCExpression invoke = maker.Apply(jceBlank, chainDots(builderType, "java", "util", "Collections", "unmodifiableList"), List.of(argToUnmodifiable));
        unmodifiableStat = maker.Exec(maker.Assign(maker.Ident(data.getPluralName()), invoke));
    }

    return List.of(unmodifiableStat);
}
项目:lombok-ianchiu    文件:JavacHandlerUtil.java   
public static boolean isConstructorCall(final JCStatement statement) {
    if (!(statement instanceof JCExpressionStatement)) return false;
    JCExpression expr = ((JCExpressionStatement) statement).expr;
    if (!(expr instanceof JCMethodInvocation)) return false;
    JCExpression invocation = ((JCMethodInvocation) expr).meth;
    String name;
    if (invocation instanceof JCFieldAccess) {
        name = ((JCFieldAccess) invocation).name.toString();
    } else if (invocation instanceof JCIdent) {
        name = ((JCIdent) invocation).name.toString();
    } else {
        name = "";
    }

    return "super".equals(name) || "this".equals(name);
}
项目:incubator-netbeans    文件:TreeUtilities.java   
private static TypeMirror attributeTree(JavacTaskImpl jti, Tree tree, Scope scope, final List<Diagnostic<? extends JavaFileObject>> errors) {
        Log log = Log.instance(jti.getContext());
        JavaFileObject prev = log.useSource(new DummyJFO());
        Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) {
            @Override
            public void report(JCDiagnostic diag) {
                errors.add(diag);
            }            
        };
        NBResolve resolve = NBResolve.instance(jti.getContext());
        resolve.disableAccessibilityChecks();
//        Enter enter = Enter.instance(jti.getContext());
//        enter.shadowTypeEnvs(true);
//        ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext());
//        ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext();
        try {
            Attr attr = Attr.instance(jti.getContext());
            Env<AttrContext> env = getEnv(scope);
            if (tree instanceof JCExpression)
                return attr.attribExpr((JCTree) tree,env, Type.noType);
            return attr.attribStat((JCTree) tree,env);
        } finally {
//            cacheContext.leave();
            log.useSource(prev);
            log.popDiagnosticHandler(discardHandler);
            resolve.restoreAccessbilityChecks();
//            enter.shadowTypeEnvs(false);
        }
    }
项目:incubator-netbeans    文件:TreeUtilities.java   
private static Scope attributeTreeTo(JavacTaskImpl jti, Tree tree, Scope scope, Tree to, final List<Diagnostic<? extends JavaFileObject>> errors) {
        Log log = Log.instance(jti.getContext());
        JavaFileObject prev = log.useSource(new DummyJFO());
        Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) {
            @Override
            public void report(JCDiagnostic diag) {
                errors.add(diag);
            }            
        };
        NBResolve resolve = NBResolve.instance(jti.getContext());
        resolve.disableAccessibilityChecks();
//        Enter enter = Enter.instance(jti.getContext());
//        enter.shadowTypeEnvs(true);
//        ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext());
//        ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext();
        try {
            Attr attr = Attr.instance(jti.getContext());
            Env<AttrContext> env = getEnv(scope);
            Env<AttrContext> result = tree instanceof JCExpression ?
                attr.attribExprToTree((JCExpression) tree, env, (JCTree) to) :
                attr.attribStatToTree((JCTree) tree, env, (JCTree) to);
            try {
                Constructor<JavacScope> c = JavacScope.class.getDeclaredConstructor(Env.class);
                c.setAccessible(true);
                return c.newInstance(result);
            } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                throw new IllegalStateException(ex);
            }
        } finally {
//            cacheContext.leave();
            log.useSource(prev);
            log.popDiagnosticHandler(discardHandler);
            resolve.restoreAccessbilityChecks();
//            enter.shadowTypeEnvs(false);
        }
    }
项目:incubator-netbeans    文件:Utilities.java   
private static JCExpression parseExpression(Context context, CharSequence expr, boolean onlyFullInput, SourcePositions[] pos, final List<Diagnostic<? extends JavaFileObject>> errors) {
    if (expr == null || (pos != null && pos.length != 1))
        throw new IllegalArgumentException();
    JavaCompiler compiler = JavaCompiler.instance(context);
    JavaFileObject prev = compiler.log.useSource(new DummyJFO());
    Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(compiler.log) {
        @Override
        public void report(JCDiagnostic diag) {
            errors.add(diag);
        }            
    };
    try {
        CharBuffer buf = CharBuffer.wrap((expr+"\u0000").toCharArray(), 0, expr.length());
        ParserFactory factory = ParserFactory.instance(context);
        ScannerFactory scannerFactory = ScannerFactory.instance(context);
        Names names = Names.instance(context);
        Scanner scanner = scannerFactory.newScanner(buf, false);
        Parser parser = new JackpotJavacParser(context, (NBParserFactory) factory, scanner, false, false, CancelService.instance(context), names);
        if (parser instanceof JavacParser) {
            if (pos != null)
                pos[0] = new ParserSourcePositions((JavacParser)parser);
            JCExpression result = parser.parseExpression();

            if (!onlyFullInput || scanner.token().kind == TokenKind.EOF) {
                return result;
            }
        }
        return null;
    } finally {
        compiler.log.useSource(prev);
        compiler.log.popDiagnosticHandler(discardHandler);
    }
}
项目:incubator-netbeans    文件:Utilities.java   
private static TypeMirror attributeTree(JavacTaskImpl jti, Tree tree, Scope scope, final List<Diagnostic<? extends JavaFileObject>> errors) {
        Log log = Log.instance(jti.getContext());
        JavaFileObject prev = log.useSource(new DummyJFO());
        Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) {
            @Override
            public void report(JCDiagnostic diag) {
                errors.add(diag);
            }            
        };
        NBResolve resolve = NBResolve.instance(jti.getContext());
        resolve.disableAccessibilityChecks();
//        Enter enter = Enter.instance(jti.getContext());
//        enter.shadowTypeEnvs(true);
//        ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext());
//        ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext();
        try {
            Attr attr = Attr.instance(jti.getContext());
            Env<AttrContext> env = ((JavacScope) scope).getEnv();
            if (tree instanceof JCExpression)
                return attr.attribExpr((JCTree) tree,env, Type.noType);
            return attr.attribStat((JCTree) tree,env);
        } finally {
//            cacheContext.leave();
            log.useSource(prev);
            log.popDiagnosticHandler(discardHandler);
            resolve.restoreAccessbilityChecks();
//            enter.shadowTypeEnvs(false);
        }
    }
项目:incubator-netbeans    文件:Utilities.java   
@Override
protected JCExpression checkExprStat(JCExpression t) {
    if (t.getTag() == JCTree.Tag.IDENT) {
        if (((IdentifierTree) t).getName().toString().startsWith("$")) {
            return t;
        }
    }
    return super.checkExprStat(t);
}
项目:incubator-netbeans    文件:NBTreeMaker.java   
@Override
public IndexedClassDecl ClassDef(JCModifiers mods, Name name, List<JCTypeParameter> typarams, JCExpression extending, List<JCExpression> implementing, List<JCTree> defs) {
    IndexedClassDecl result = new IndexedClassDecl(mods, name, typarams, extending, implementing, defs, null);

    result.pos = pos;

    return result;
}
项目:incubator-netbeans    文件:NBTreeMaker.java   
protected IndexedClassDecl(JCModifiers mods,
                           Name name,
                           List<JCTypeParameter> typarams,
                           JCExpression extending,
                           List<JCExpression> implementing,
                           List<JCTree> defs,
                           ClassSymbol sym) {
    super(mods, name, typarams, extending, implementing, defs, sym);
    this.index = -1;
}
项目:incubator-netbeans    文件:NBParserFactory.java   
@Override
protected JCTree methodDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, List<JCTypeParameter> typarams, boolean isInterface, boolean isVoid, Comment dc) {
    if (cancelService != null) {
        cancelService.abortIfCanceled();
    }
    return super.methodDeclaratorRest(pos, mods, type, name, typarams, isInterface, isVoid, dc);
}
项目:incubator-netbeans    文件:NBJavadocMemberEnter.java   
@Override
public void visitVarDef(JCVariableDecl tree) {
    cancelService.abortIfCanceled();
    JCExpression init = tree.init;
    try {
        super.visitVarDef(tree);
    } finally {
        //reinstall init:
        tree.init = init;
    }
}
项目:openjdk-jdk10    文件:AssertCheckAnalyzer.java   
@Override
public void visitApply(JCMethodInvocation tree) {
    Symbol m = TreeInfo.symbolFor(tree);
    AssertOverloadKind ak = assertOverloadKind(m);
    if (ak != AssertOverloadKind.NONE &&
        !m.name.contentEquals("error")) {
        JCExpression lastParam = tree.args.last();
        if (isSimpleStringArg(lastParam) != ak.simpleArgExpected()) {
            messages.error(lastParam, ak.errKey);
        }
    }

    super.visitApply(tree);
}
项目:openjdk-jdk10    文件:AssertCheckAnalyzer.java   
boolean isSimpleStringArg(JCExpression e) {
    switch (e.getTag()) {
        case LAMBDA:
            JCLambda lambda = (JCLambda)e;
            return (lambda.getBodyKind() == BodyKind.EXPRESSION) &&
                    isSimpleStringArg((JCExpression)lambda.body);
        default:
            Symbol argSym = TreeInfo.symbolFor(e);
            return (e.type.constValue() != null ||
                    (argSym != null && argSym.kind == Kinds.Kind.VAR));
    }
}
项目:openjdk-jdk10    文件:LegacyLogMethodAnalyzer.java   
void checkLegacyLogMethod(JCMethodInvocation tree) {
    Symbol method = TreeInfo.symbolFor(tree);
    if (method == null ||
        method.kind != Kinds.Kind.MTH ||
        !typeToCheck(method.owner.type) ||
        !LEGACY_METHOD_NAMES.contains(method.name.toString()) ||
        !((MethodSymbol) method).isVarArgs() ||
        method.type.getParameterTypes().size() < 2) {
        return ;
    }
    JCExpression key = tree.args.get(method.type.getParameterTypes().size() - 2);
    if (key.hasTag(Tag.LITERAL)) {
        messages.error(tree, "crules.use.of.legacy.log.method", tree);
    }
}
项目:openjdk-jdk10    文件:JavacTrees.java   
private Env<AttrContext> attribExprToTree(JCExpression expr, Env<AttrContext>env, JCTree tree) {
    JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
    try {
        return attr.attribExprToTree(expr, env, tree);
    } finally {
        log.useSource(prev);
    }
}
项目:openjdk-jdk10    文件:ArgumentAttr.java   
/**
 * Set the results of method attribution.
 */
void setResult(JCExpression tree, Type type) {
    result = type;
    if (env.info.isSpeculative) {
        //if we are in a speculative branch we can save the type in the tree itself
        //as there's no risk of polluting the original tree.
        tree.type = result;
    }
}
项目:openjdk-jdk10    文件:ArgumentAttr.java   
/**
 * Process a method argument; this method takes care of performing a speculative pass over the
 * argument tree and calling a well-defined entry point to build the argument type associated
 * with such tree.
 */
@SuppressWarnings("unchecked")
<T extends JCExpression, Z extends ArgumentType<T>> void processArg(T that, Function<T, Z> argumentTypeFactory) {
    UniquePos pos = new UniquePos(that);
    processArg(that, () -> {
        T speculativeTree = (T)deferredAttr.attribSpeculative(that, env, attr.new MethodAttrInfo() {
            @Override
            protected boolean needsArgumentAttr(JCTree tree) {
                return !new UniquePos(tree).equals(pos);
            }
        });
        return argumentTypeFactory.apply(speculativeTree);
    });
}
项目:openjdk-jdk10    文件:ArgumentAttr.java   
/**
 * Process a method argument; this method allows the caller to specify a custom speculative attribution
 * logic (this is used e.g. for lambdas).
 */
@SuppressWarnings("unchecked")
<T extends JCExpression, Z extends ArgumentType<T>> void processArg(T that, Supplier<Z> argumentTypeFactory) {
    UniquePos pos = new UniquePos(that);
    Z cached = (Z)argumentTypeCache.get(pos);
    if (cached != null) {
        //dup existing speculative type
        setResult(that, cached.dup(that, env));
    } else {
        Z res = argumentTypeFactory.get();
        argumentTypeCache.put(pos, res);
        setResult(that, res);
    }
}
项目:openjdk-jdk10    文件:Modules.java   
private void checkDuplicateExportsToModule(JCExpression name, ModuleSymbol msym,
        ExportsDirective d) {
    if (d.modules != null) {
        for (ModuleSymbol other : d.modules) {
            if (msym == other) {
                reportExportsConflictToModule(name, msym);
            }
        }
    }
}
项目:openjdk-jdk10    文件:Modules.java   
private void checkDuplicateOpensToModule(JCExpression name, ModuleSymbol msym,
        OpensDirective d) {
    if (d.modules != null) {
        for (ModuleSymbol other : d.modules) {
            if (msym == other) {
                reportOpensConflictToModule(name, msym);
            }
        }
    }
}
项目:manifold    文件:ExtensionTransformer.java   
private boolean isConstructProxyCall( JCExpression expression )
{
  if( expression instanceof JCTree.JCMethodInvocation )
  {
    // don't erase cast if we generated it here e.g.., for structural call cast on constructProxy

    JCExpression meth = ((JCTree.JCMethodInvocation)expression).meth;
    return meth instanceof JCTree.JCFieldAccess && ((JCTree.JCFieldAccess)meth).getIdentifier().toString().equals( "constructProxy" );
  }
  return expression instanceof JCTypeCast && isConstructProxyCall( ((JCTypeCast)expression).getExpression() );
}
项目:manifold    文件:ExtensionTransformer.java   
private void verifyExtensionInterfaces( JCTree.JCClassDecl tree )
{
  if( !hasAnnotation( tree.getModifiers().getAnnotations(), Extension.class ) )
  {
    return;
  }

  outer:
  for( JCExpression iface: tree.getImplementsClause() )
  {
    final Symbol.TypeSymbol ifaceSym = iface.type.tsym;
    if( ifaceSym == _tp.getSymtab().objectType.tsym )
    {
      continue;
    }

    for( Attribute.Compound anno: ifaceSym.getAnnotationMirrors() )
    {
      if( anno.type.toString().equals( Structural.class.getName() ) )
      {
        continue outer;
      }
    }
    // extension interfaces must be structural
    _tp.report( iface, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_ONLY_STRUCTURAL_INTERFACE_ALLOWED_HERE.get( iface.toString() ) );
  }
}
项目:manifold    文件:ExtensionTransformer.java   
private JCExpression replaceCastExpression( JCExpression expression, Type type )
{
  TreeMaker make = _tp.getTreeMaker();
  Symtab symbols = _tp.getSymtab();
  Names names = Names.instance( _tp.getContext() );
  JavacElements elementUtils = JavacElements.instance( _tp.getContext() );
  Symbol.ClassSymbol reflectMethodClassSym = elementUtils.getTypeElement( getClass().getName() );

  Symbol.MethodSymbol makeInterfaceProxyMethod = resolveMethod( expression.pos(), names.fromString( "assignStructuralIdentity" ), reflectMethodClassSym.type,
                                                                List.from( new Type[]{symbols.objectType, symbols.classType} ) );

  JavacElements javacElems = _tp.getElementUtil();
  ArrayList<JCExpression> newArgs = new ArrayList<>();
  newArgs.add( expression );
  JCTree.JCFieldAccess ifaceClassExpr = (JCTree.JCFieldAccess)memberAccess( make, javacElems, type.tsym.getQualifiedName().toString() + ".class" );
  ifaceClassExpr.type = symbols.classType;
  ifaceClassExpr.sym = symbols.classType.tsym;
  assignTypes( ifaceClassExpr.selected, type.tsym );
  newArgs.add( ifaceClassExpr );

  JCTree.JCMethodInvocation makeProxyCall = make.Apply( List.nil(), memberAccess( make, javacElems, ExtensionTransformer.class.getName() + ".assignStructuralIdentity" ), List.from( newArgs ) );
  makeProxyCall.type = symbols.objectType;
  JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)makeProxyCall.getMethodSelect();
  newMethodSelect.sym = makeInterfaceProxyMethod;
  newMethodSelect.type = makeInterfaceProxyMethod.type;
  assignTypes( newMethodSelect.selected, reflectMethodClassSym );

  JCTypeCast castCall = make.TypeCast( symbols.objectType, makeProxyCall );
  castCall.type = symbols.objectType;

  return castCall;

}