當前位置: 首頁>>代碼示例>>Java>>正文


Java TreeMaker.Select方法代碼示例

本文整理匯總了Java中com.sun.tools.javac.tree.TreeMaker.Select方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeMaker.Select方法的具體用法?Java TreeMaker.Select怎麽用?Java TreeMaker.Select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.tools.javac.tree.TreeMaker的用法示例。


在下文中一共展示了TreeMaker.Select方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readField

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
public static JCTree.JCExpression readField(JavacNode fieldNode, JCTree.JCExpression receiver) {
    TreeMaker maker = fieldNode.getTreeMaker();

    JCTree.JCVariableDecl fieldDecl = (JCTree.JCVariableDecl) fieldNode.get();

    if (receiver == null) {
        if ((fieldDecl.mods.flags & Flags.STATIC) == 0) {
            receiver = maker.Ident(fieldNode.toName("this"));
        } else {
            JavacNode containerNode = fieldNode.up();
            if (containerNode != null && containerNode.get() instanceof JCTree.JCClassDecl) {
                JCTree.JCClassDecl container = (JCTree.JCClassDecl) fieldNode.up().get();
                receiver = maker.Ident(container.name);
            }
        }
    }

    return receiver == null ? maker.Ident(fieldDecl.name) : maker.Select(receiver, fieldDecl.name);
}
 
開發者ID:aalmiray,項目名稱:griffon2,代碼行數:20,代碼來源:HandlerUtils.java

示例2: createTypeReference

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private 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);
	
	TreeMaker 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;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:20,代碼來源:HandleEqualsAndHashCode.java

示例3: buildExceptionClassExpression

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的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

示例4: memberAccess

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCExpression memberAccess( TreeMaker make, JavacElements node, String... components )
{
  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,代碼來源:ExtensionTransformer.java

示例5: memberAccess

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的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

示例6: createReadFromParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createReadFromParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, String varName, boolean isArray) {

    // parcel.createTypedArrayList(Type.CREATOR)

    final TreeMaker treeMaker = astHelper.getTreeMaker();

    // here we have List<OUR_TYPE>
    final Element fieldElement = astHelper.findFieldByName(rootElement, varName);
    if (fieldElement == null) {
        return List.nil();
    }

    final JCTree.JCExpression typeOfElement = astHelper.getListTypeParameter((DeclaredType) fieldElement.asType());

    final JCTree.JCExpression creator = treeMaker.Select(typeOfElement, astHelper.getName("CREATOR"));

    final JCTree.JCStatement statement = treeMaker.Exec(
            treeMaker.Assign(
                    treeMaker.Ident(astHelper.getName(varName)),
                    treeMaker.Apply(
                            List.<JCTree.JCExpression>nil(),
                            treeMaker.Select(parcel, astHelper.getName("createTypedArrayList")),
                            List.of(creator)
                    )
            )
    );

    return List.of(statement);
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:31,代碼來源:StatementCreatorTypedList.java

示例7: createJavaLangObject

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
public static JCExpression createJavaLangObject(JavacAST ast) {
	TreeMaker maker = ast.getTreeMaker();
	JCExpression out = maker.Ident(ast.toName("java"));
	out = maker.Select(out, ast.toName("lang"));
	out = maker.Select(out, ast.toName("Object"));
	return out;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:8,代碼來源:JavacResolution.java

示例8: createFieldAccessor

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
static JCExpression createFieldAccessor(TreeMaker maker, JavacNode field, FieldAccess fieldAccess, JCExpression receiver) {
	boolean lookForGetter = lookForGetter(field, fieldAccess);
	
	GetterMethod getter = lookForGetter ? findGetter(field) : null;
	JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
	
	if (getter == null) {
		if (receiver == null) {
			if ((fieldDecl.mods.flags & Flags.STATIC) == 0) {
				receiver = maker.Ident(field.toName("this"));
			} else {
				JavacNode containerNode = field.up();
				if (containerNode != null && containerNode.get() instanceof JCClassDecl) {
					JCClassDecl container = (JCClassDecl) field.up().get();
					receiver = maker.Ident(container.name);
				}
			}
		}
		
		return receiver == null ? maker.Ident(fieldDecl.name) : maker.Select(receiver, fieldDecl.name);
	}
	
	if (receiver == null) receiver = maker.Ident(field.toName("this"));
	JCMethodInvocation call = maker.Apply(List.<JCExpression>nil(),
			maker.Select(receiver, getter.name), List.<JCExpression>nil());
	return call;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:28,代碼來源:JavacHandlerUtil.java

示例9: selfType

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private static JCFieldAccess selfType(JavacNode typeNode) {
	TreeMaker maker = typeNode.getTreeMaker();
	Name name = ((JCClassDecl) typeNode.get()).name;
	return maker.Select(maker.Ident(name), typeNode.toName("class"));
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:6,代碼來源:HandleLog.java

示例10: createFactoryParameter

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override public JCExpression createFactoryParameter(JavacNode typeNode, JCFieldAccess loggingType) {
	TreeMaker maker = typeNode.getTreeMaker();
	JCExpression method = maker.Select(loggingType, typeNode.toName("getName"));
	return maker.Apply(List.<JCExpression>nil(), method, List.<JCExpression>nil());
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:6,代碼來源:HandleLog.java

示例11: cloneType0

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private static JCExpression cloneType0(TreeMaker maker, JCTree in) {
	if (in == null) return null;
	
	if (in instanceof JCPrimitiveTypeTree) return (JCExpression) in;
	
	if (in instanceof JCIdent) {
		return maker.Ident(((JCIdent) in).name);
	}
	
	if (in instanceof JCFieldAccess) {
		JCFieldAccess fa = (JCFieldAccess) in;
		return maker.Select(cloneType0(maker, fa.selected), fa.name);
	}
	
	if (in instanceof JCArrayTypeTree) {
		JCArrayTypeTree att = (JCArrayTypeTree) in;
		return maker.TypeArray(cloneType0(maker, att.elemtype));
	}
	
	if (in instanceof JCTypeApply) {
		JCTypeApply ta = (JCTypeApply) in;
		ListBuffer<JCExpression> lb = ListBuffer.lb();
		for (JCExpression typeArg : ta.arguments) {
			lb.append(cloneType0(maker, typeArg));
		}
		return maker.TypeApply(cloneType0(maker, ta.clazz), lb.toList());
	}
	
	if (in instanceof JCWildcard) {
		JCWildcard w = (JCWildcard) in;
		JCExpression newInner = cloneType0(maker, w.inner);
		TypeBoundKind newKind;
		switch (w.getKind()) {
		case SUPER_WILDCARD:
			newKind = maker.TypeBoundKind(BoundKind.SUPER);
			break;
		case EXTENDS_WILDCARD:
			newKind = maker.TypeBoundKind(BoundKind.EXTENDS);
			break;
		default:
		case UNBOUNDED_WILDCARD:
			newKind = maker.TypeBoundKind(BoundKind.UNBOUND);
			break;
		}
		return maker.Wildcard(newKind, newInner);
	}
	
	// This is somewhat unsafe, but it's better than outright throwing an exception here. Returning null will just cause an exception down the pipeline.
	return (JCExpression) in;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:51,代碼來源:JavacHandlerUtil.java

示例12: get

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
public JCExpression get(final JavacNode node, final Name name) {
	final TreeMaker maker = node.getTreeMaker();
	return maker.Select(maker.Ident(node.toName("this")), name);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:5,代碼來源:HandleDelegate.java

示例13: handle

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override public void handle(AnnotationValues<Cleanup> annotation, JCAnnotation ast, JavacNode annotationNode) {
	if (inNetbeansEditor(annotationNode)) return;
	
	deleteAnnotationIfNeccessary(annotationNode, Cleanup.class);
	String cleanupName = annotation.getInstance().value();
	if (cleanupName.length() == 0) {
		annotationNode.addError("cleanupName cannot be the empty string.");
		return;
	}
	
	if (annotationNode.up().getKind() != Kind.LOCAL) {
		annotationNode.addError("@Cleanup is legal only on local variable declarations.");
		return;
	}
	
	JCVariableDecl decl = (JCVariableDecl)annotationNode.up().get();
	
	if (decl.init == null) {
		annotationNode.addError("@Cleanup variable declarations need to be initialized.");
		return;
	}
	
	JavacNode ancestor = annotationNode.up().directUp();
	JCTree blockNode = ancestor.get();
	
	final List<JCStatement> statements;
	if (blockNode instanceof JCBlock) {
		statements = ((JCBlock)blockNode).stats;
	} else if (blockNode instanceof JCCase) {
		statements = ((JCCase)blockNode).stats;
	} else if (blockNode instanceof JCMethodDecl) {
		statements = ((JCMethodDecl)blockNode).body.stats;
	} else {
		annotationNode.addError("@Cleanup is legal only on a local variable declaration inside a block.");
		return;
	}
	
	boolean seenDeclaration = false;
	ListBuffer<JCStatement> newStatements = ListBuffer.lb();
	ListBuffer<JCStatement> tryBlock = ListBuffer.lb();
	for (JCStatement statement : statements) {
		if (!seenDeclaration) {
			if (statement == decl) seenDeclaration = true;
			newStatements.append(statement);
		} else {
			tryBlock.append(statement);
		}
	}
	
	if (!seenDeclaration) {
		annotationNode.addError("LOMBOK BUG: Can't find this local variable declaration inside its parent.");
		return;
	}
	doAssignmentCheck(annotationNode, tryBlock.toList(), decl.name);
	
	TreeMaker maker = annotationNode.getTreeMaker();
	JCFieldAccess cleanupMethod = maker.Select(maker.Ident(decl.name), annotationNode.toName(cleanupName));
	List<JCStatement> cleanupCall = List.<JCStatement>of(maker.Exec(
			maker.Apply(List.<JCExpression>nil(), cleanupMethod, List.<JCExpression>nil())));
	
	JCMethodInvocation preventNullAnalysis = preventNullAnalysis(maker, annotationNode, maker.Ident(decl.name));
	JCBinary isNull = maker.Binary(CTC_NOT_EQUAL, preventNullAnalysis, maker.Literal(CTC_BOT, null));
	
	JCIf ifNotNullCleanup = maker.If(isNull, maker.Block(0, cleanupCall), null);
	
	JCBlock finalizer = recursiveSetGeneratedBy(maker.Block(0, List.<JCStatement>of(ifNotNullCleanup)), ast);
	
	newStatements.append(setGeneratedBy(maker.Try(setGeneratedBy(maker.Block(0, tryBlock.toList()), ast), List.<JCCatch>nil(), finalizer), ast));
	
	if (blockNode instanceof JCBlock) {
		((JCBlock)blockNode).stats = newStatements.toList();
	} else if (blockNode instanceof JCCase) {
		((JCCase)blockNode).stats = newStatements.toList();
	} else if (blockNode instanceof JCMethodDecl) {
		((JCMethodDecl)blockNode).body.stats = newStatements.toList();
	} else throw new AssertionError("Should not get here");
	
	ancestor.rebuild();
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:80,代碼來源:HandleCleanup.java

示例14: handle

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override public void handle(AnnotationValues<Synchronized> annotation, JCAnnotation ast, JavacNode annotationNode) {
	if (inNetbeansEditor(annotationNode)) return;
	
	deleteAnnotationIfNeccessary(annotationNode, Synchronized.class);
	JavacNode methodNode = annotationNode.up();
	
	if (methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof JCMethodDecl)) {
		annotationNode.addError("@Synchronized is legal only on methods.");
		
		return;
	}
	
	JCMethodDecl method = (JCMethodDecl)methodNode.get();
	
	if ((method.mods.flags & Flags.ABSTRACT) != 0) {
		annotationNode.addError("@Synchronized is legal only on concrete methods.");
		
		return;
	}
	boolean isStatic = (method.mods.flags & Flags.STATIC) != 0;
	String lockName = annotation.getInstance().value();
	boolean autoMake = false;
	if (lockName.length() == 0) {
		autoMake = true;
		lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
	}
	
	TreeMaker maker = methodNode.getTreeMaker().at(ast.pos);
	
	if (fieldExists(lockName, methodNode) == MemberExistsResult.NOT_EXISTS) {
		if (!autoMake) {
			annotationNode.addError("The field " + lockName + " does not exist.");
			return;
		}
		JCExpression objectType = chainDots(methodNode, ast.pos, "java", "lang", "Object");
		//We use 'new Object[0];' because unlike 'new Object();', empty arrays *ARE* serializable!
		JCNewArray newObjectArray = maker.NewArray(chainDots(methodNode, ast.pos, "java", "lang", "Object"),
				List.<JCExpression>of(maker.Literal(CTC_INT, 0)), null);
		JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
				maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic ? Flags.STATIC : 0)),
				methodNode.toName(lockName), objectType, newObjectArray), ast);
		injectFieldSuppressWarnings(methodNode.up(), fieldDecl);
	}
	
	if (method.body == null) return;
	
	JCExpression lockNode;
	if (isStatic) {
		lockNode = chainDots(methodNode, ast.pos, methodNode.up().getName(), lockName);
	} else {
		lockNode = maker.Select(maker.Ident(methodNode.toName("this")), methodNode.toName(lockName));
	}
	
	recursiveSetGeneratedBy(lockNode, ast);
	method.body = setGeneratedBy(maker.Block(0, List.<JCStatement>of(setGeneratedBy(maker.Synchronized(lockNode, method.body), ast))), ast);
	
	methodNode.rebuild();
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:59,代碼來源:HandleSynchronized.java

示例15: SuperCall

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
/** Generate call to superclass constructor. This is:
 *
 *    super(id_0, ..., id_n)
 *
 * or, if based == true
 *
 *    id_0.super(id_1,...,id_n)
 *
 *  where id_0, ..., id_n are the names of the given parameters.
 *
 *  @param make    The tree factory
 *  @param params  The parameters that need to be passed to super
 *  @param typarams  The type parameters that need to be passed to super
 *  @param based   Is first parameter a this$n?
 */
JCExpressionStatement SuperCall(TreeMaker make,
               List<Type> typarams,
               List<JCVariableDecl> params,
               boolean based) {
    JCExpression meth;
    if (based) {
        meth = make.Select(make.Ident(params.head), names._super);
        params = params.tail;
    } else {
        meth = make.Ident(names._super);
    }
    List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null;
    return make.Exec(make.Apply(typeargs, meth, make.Idents(params)));
}
 
開發者ID:sebastianoe,項目名稱:s4j,代碼行數:30,代碼來源:MemberEnter.java


注:本文中的com.sun.tools.javac.tree.TreeMaker.Select方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。