本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
});
}
示例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;
}
示例9: getReturnType
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
* @return target method's return type
*/
@NotNull
public JCTree.JCExpression getReturnType() {
return returnType;
}
示例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));
}
示例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);
}