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


Java TreeMaker.TypeCast方法代碼示例

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


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

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

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

示例3: longToIntForHashCode

import com.sun.tools.javac.tree.TreeMaker; //導入方法依賴的package包/類
/** The 2 references must be clones of each other. */
private JCExpression longToIntForHashCode(TreeMaker maker, JCExpression ref1, JCExpression ref2) {
	/* (int)(ref >>> 32 ^ ref) */
	JCExpression shift = maker.Binary(CTC_UNSIGNED_SHIFT_RIGHT, ref1, maker.Literal(32));
	JCExpression xorBits = maker.Binary(CTC_BITXOR, shift, ref2);
	return maker.TypeCast(maker.TypeIdent(CTC_INT), xorBits);
}
 
開發者ID:redundent,項目名稱:lombok,代碼行數:8,代碼來源:HandleEqualsAndHashCode.java

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


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