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


Java TreeMaker.Apply方法代碼示例

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


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

示例1: createField

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private static boolean createField(LoggingFramework framework, JavacNode typeNode, JCFieldAccess loggingType, JCTree source) {
	TreeMaker maker = typeNode.getTreeMaker();
	
	// private static final <loggerType> log = <factoryMethod>(<parameter>);
	JCExpression loggerType = chainDotsString(typeNode, framework.getLoggerTypeName());
	JCExpression factoryMethod = chainDotsString(typeNode, framework.getLoggerFactoryMethodName());
	
	JCExpression loggerName = framework.createFactoryParameter(typeNode, loggingType);
	JCMethodInvocation factoryMethodCall = maker.Apply(List.<JCExpression>nil(), factoryMethod, List.<JCExpression>of(loggerName));
	
	JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
			maker.Modifiers(Flags.PRIVATE | Flags.FINAL | Flags.STATIC),
			typeNode.toName("log"), loggerType, factoryMethodCall), source);
	
	injectField(typeNode, fieldDecl);
	return true;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:18,代碼來源:HandleLog.java

示例2: replaceCastExpression

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

}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:34,代碼來源:ExtensionTransformer.java

示例3: buildBootstrapStaticBlock

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCTree.JCStatement buildBootstrapStaticBlock()
{
  TreeMaker make = _javacJacker.getTreeMaker();
  JavacElements javacElems = _javacJacker.getJavacElements();

  JCTree.JCMethodInvocation bootstrapInitCall = make.Apply( List.nil(), memberAccess( make, javacElems, Bootstrap.class.getName() + ".init" ), List.nil() );
  return make.Block( Modifier.STATIC, List.of( make.Exec( bootstrapInitCall ) ) );
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:9,代碼來源:BootstrapInserter.java

示例4: createWriteToParcel

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
@Override
public List<JCTree.JCStatement> createWriteToParcel(ASTHelper astHelper, Element rootElement, JCTree.JCExpression parcel, JCTree.JCExpression flags, String varName, boolean isArray) {
    final TreeMaker treeMaker = astHelper.getTreeMaker();
    final JCTree.JCExpression expression = treeMaker.Apply(
            List.<JCTree.JCExpression>nil(),
            treeMaker.Select(parcel, astHelper.getName(getWriteToParcelMethodCallName(isArray))),
            getWriteMethodCallParameters(treeMaker, astHelper.getName(varName), flags, isArray)
    );
    return List.of((JCTree.JCStatement) treeMaker.Exec(expression));
}
 
開發者ID:noties,項目名稱:ParcelGen,代碼行數:11,代碼來源:StatementCreatorBase.java

示例5: createSimpleGetterBody

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private List<JCStatement> createSimpleGetterBody(TreeMaker treeMaker, JavacNode field) {
	JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
	JCExpression fieldRef = createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD);

	JCStatement returnExpression = null;
	
	String varTypeString = fieldDecl.vartype.toString();
	boolean isMutable = false;
	boolean isTypeCastNeeded = false;
	if (Timestamp.class.getSimpleName().equals(varTypeString) || Timestamp.class.getName().equals(varTypeString)) {
		isMutable = true;
		isTypeCastNeeded = true;
	} else if (varTypeString.endsWith("[]")) {
		isMutable = true;
	}
	
	if (isMutable) {
		JCExpression nullCheck = treeMaker.Binary(CTC_EQUAL, fieldRef, treeMaker.Literal(CTC_BOT, null));
		JCExpression callClone = treeMaker.Apply(List.<JCExpression>nil(), treeMaker.Select(fieldRef, field.toName("clone")), List.<JCExpression>nil());					
		if (isTypeCastNeeded) {
			callClone = treeMaker.TypeCast(
					fieldDecl.vartype,
					callClone
			);
		}
		
		JCConditional conditional = treeMaker.Conditional(
				nullCheck, 
				treeMaker.Literal(CTC_BOT, null), 
				callClone
		);
		
		returnExpression = treeMaker.Return(conditional);
	} else {
		returnExpression = treeMaker.Return(fieldRef);
	}
	
	return List.<JCStatement>of(returnExpression);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:40,代碼來源:HandleGetter.java

示例6: 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

示例7: replaceStructuralCall

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCTree replaceStructuralCall( JCTree.JCMethodInvocation theCall )
{
  JCExpression methodSelect = theCall.getMethodSelect();
  if( methodSelect instanceof JCTree.JCFieldAccess )
  {
    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( theCall.pos(), names.fromString( "constructProxy" ), reflectMethodClassSym.type,
                                                                  List.from( new Type[]{symbols.objectType, symbols.classType} ) );

    JCTree.JCFieldAccess m = (JCTree.JCFieldAccess)methodSelect;
    TreeMaker make = _tp.getTreeMaker();
    JavacElements javacElems = _tp.getElementUtil();
    JCExpression thisArg = m.selected;

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

    JCTree.JCMethodInvocation makeProxyCall = make.Apply( List.nil(), memberAccess( make, javacElems, ExtensionTransformer.class.getName() + ".constructProxy" ), List.from( newArgs ) );
    makeProxyCall.setPos( theCall.pos );
    makeProxyCall.type = thisArg.type;
    JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)makeProxyCall.getMethodSelect();
    newMethodSelect.sym = makeInterfaceProxyMethod;
    newMethodSelect.type = makeInterfaceProxyMethod.type;
    assignTypes( newMethodSelect.selected, reflectMethodClassSym );

    JCTypeCast cast = make.TypeCast( thisArg.type, makeProxyCall );
    cast.type = thisArg.type;

    ((JCTree.JCFieldAccess)theCall.meth).selected = cast;
    return theCall;
  }
  return null;
}
 
開發者ID:manifold-systems,項目名稱:manifold,代碼行數:42,代碼來源:ExtensionTransformer.java

示例8: 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

示例9: callGet

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCMethodInvocation callGet(JavacNode source, JCExpression receiver) {
	TreeMaker maker = source.getTreeMaker();
	return maker.Apply(NIL_EXPRESSION, maker.Select(receiver, source.toName("get")), NIL_EXPRESSION);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:5,代碼來源:HandleGetter.java

示例10: createToString

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCMethodDecl createToString(JavacNode typeNode, List<JavacNode> fields, boolean includeFieldNames, boolean callSuper, FieldAccess fieldAccess, JCTree source) {
	TreeMaker maker = typeNode.getTreeMaker();
	
	JCAnnotation overrideAnnotation = maker.Annotation(chainDots(typeNode, "java", "lang", "Override"), List.<JCExpression>nil());
	JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
	JCExpression returnType = chainDots(typeNode, "java", "lang", "String");
	
	boolean first = true;
	
	String typeName = getTypeName(typeNode);
	String infix = ", ";
	String suffix = ")";
	String prefix;
	if (callSuper) {
		prefix = typeName + "(super=";
	} else if (fields.isEmpty()) {
		prefix = typeName + "()";
	} else if (includeFieldNames) {
		prefix = typeName + "(" + ((JCVariableDecl)fields.iterator().next().get()).name.toString() + "=";
	} else {
		prefix = typeName + "(";
	}
	
	JCExpression current = maker.Literal(prefix);
	
	if (callSuper) {
		JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
				maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("toString")),
				List.<JCExpression>nil());
		current = maker.Binary(CTC_PLUS, current, callToSuper);
		first = false;
	}
	
	for (JavacNode fieldNode : fields) {
		JCExpression expr;
		
		JCExpression fieldAccessor = createFieldAccessor(maker, fieldNode, fieldAccess);
		
		JCExpression fieldType = getFieldType(fieldNode, fieldAccess);
		
		// The distinction between primitive and object will be useful if we ever add a 'hideNulls' option.
		boolean fieldIsPrimitive = fieldType instanceof JCPrimitiveTypeTree;
		boolean fieldIsPrimitiveArray = fieldType instanceof JCArrayTypeTree && ((JCArrayTypeTree) fieldType).elemtype instanceof JCPrimitiveTypeTree;
		boolean fieldIsObjectArray = !fieldIsPrimitiveArray && fieldType instanceof JCArrayTypeTree;
		@SuppressWarnings("unused")
		boolean fieldIsObject = !fieldIsPrimitive && !fieldIsPrimitiveArray && !fieldIsObjectArray;
		
		if (fieldIsPrimitiveArray || fieldIsObjectArray) {
			JCExpression tsMethod = chainDots(typeNode, "java", "util", "Arrays", fieldIsObjectArray ? "deepToString" : "toString");
			expr = maker.Apply(List.<JCExpression>nil(), tsMethod, List.<JCExpression>of(fieldAccessor));
		} else expr = fieldAccessor;
		
		if (first) {
			current = maker.Binary(CTC_PLUS, current, expr);
			first = false;
			continue;
		}
		
		if (includeFieldNames) {
			current = maker.Binary(CTC_PLUS, current, maker.Literal(infix + fieldNode.getName() + "="));
		} else {
			current = maker.Binary(CTC_PLUS, current, maker.Literal(infix));
		}
		
		current = maker.Binary(CTC_PLUS, current, expr);
	}
	
	if (!first) current = maker.Binary(CTC_PLUS, current, maker.Literal(suffix));
	
	JCStatement returnStatement = maker.Return(current);
	
	JCBlock body = maker.Block(0, List.of(returnStatement));
	
	return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("toString"), returnType,
			List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null), source);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:77,代碼來源:HandleToString.java

示例11: get

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

示例12: preventNullAnalysis

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
private JCMethodInvocation preventNullAnalysis(TreeMaker maker, JavacNode node, JCExpression expression) {
	JCMethodInvocation singletonList = maker.Apply(List.<JCExpression>nil(), chainDotsString(node, "java.util.Collections.singletonList"), List.of(expression));
	JCMethodInvocation cleanedExpr = maker.Apply(List.<JCExpression>nil(), maker.Select(singletonList, node.toName("get")) , List.<JCExpression>of(maker.Literal(TypeTags.INT, 0)));
	return cleanedExpr;
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:6,代碼來源:HandleCleanup.java


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