当前位置: 首页>>代码示例>>Java>>正文


Java JCTree.JCExpression方法代码示例

本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCExpression方法的典型用法代码示例。如果您正苦于以下问题:Java JCTree.JCExpression方法的具体用法?Java JCTree.JCExpression怎么用?Java JCTree.JCExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.tree.JCTree的用法示例。


在下文中一共展示了JCTree.JCExpression方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildReturnCheck

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@NotNull
private static Optional<List<JCTree.JCStatement>> buildReturnCheck(@NotNull ReturnToInstrumentInfo info) {
    CompilationUnitProcessingContext context = info.getContext();
    ExpressionTree returnExpression = info.getReturnExpression().getExpression();
    if (!(returnExpression instanceof JCTree.JCExpression)) {
        context.getLogger().reportDetails(String.format(
                "find a 'return' expression of type %s but got %s",
                JCTree.JCExpression.class.getName(), returnExpression.getClass().getName()
        ));
        return Optional.empty();
    }
    JCTree.JCExpression returnJcExpression = (JCTree.JCExpression) returnExpression;

    TreeMaker factory = context.getAstFactory();
    Names symbolsTable = context.getSymbolsTable();
    ExceptionTextGenerator<ReturnToInstrumentInfo> generator =
            context.getExceptionTextGeneratorManager().getGenerator(METHOD_RETURN, context.getPluginSettings());
    String errorMessage = generator.generate(info);

    List<JCTree.JCStatement> result = List.of(
            factory.VarDef(
                    factory.Modifiers(0),
                    symbolsTable.fromString(info.getTmpVariableName()),
                    info.getReturnType(),
                    returnJcExpression
            )
    );
    String exceptionToThrow = info.getContext().getPluginSettings().getExceptionToThrow(METHOD_RETURN);
    result = result.append(InstrumentationUtil.buildVarCheck(factory,
                                                             symbolsTable,
                                                             info.getTmpVariableName(),
                                                             errorMessage,
                                                             exceptionToThrow));
    result = result.append(
            factory.Return(
                    factory.Ident(symbolsTable.fromString(info.getTmpVariableName()))));
    return Optional.of(result);
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:39,代码来源:MethodReturnInstrumentator.java

示例2: ReturnToInstrumentInfo

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public ReturnToInstrumentInfo(@NotNull CompilationUnitProcessingContext context,
                              @Nullable String notNullAnnotation,
                              @Nullable String notNullByDefaultAnnotationDescription,
                              @NotNull ReturnTree returnExpression,
                              @NotNull JCTree.JCExpression returnType,
                              @NotNull String tmpVariableName,
                              @NotNull Tree parent,
                              @Nullable String qualifiedMethodName)
{
    if (notNullAnnotation == null && notNullByDefaultAnnotationDescription == null) {
        throw new IllegalArgumentException(String.format(
                "Detected an invalid attempt to instrument a method return - either NotNull annotation or "
                + "NotNullByDefault annotations are undefined. Method: %s()", qualifiedMethodName));
    }
    this.context = context;
    this.notNullAnnotation = notNullAnnotation;
    this.notNullByDefaultAnnotationDescription = notNullByDefaultAnnotationDescription;
    this.returnExpression = returnExpression;
    this.returnType = returnType;
    this.tmpVariableName = tmpVariableName;
    this.parent = parent;
    this.qualifiedMethodName = qualifiedMethodName;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:24,代码来源:ReturnToInstrumentInfo.java

示例3: mayBeInstrumentReturnType

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private boolean mayBeInstrumentReturnType(@NotNull MethodTree method) {
    Tree returnType = method.getReturnType();
    if (returnType == null
        || METHOD_RETURN_TYPES_TO_SKIP.contains(returnType.toString())
        || (!(returnType instanceof JCTree.JCExpression)))
    {
        return false;
    }

    Annotations annotations = findAnnotation(method.getModifiers());
    if (annotations.notNull.isPresent()
        || (!returnNotNullByDefault.isEmpty() && !annotations.nullable.isPresent()))
    {
        methodNotNullAnnotation = annotations.notNull.orElse(null);
        methodReturnType = (JCTree.JCExpression) returnType;
        return true;
    }
    return false;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:20,代码来源:InstrumentationApplianceFinder.java

示例4: makeStubFromSource

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private SrcClass makeStubFromSource()
{
  List<CompilationUnitTree> trees = new ArrayList<>();
  JavaParser.instance().parseText( _existingSource, trees, null, null, null );
  JCTree.JCClassDecl classDecl = (JCTree.JCClassDecl)trees.get( 0 ).getTypeDecls().get( 0 );
  SrcClass srcExtended = new SrcClass( _fqn, classDecl.getKind() == Tree.Kind.CLASS ? SrcClass.Kind.Class : SrcClass.Kind.Interface )
    .modifiers( classDecl.getModifiers().getFlags() );
  if( classDecl.extending != null )
  {
    srcExtended.superClass( classDecl.extending.toString() );
  }
  for( JCTree.JCExpression iface : classDecl.implementing )
  {
    srcExtended.addInterface( iface.toString() );
  }
  return srcExtended;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:18,代码来源:ExtCodeGen.java

示例5: attributeTree

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private static TypeMirror attributeTree(JavacTaskImpl jti, Tree tree, Scope scope, 
            final List<Diagnostic<? extends JavaFileObject>> errors, @NullAllowed final Diagnostic.Kind filter) {
        Log log = Log.instance(jti.getContext());
        JavaFileObject prev = log.useSource(new DummyJFO());
        Enter enter = Enter.instance(jti.getContext());
        
        Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log) {
            private Diagnostic.Kind f = filter == null ? Diagnostic.Kind.ERROR : filter;
            @Override
            public void report(JCDiagnostic diag) {
                if (diag.getKind().compareTo(f) >= 0) {
                    errors.add(diag);
                }
            }            
        };
//        ArgumentAttr argumentAttr = ArgumentAttr.instance(jti.getContext());
//        ArgumentAttr.LocalCacheContext cacheContext = argumentAttr.withLocalCacheContext();
        try {
//            enter.shadowTypeEnvs(true);
            Attr attr = Attr.instance(jti.getContext());
            Env<AttrContext> env = ((JavacScope) scope).getEnv();
            if (tree instanceof JCTree.JCExpression) {
                return attr.attribExpr((JCTree) tree,env, Type.noType);
            }
            return attr.attribStat((JCTree) tree,env);
        } finally {
//            cacheContext.leave();
            log.useSource(prev);
            log.popDiagnosticHandler(discardHandler);
//            enter.shadowTypeEnvs(false);
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:Utilities.java

示例6: buildExceptionClassExpression

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@NotNull
public static JCTree.JCExpression buildExceptionClassExpression(@NotNull String exceptionClass,
                                                                @NotNull TreeMaker factory,
                                                                @NotNull Names symbolsTable)
{
    String[] parts = exceptionClass.split("\\.");
    JCTree.JCIdent identifier = factory.Ident(symbolsTable.fromString(parts[0]));
    JCTree.JCFieldAccess selector = null;
    for (int i = 1; i < parts.length; i++) {
        selector = factory.Select(selector == null ? identifier : selector, symbolsTable.fromString(parts[i]));
    }
    return selector == null ? identifier : selector;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:14,代码来源:InstrumentationUtil.java

示例7: setLazyConstValue

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public void setLazyConstValue(final Env<AttrContext> env,
                              final Attr attr,
                              final JCTree.JCExpression initializer)
{
    setData(new Callable<Object>() {
        public Object call() {
            return attr.attribLazyConstantValue(env, initializer, type);
        }
    });
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:11,代码来源:Symbol.java

示例8: memberAccess

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private JCTree.JCExpression memberAccess( TreeMaker make, JavacElements node, String... components )
{
  JCTree.JCExpression expr = make.Ident( node.getName( components[0] ) );
  for( int i = 1; i < components.length; i++ )
  {
    expr = make.Select( expr, node.getName( components[i] ) );
  }
  return expr;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:10,代码来源:BootstrapInserter.java

示例9: getReturnType

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
 * @return  target method's return type
 */
@NotNull
public JCTree.JCExpression getReturnType() {
    return returnType;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:8,代码来源:ReturnToInstrumentInfo.java

示例10: collectAll

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
protected List<JCTree> collectAll(JCTree.JCExpression lhs, JCTree.JCExpression rhs) {
    return List.<JCTree>nil()
            .appendList(collectAll(lhs))
            .appendList(collectAll(rhs));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:StringConcat.java

示例11: mandatoryType

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private boolean mandatoryType(JCTree that) {
    return that instanceof JCTree.JCExpression ||
            that.hasTag(VARDEF) ||
            that.hasTag(METHODDEF) ||
            that.hasTag(CLASSDEF);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:CheckAttributedTree.java


注:本文中的com.sun.tools.javac.tree.JCTree.JCExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。