本文整理汇总了Java中com.sun.tools.javac.code.Symbol.VarSymbol方法的典型用法代码示例。如果您正苦于以下问题:Java Symbol.VarSymbol方法的具体用法?Java Symbol.VarSymbol怎么用?Java Symbol.VarSymbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.code.Symbol
的用法示例。
在下文中一共展示了Symbol.VarSymbol方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addField
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
private void addField( SrcClass srcClass, Symbol sym )
{
Symbol.VarSymbol field = (Symbol.VarSymbol)sym;
SrcField srcField = new SrcField( field.name.toString(), new SrcType( field.type.toString() ) );
if( sym.isEnum() )
{
srcField.enumConst();
}
else
{
srcField.modifiers( field.getModifiers() );
if( Modifier.isFinal( (int)srcField.getModifiers() ) )
{
srcField.initializer( new SrcRawExpression( getValueForType( sym.type ) ) );
}
}
srcClass.addField( srcField );
}
示例2: genSuperCtorCall
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
private String genSuperCtorCall( Symbol.MethodSymbol superCtor )
{
String bodyStmt;
StringBuilder sb = new StringBuilder( "super(" );
List<Symbol.VarSymbol> parameters = superCtor.getParameters();
for( int i = 0; i < parameters.size(); i++ )
{
Symbol.VarSymbol param = parameters.get( i );
if( i > 0 )
{
sb.append( ", " );
}
sb.append( getValueForType( param.type ) );
}
sb.append( ");" );
bodyStmt = sb.toString();
return bodyStmt;
}
示例3: getFields
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
private List<String> getFields(Symbol.TypeSymbol type) {
String typeStr = type.toString();
if (!fieldsMap.containsKey(typeStr)) {
List<Symbol.VarSymbol> varSymbols = getMember(Symbol.VarSymbol.class, ElementKind.FIELD, type);
fieldsMap.put(typeStr, varSymbols.stream().filter(s->!s.isStatic()).map(Symbol.VarSymbol::toString).collect(Collectors.toList()));
}
return fieldsMap.get(typeStr);
}
示例4: mimicParameters
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
/** Compose method parameters that mimic original code. */
@NonNull
public static StringBuilder mimicParameters(@NonNull final MethodSpec.Builder builder,
@NonNull final Symbol.MethodSymbol ms) throws Exception {
String delimiter = "";
final StringBuilder arguments = new StringBuilder();
final com.sun.tools.javac.util.List<Symbol.VarSymbol> parameters = ms.getParameters();
for (int i = 0, len = parameters.size(); i < len; i++) {
final Symbol.VarSymbol param = parameters.get(i);
// mimic parameter of the method: name, type, modifiers
final TypeName paramType = TypeName.get(param.asType());
final String parameterName = param.name.toString();
final ParameterSpec.Builder parameter = ParameterSpec.builder(paramType, parameterName, Modifier.FINAL);
if (param.hasAnnotations()) {
// DONE: copy annotations of parameter
for (final Attribute.Compound am : param.getAnnotationMirrors()) {
final AnnotationSpec.Builder builderAnnotation = mimicAnnotation(am);
if (null != builderAnnotation) {
parameter.addAnnotation(builderAnnotation.build());
}
}
}
// support VarArgs if needed
builder.varargs(ms.isVarArgs() && i == len - 1);
builder.addParameter(parameter.build());
// compose parameters list for forwarding
arguments.append(delimiter).append(parameterName);
delimiter = ", ";
}
return arguments;
}
示例5: lambdaInitialStore
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
private NullnessStore<Nullness> lambdaInitialStore(
UnderlyingAST.CFGLambda underlyingAST, List<LocalVariableNode> parameters) {
NullnessStore.Builder<Nullness> result = NullnessStore.<Nullness>empty().toBuilder();
LambdaExpressionTree code = underlyingAST.getLambdaTree();
// need to check annotation for i'th parameter of functional interface declaration
Symbol.MethodSymbol fiMethodSymbol = NullabilityUtil.getFunctionalInterfaceMethod(code, types);
com.sun.tools.javac.util.List<Symbol.VarSymbol> fiMethodParameters =
fiMethodSymbol.getParameters();
for (int i = 0; i < parameters.size(); i++) {
LocalVariableNode param = parameters.get(i);
VariableTree variableTree = code.getParameters().get(i);
Element element = param.getElement();
Nullness assumed;
// we treat lambda parameters differently; they "inherit" the nullability of the
// corresponding functional interface parameter, unless they are explicitly annotated
if (Nullness.hasNullableAnnotation(element)) {
assumed = NULLABLE;
} else if (NullabilityUtil.lambdaParamIsExplicitlyTyped(variableTree)) {
// the parameter has a declared type with no @Nullable annotation
// treat as non-null
assumed = NONNULL;
} else {
if (fromUnannotatedPackage(fiMethodSymbol)) {
// optimistically assume parameter is non-null
assumed = NONNULL;
} else {
assumed = Nullness.hasNullableAnnotation(fiMethodParameters.get(i)) ? NULLABLE : NONNULL;
}
}
result.setInformation(AccessPath.fromLocal(param), assumed);
}
result = handler.onDataflowInitialStore(underlyingAST, parameters, result);
return result.build();
}
示例6: getParams
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
public List<Symbol.VarSymbol> getParams(){
return params;
}
示例7: findExtMethod
import com.sun.tools.javac.code.Symbol; //导入方法依赖的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;
}
示例8: hasCallMethod
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
private static boolean hasCallMethod( BasicJavacTask javacTask, Symbol.ClassSymbol classSymbol )
{
Name call = Names.instance( javacTask.getContext() ).fromString( "call" );
Iterable<Symbol> elems = IDynamicJdk.instance().getMembersByName( classSymbol, call );
for( Symbol s : elems )
{
if( s instanceof Symbol.MethodSymbol )
{
List<Symbol.VarSymbol> parameters = ((Symbol.MethodSymbol)s).getParameters();
if( parameters.size() != 6 )
{
return false;
}
Symtab symbols = Symtab.instance( javacTask.getContext() );
Types types = Types.instance( javacTask.getContext() );
return types.erasure( parameters.get( 0 ).asType() ).equals( types.erasure( symbols.classType ) ) &&
parameters.get( 1 ).asType().equals( symbols.stringType ) &&
parameters.get( 2 ).asType().equals( symbols.stringType ) &&
types.erasure( parameters.get( 3 ).asType() ).equals( types.erasure( symbols.classType ) ) &&
parameters.get( 4 ).asType() instanceof Type.ArrayType && types.erasure( ((Type.ArrayType)parameters.get( 4 ).asType()).getComponentType() ).equals( types.erasure( symbols.classType ) ) &&
parameters.get( 5 ).asType() instanceof Type.ArrayType && ((Type.ArrayType)parameters.get( 5 ).asType()).getComponentType().equals( symbols.objectType );
}
}
Type superclass = classSymbol.getSuperclass();
if( !(superclass instanceof NoType) )
{
if( hasCallMethod( javacTask, (Symbol.ClassSymbol)superclass.tsym ) )
{
return true;
}
}
for( Type iface : classSymbol.getInterfaces() )
{
if( hasCallMethod( javacTask, (Symbol.ClassSymbol)iface.tsym ) )
{
return true;
}
}
return false;
}
示例9: addMethod
import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
private void addMethod( IModule module, SrcClass srcClass, Symbol.MethodSymbol method, BasicJavacTask javacTask )
{
SrcMethod srcMethod = new SrcMethod( srcClass );
addAnnotations( srcMethod, method );
srcMethod.modifiers( method.getModifiers() );
if( (method.flags() & Flags.VARARGS) != 0 )
{
srcMethod.modifiers( srcMethod.getModifiers() | 0x00000080 ); // Modifier.VARARGS
}
String name = method.flatName().toString();
if( name.equals( "<clinit>" ) )
{
return;
}
boolean isConstructor = name.equals( "<init>" );
if( isConstructor )
{
srcMethod.name( srcClass.getSimpleName() );
srcMethod.setConstructor( true );
}
else
{
srcMethod.name( name );
srcMethod.returns( new SrcType( method.getReturnType().toString() ) );
}
for( Symbol.TypeVariableSymbol typeVar : method.getTypeParameters() )
{
srcMethod.addTypeVar( makeTypeVarType( typeVar ) );
}
for( Symbol.VarSymbol param : method.getParameters() )
{
SrcParameter srcParam = new SrcParameter( param.flatName().toString(), new SrcType( param.type.toString() ) );
srcMethod.addParam( srcParam );
addAnnotations( srcParam, param );
}
for( Type throwType : method.getThrownTypes() )
{
srcMethod.addThrowType( new SrcType( throwType.toString() ) );
}
String bodyStmt;
if( srcMethod.isConstructor() )
{
// Note we can't just throw an exception for the ctor body, the compiler will
// still complain about the missing super() cal if the super class does not have
// an accessible default ctor. To appease the compiler we generate a super(...)
// call to the first accessible constructor we can find in the super class.
bodyStmt = genSuperCtorCall( module, srcClass, javacTask );
}
else
{
bodyStmt = "throw new RuntimeException();";
}
srcMethod.body( new SrcStatementBlock()
.addStatement(
new SrcRawStatement()
.rawText( bodyStmt ) ) );
srcClass.addMethod( srcMethod );
}