本文整理匯總了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;
}
示例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);
}
示例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);
}
示例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;
}