本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCExpression类的典型用法代码示例。如果您正苦于以下问题:Java JCExpression类的具体用法?Java JCExpression怎么用?Java JCExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JCExpression类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createField
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
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;
}
示例2: resolveIdent
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
/**
* 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);
}
}
示例3: resolveIdent
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
/** 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);
}
}
示例4: resolutionExceptionBlock
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
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;
}
示例5: replaceExtCall
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
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 );
}
}
}
示例6: isStructuralMethod
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
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;
}
示例7: cloneParamType
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
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());
}
}
}
示例8: resolveIdent
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
/** 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);
}
}
示例9: createTypeReference
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
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;
}
示例10: resolutionExceptionBlock
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
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;
}
示例11: generateMethods
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
@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);
}
示例12: generateCleanMethod
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
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;
}
*/
}
示例13: generateMethods
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
@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);
}
示例14: suppress
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
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;
}
示例15: visitTree
import com.sun.tools.javac.tree.JCTree.JCExpression; //导入依赖的package包/类
@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);
}