当前位置: 首页>>代码示例>>Java>>正文


Java Symbol.ClassSymbol方法代码示例

本文整理汇总了Java中com.sun.tools.javac.code.Symbol.ClassSymbol方法的典型用法代码示例。如果您正苦于以下问题:Java Symbol.ClassSymbol方法的具体用法?Java Symbol.ClassSymbol怎么用?Java Symbol.ClassSymbol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.tools.javac.code.Symbol的用法示例。


在下文中一共展示了Symbol.ClassSymbol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractClass

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
/** Extract reflection Class<?> information from type element. */
@NonNull
public static Class<?> extractClass(@NonNull final TypeElement te) throws ClassNotFoundException {
    final Name name;

    if (te instanceof Symbol.ClassSymbol) {
        final Symbol.ClassSymbol cs = (Symbol.ClassSymbol) te;

        // this method is more accurate for nested classes
        name = cs.flatName();
    } else {
        name = te.getQualifiedName();
    }

    final String className = name.toString();

    try {
        return Class.forName(className).asSubclass(Annotation.class);
    } catch (ClassNotFoundException ex) {
        // it can be sub-type, try another approach bellow
    }

    final int dot = className.lastIndexOf(".");
    final String innerFix2 = className.substring(0, dot) + "$" + className.substring(dot + 1);
    return Class.forName(innerFix2).asSubclass(Annotation.class);
}
 
开发者ID:OleksandrKucherenko,项目名称:autoproxy,代码行数:27,代码来源:CommonClassGenerator.java

示例2: replaceExtCall

import com.sun.tools.javac.code.Symbol; //导入方法依赖的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 );
    }
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:27,代码来源:ExtensionTransformer.java

示例3: getClassSymbol

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
public Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> getClassSymbol( BasicJavacTask javacTask, String fqn )
{
  JavacElements elementUtils = JavacElements.instance( javacTask.getContext() );
  Symbol.ClassSymbol typeElement = elementUtils.getTypeElement( fqn );
  JavacTrees trees = JavacTrees.instance( javacTask.getContext() );
  TreePath path = trees.getPath( typeElement );
  if( path != null )
  {
    return new Pair<>( typeElement, (JCTree.JCCompilationUnit)path.getCompilationUnit() );
  }
  else
  {
    // TreePath is only applicable to a source file;
    // if fqn is not a source file, there is no compilation unit available
    return new Pair<>( typeElement, null );
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:18,代码来源:ClassSymbols.java

示例4: handle

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
public void handle(Element element) {
    if (! (element.getKind() == ElementKind.INTERFACE)) return;
    Symbol.ClassSymbol classSymbol = (Symbol.ClassSymbol) element;
    String qualifiedName = classSymbol.getQualifiedName().toString();
    String clz = classSymbol.getSimpleName().toString();
    String pkg = qualifiedName.substring(0, qualifiedName.lastIndexOf("."));
    genXmlConfig(pkg, clz, classSymbol);
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:9,代码来源:DaoGenProcessor.java

示例5: genNewXml

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
private String genNewXml(String data, Symbol.ClassSymbol classSymbol) {
    DaoGen daoGen = classSymbol.getAnnotation(DaoGen.class);
    DaoEnv daoEnv = new DaoEnv(daoGen,classSymbol);
    Function<Symbol.MethodSymbol,MapperMethod> gen = (methodSymbol -> DaoGenHelper.toMapperMethod(daoEnv, methodSymbol));

    Map<String,MapperMethod> methodMap =
            daoGenHelper.getMember(Symbol.MethodSymbol.class, ElementKind.METHOD, classSymbol)
            .stream()
            .filter(methodSymbol1 -> !methodsInObjects.contains(methodSymbol1.getSimpleName().toString()))
            .filter(m -> m.getAnnotationMirrors()
                    .stream()
                    .noneMatch(c -> c.getAnnotationType().toString().contains("org.apache.ibatis.annotations")))
                    .collect(Collectors.toMap(DaoGenHelper::getMethodName, gen));
    return daoGenHelper.mixMethodToData(daoGen, classSymbol.toString(),methodMap,data);
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:16,代码来源:DaoGenProcessor.java

示例6: getSafeInitMethods

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
/**
 * @param blockTree block of statements
 * @param state visitor state
 * @return Elements of safe init methods that are invoked as top-level statements in the method
 */
private Set<Element> getSafeInitMethods(
    BlockTree blockTree, Symbol.ClassSymbol classSymbol, VisitorState state) {
  Set<Element> result = new LinkedHashSet<>();
  List<? extends StatementTree> statements = blockTree.getStatements();
  for (StatementTree stmt : statements) {
    Element privMethodElem = getInvokeOfSafeInitMethod(stmt, classSymbol, state);
    if (privMethodElem != null) {
      result.add(privMethodElem);
    }
  }
  return result;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:18,代码来源:NullAway.java

示例7: getInvokeOfSafeInitMethod

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
/**
 * A safe init method is an instance method that is either private or final (so no overriding is
 * possible)
 *
 * @param stmt the statement
 * @param enclosingClassSymbol symbol for enclosing constructor / initializer
 * @param state visitor state
 * @return element of safe init function if stmt invokes that function; null otherwise
 */
@Nullable
private Element getInvokeOfSafeInitMethod(
    StatementTree stmt, final Symbol.ClassSymbol enclosingClassSymbol, VisitorState state) {
  Matcher<ExpressionTree> invokeMatcher =
      (expressionTree, s) -> {
        if (!(expressionTree instanceof MethodInvocationTree)) {
          return false;
        }
        MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expressionTree;
        Symbol.MethodSymbol symbol = ASTHelpers.getSymbol(methodInvocationTree);
        Set<Modifier> modifiers = symbol.getModifiers();
        if ((symbol.isPrivate() || modifiers.contains(Modifier.FINAL)) && !symbol.isStatic()) {
          // check it's the same class (could be an issue with inner classes)
          if (ASTHelpers.enclosingClass(symbol).equals(enclosingClassSymbol)) {
            // make sure the receiver is 'this'
            ExpressionTree receiver = ASTHelpers.getReceiver(expressionTree);
            return receiver == null || isThisIdentifier(receiver);
          }
        }
        return false;
      };
  if (stmt.getKind().equals(EXPRESSION_STATEMENT)) {
    ExpressionTree expression = ((ExpressionStatementTree) stmt).getExpression();
    if (invokeMatcher.matches(expression, state)) {
      return ASTHelpers.getSymbol(expression);
    }
  }
  return null;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:39,代码来源:NullAway.java

示例8: onMatchTopLevelClass

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
@Override
public void onMatchTopLevelClass(
    NullAway analysis, ClassTree tree, VisitorState state, Symbol.ClassSymbol classSymbol) {
  // Clear compilation unit specific state
  this.filterMethodOrLambdaSet.clear();
  this.observableOuterCallInChain.clear();
  this.observableCallToInnerMethodOrLambda.clear();
  this.mapToFilterMap.clear();
  this.filterToNSMap.clear();
  this.bodyToMethodOrLambda.clear();
  this.returnToEnclosingMethodOrLambda.clear();
}
 
开发者ID:uber,项目名称:NullAway,代码行数:13,代码来源:RxNullabilityPropagator.java

示例9: getTypeByName

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
Type getTypeByName(String typeName, List<Type> tparams) {
    return new Type.ClassType(
               Type.noType,
               tparams,
               new Symbol.ClassSymbol(0, names.fromString(typeName), null));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:PackageGenerator.java

示例10: getClassSymbol

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
public Symbol.ClassSymbol getClassSymbol( String fqn )
{
  return getElementUtil().getTypeElement( fqn );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:5,代码来源:CompiledTypeProcessor.java

示例11: getFullName

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
public CharSequence getFullName(Element element) {
    Symbol sym = (Symbol)element;
    return element instanceof Symbol.ClassSymbol ? 
        ((Symbol.ClassSymbol)element).fullname :
        Symbol.TypeSymbol.formFullName(sym.name, sym.owner);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:ElementsService.java

示例12: removeNotInProfile

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
Collection<? extends Symbol.ClassSymbol> removeNotInProfile(final URI uri) {
    return uri == null ? null : notInProfiles.remove(uri);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:4,代码来源:NBMessager.java

示例13: getObjectClass

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
Symbol.ClassSymbol getObjectClass()
{
  Symtab symbols = Symtab.instance( _tp.getContext() );
  return (Symbol.ClassSymbol)symbols.objectType.tsym;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:6,代码来源:ExtensionTransformer.java

示例14: checkFieldInitialization

import com.sun.tools.javac.code.Symbol; //导入方法依赖的package包/类
/**
 * check that all @NonNull fields of the class are properly initialized
 *
 * @param tree the class
 * @param state visitor state
 */
private void checkFieldInitialization(ClassTree tree, VisitorState state) {
  FieldInitEntities entities = collectEntities(tree, state);
  Symbol.ClassSymbol classSymbol = ASTHelpers.getSymbol(tree);
  class2Entities.put(classSymbol, entities);
  // set of all non-null instance fields f such that *some* constructor does not initialize f
  Set<Symbol> notInitializedInConstructors;
  SetMultimap<MethodTree, Symbol> constructorInitInfo;
  if (entities.constructors().isEmpty()) {
    constructorInitInfo = null;
    notInitializedInConstructors = entities.nonnullInstanceFields();
  } else {
    constructorInitInfo = checkConstructorInitialization(entities, state);
    notInitializedInConstructors = ImmutableSet.copyOf(constructorInitInfo.values());
  }
  class2ConstructorUninit.putAll(classSymbol, notInitializedInConstructors);
  Set<Symbol> notInitializedAtAll =
      notAssignedInAnyInitializer(entities, notInitializedInConstructors, state);
  SetMultimap<Element, Element> errorFieldsForInitializer = LinkedHashMultimap.create();
  // non-null if we have a single initializer method
  Symbol.MethodSymbol singleInitializerMethod = null;
  if (entities.instanceInitializerMethods().size() == 1) {
    singleInitializerMethod =
        ASTHelpers.getSymbol(entities.instanceInitializerMethods().iterator().next());
  }
  for (Symbol uninitField : notInitializedAtAll) {
    if (singleInitializerMethod != null) {
      // report it on the initializer
      errorFieldsForInitializer.put(singleInitializerMethod, uninitField);
    } else if (constructorInitInfo == null) {
      // report it on the field
      fieldsWithInitializationErrors.add(uninitField);
    } else {
      // report it on each constructor that does not initialize it
      for (MethodTree methodTree : constructorInitInfo.keySet()) {
        Set<Symbol> uninitFieldsForConstructor = constructorInitInfo.get(methodTree);
        if (uninitFieldsForConstructor.contains(uninitField)) {
          errorFieldsForInitializer.put(ASTHelpers.getSymbol(methodTree), uninitField);
        }
      }
    }
  }
  for (Element constructorElement : errorFieldsForInitializer.keySet()) {
    initializerErrors.put(
        constructorElement,
        errMsgForInitializer(errorFieldsForInitializer.get(constructorElement)));
  }
  // For static fields
  Set<Symbol> notInitializedStaticFields = notInitializedStatic(entities, state);
  for (Symbol uninitSField : notInitializedStaticFields) {
    // Always report it on the field for static fields (can't do @SuppressWarnings on a static
    // initialization block
    // anyways).
    fieldsWithInitializationErrors.add(uninitSField);
  }
}
 
开发者ID:uber,项目名称:NullAway,代码行数:62,代码来源:NullAway.java

示例15: 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;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:57,代码来源:ExtensionTransformer.java


注:本文中的com.sun.tools.javac.code.Symbol.ClassSymbol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。