本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCMethodInvocation方法的典型用法代码示例。如果您正苦于以下问题:Java JCTree.JCMethodInvocation方法的具体用法?Java JCTree.JCMethodInvocation怎么用?Java JCTree.JCMethodInvocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.tree.JCTree
的用法示例。
在下文中一共展示了JCTree.JCMethodInvocation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceExtCall
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的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 );
}
}
}
示例2: isStructuralMethod
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的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;
}
示例3: isConstructProxyCall
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private boolean isConstructProxyCall( JCExpression expression )
{
if( expression instanceof JCTree.JCMethodInvocation )
{
// don't erase cast if we generated it here e.g.., for structural call cast on constructProxy
JCExpression meth = ((JCTree.JCMethodInvocation)expression).meth;
return meth instanceof JCTree.JCFieldAccess && ((JCTree.JCFieldAccess)meth).getIdentifier().toString().equals( "constructProxy" );
}
return expression instanceof JCTypeCast && isConstructProxyCall( ((JCTypeCast)expression).getExpression() );
}
示例4: visitApply
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
* Replace all extension method call-sites with static calls to extension methods
*/
@Override
public void visitApply( JCTree.JCMethodInvocation tree )
{
super.visitApply( tree );
Symbol.MethodSymbol method = findExtMethod( tree );
eraseGenericStructuralVarargs( tree );
if( _tp.isGenerate() )
{
// Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
return;
}
if( method != null )
{
// Replace with extension method call
replaceExtCall( tree, method );
result = tree;
}
else if( isStructuralMethod( tree ) )
{
// The structural interface method is implemented directly in the type or supertype hierarchy,
// replace with proxy call
result = replaceStructuralCall( tree );
}
else
{
result = tree;
}
}
示例5: eraseGenericStructuralVarargs
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private void eraseGenericStructuralVarargs( JCTree.JCMethodInvocation tree )
{
if( tree.varargsElement instanceof Type.ClassType && TypeUtil.isStructuralInterface( _tp, tree.varargsElement.tsym ) )
{
tree.varargsElement = _tp.getSymtab().objectType;
}
}
示例6: replaceCastExpression
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的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;
}
示例7: buildBootstrapStaticBlock
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的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 ) ) );
}
示例8: replaceStructuralCall
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的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;
}
示例9: findExtMethod
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private Symbol.MethodSymbol findExtMethod( JCTree.JCMethodInvocation tree )
{
JCExpression methodSelect = tree.getMethodSelect();
if( methodSelect instanceof MemberSelectTree )
{
JCTree.JCFieldAccess meth = (JCTree.JCFieldAccess)tree.meth;
if( meth.sym == null || !meth.sym.hasAnnotations() )
{
return null;
}
for( Attribute.Compound annotation : meth.sym.getAnnotationMirrors() )
{
if( annotation.type.toString().equals( ExtensionMethod.class.getName() ) )
{
String extensionClass = (String)annotation.values.get( 0 ).snd.getValue();
boolean isStatic = (boolean)annotation.values.get( 1 ).snd.getValue();
BasicJavacTask javacTask = (BasicJavacTask)_tp.getJavacTask(); //JavacHook.instance() != null ? (JavacTaskImpl)JavacHook.instance().getJavacTask() : ClassSymbols.instance( _sp.getTypeLoader().getModule() ).getJavacTask();
Symbol.ClassSymbol extClassSym = ClassSymbols.instance( _sp.getTypeLoader().getModule() ).getClassSymbol( javacTask, extensionClass ).getFirst();
if( extClassSym == null )
{
// This can happen during bootstrapping with Dark Java classes from Manifold itself
// e.g., ManResolve is a darkj class Manifold uses, ManResolve uses String, which may have an extension class which needs ManResole...
// So we short-circuit that here (ManResolve or any other darkj class used during bootstrapping doesn't really need to use extensions)
return null;
}
Types types = Types.instance( javacTask.getContext() );
outer:
for( Symbol elem : IDynamicJdk.instance().getMembers( extClassSym ) )
{
if( elem instanceof Symbol.MethodSymbol && elem.flatName().toString().equals( meth.sym.name.toString() ) )
{
Symbol.MethodSymbol extMethodSym = (Symbol.MethodSymbol)elem;
List<Symbol.VarSymbol> extParams = extMethodSym.getParameters();
List<Symbol.VarSymbol> calledParams = ((Symbol.MethodSymbol)meth.sym).getParameters();
int thisOffset = isStatic ? 0 : 1;
if( extParams.size() - thisOffset != calledParams.size() )
{
continue;
}
for( int i = thisOffset; i < extParams.size(); i++ )
{
Symbol.VarSymbol extParam = extParams.get( i );
Symbol.VarSymbol calledParam = calledParams.get( i - thisOffset );
if( !types.isSameType( types.erasure( extParam.type ), types.erasure( calledParam.type ) ) )
{
continue outer;
}
}
return extMethodSym;
}
}
}
}
}
return null;
}