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


Java JavacElements类代码示例

本文整理汇总了Java中com.sun.tools.javac.model.JavacElements的典型用法代码示例。如果您正苦于以下问题:Java JavacElements类的具体用法?Java JavacElements怎么用?Java JavacElements使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getLocalVars

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
/**Return variables declared in the given scope.
 */
public Iterable<? extends Element> getLocalVars(Scope scope, ElementAcceptor acceptor) {
    ArrayList<Element> members = new ArrayList<Element>();
    Elements elements = JavacElements.instance(ctx);
    Types types = JavacTypes.instance(ctx);
    while(scope != null && scope.getEnclosingClass() != null) {
        for (Element local : scope.getLocalElements()) {
            if (acceptor == null || acceptor.accept(local, null)) {
                if (!isHidden(local, members, elements, types)) {
                    members.add(local);
                }
            }
        }
        scope = scope.getEnclosingScope();
    }
    return members;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ElementUtilities.java

示例2: init

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
private void init(Context context) {
    modules = Modules.instance(context);
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);
    docTreeMaker = DocTreeMaker.instance(context);
    parser = ParserFactory.instance(context);
    syms = Symtab.instance(context);
    fileManager = context.get(JavaFileManager.class);
    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:JavacTrees.java

示例3: ToolEnvironment

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
/**
 * Constructor
 *
 * @param context      Context for this javadoc instance.
 */
protected ToolEnvironment(Context context) {
    context.put(ToolEnvKey, this);
    this.context = context;

    messager = Messager.instance0(context);
    syms = Symtab.instance(context);
    finder = JavadocClassFinder.instance(context);
    enter = JavadocEnter.instance(context);
    names = Names.instance(context);
    externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
    chk = Check.instance(context);
    types = com.sun.tools.javac.code.Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager instanceof JavacFileManager) {
        ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
    }
    docTrees = JavacTrees.instance(context);
    source = Source.instance(context);
    elements =  JavacElements.instance(context);
    typeutils = JavacTypes.instance(context);
    elementToTreePath = new HashMap<>();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:ToolEnvironment.java

示例4: process

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    round++;

    JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv;
    Context c = jpe.getContext();
    check(c.get(JavacElements.class), eltUtils);
    check(c.get(JavacTypes.class), typeUtils);
    check(c.get(JavacTrees.class), treeUtils);

    final int MAXROUNDS = 3;
    if (round < MAXROUNDS)
        generateSource("Gen" + round);

    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TestContext.java

示例5: replaceExtCall

import com.sun.tools.javac.model.JavacElements; //导入依赖的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

示例6: warnIfDuplicate

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
private boolean warnIfDuplicate( AbstractSrcMethod method, SrcClass extendedType, DiagnosticListener<JavaFileObject> errorHandler, JavacTaskImpl javacTask )
{
  AbstractSrcMethod duplicate = findMethod( method, extendedType, new JavacTaskImpl[]{javacTask} );

  if( duplicate == null )
  {
    return false;
  }

  JavacElements elems = JavacElements.instance( javacTask.getContext() );
  Symbol.ClassSymbol sym = elems.getTypeElement( ((SrcClass)method.getOwner()).getName() );
  JavaFileObject file = sym.sourcefile;
  SrcAnnotationExpression anno = duplicate.getAnnotation( ExtensionMethod.class );
  if( anno != null )
  {
    errorHandler.report( new JavacDiagnostic( file.toUri().getScheme() == null ? null : new SourceJavaFileObject( file.toUri() ),
                                              Diagnostic.Kind.WARNING, 0, 0, 0, ExtIssueMsg.MSG_EXTENSION_DUPLICATION.get( method.signature(), ((SrcClass)method.getOwner()).getName(), anno.getArgument( ExtensionMethod.extensionClass ).getValue()) ) );
  }
  else
  {
    errorHandler.report( new JavacDiagnostic( file.toUri().getScheme() == null ? null : new SourceJavaFileObject( file.toUri() ),
                                              Diagnostic.Kind.WARNING, 0, 0, 0, ExtIssueMsg.MSG_EXTENSION_SHADOWS.get( method.signature(), ((SrcClass)method.getOwner()).getName(), extendedType.getName()) ) );
  }
  return true;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:26,代码来源:ExtCodeGen.java

示例7: hijackJavacFileManager

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
private void hijackJavacFileManager()
{
  if( !(_fileManager instanceof ManifoldJavaFileManager) && _manFileManager == null )
  {
    _ctx = _javacTask.getContext();
    _fileManager = _ctx.get( JavaFileManager.class );
    _javaInputFiles = new HashSet<>();
    _gosuInputFiles = fetchGosuInputFiles();
    _treeMaker = TreeMaker.instance( _ctx );
    _javacElements = JavacElements.instance( _ctx );
    _typeProcessor = new TypeProcessor( _javacTask );
    _issueReporter = new IssueReporter( Log.instance( getContext() ) );
    _seenModules = new LinkedHashSet<>();

    injectManFileManager();
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:18,代码来源:JavacPlugin.java

示例8: getClassSymbol

import com.sun.tools.javac.model.JavacElements; //导入依赖的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

示例9: DocEnv

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
/**
 * Constructor
 *
 * @param context      Context for this javadoc instance.
 */
protected DocEnv(Context context) {
    context.put(docEnvKey, this);
    this.context = context;

    messager = Messager.instance0(context);
    syms = Symtab.instance(context);
    finder = JavadocClassFinder.instance(context);
    enter = JavadocEnter.instance(context);
    names = Names.instance(context);
    externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable"));
    chk = Check.instance(context);
    types = com.sun.tools.javac.code.Types.instance(context);
    fileManager = context.get(JavaFileManager.class);
    if (fileManager instanceof JavacFileManager) {
        ((JavacFileManager)fileManager).setSymbolFileEnabled(false);
    }
    docTrees = JavacTrees.instance(context);
    source = Source.instance(context);
    elements =  JavacElements.instance(context);
    typeutils = JavacTypes.instance(context);
    elementToTreePath = new HashMap<>();
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:28,代码来源:DocEnv.java

示例10: scan

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
@Override
public boolean scan(Element element) {
	try {
		this.rawSource = ((Symbol.ClassSymbol) element).sourcefile.getCharContent(true);
		TreePath path = trees.getPath(element);

		treeMaker = TreeMaker.instance(context);
		elements = JavacElements.instance(context);

		scan(path, context);

		return true;
	} catch(IOException e) {
		messager.printMessage(Diagnostic.Kind.WARNING,
				"Unable to find raw source for element " + element.getSimpleName().toString());
	} catch(NoClassDefFoundError ignored) {
		messager.printMessage(Diagnostic.Kind.WARNING,
				"Unable to generate power assertions because javac is not compiling the code");
	}
	return false;
}
 
开发者ID:jkschneider,项目名称:java-power-assert,代码行数:22,代码来源:JavacPowerAssertGenerator.java

示例11: createOrGetField

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
public GField createOrGetField(long modifiers, String name, String type, JCTree.JCExpression init) {
    GField field = (GField) getMember(name);
    if (field == null) {
        TreeMaker maker = getEnvironment().getMaker();
        JavacElements utils = getEnvironment().getUtils();
        JCVariableDecl variableDecl = maker.VarDef(maker.Modifiers(modifiers), utils.getName(name),
                maker.Ident(utils.getName(type)), init);

        field = new GField(this, variableDecl, null);
        field.setName(name);
        field.setMemberSignature(name);
        putMember(field);
        classDecl.defs = classDecl.defs.append(variableDecl);
    }

    return field;
}
 
开发者ID:ixkor,项目名称:genaroid,代码行数:18,代码来源:GClass.java

示例12: JavacProcessingEnvironment

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) {
    options = Options.instance(context);
    this.context = context;
    log = Log.instance(context);
    source = Source.instance(context);
    printProcessorInfo = options.get("-XprintProcessorInfo") != null;
    printRounds = options.get("-XprintRounds") != null;
    verbose = options.get("-verbose") != null;
    lint = options.lint("processing");
    procOnly = options.get("-proc:only") != null ||
        options.get("-Xprint") != null;
    fatalErrors = options.get("fatalEnterError") != null;
    platformAnnotations = initPlatformAnnotations();

    // Initialize services before any processors are initialzied
    // in case processors use them.
    filer = new JavacFiler(context);
    messager = new JavacMessager(context, this);
    elementUtils = new JavacElements(context);
    typeUtils = new JavacTypes(context);
    processorOptions = initProcessorOptions(context);
    unmatchedProcessorOptions = initUnmatchedProcessorOptions();
    initProcessorIterator(context, processors);
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:25,代码来源:JavacProcessingEnvironment.java

示例13: getWriteInlineMethod

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
private JCMethodDecl getWriteInlineMethod(JavacElements utils, JCExpression ioExceptionClass, JCModifiers methodModifiers, JCExpression objectOutputClass, JCBlock writeInlineBlock) {
    return maker.MethodDef(
            methodModifiers,
            utils.getName("writeInline"),
            maker.TypeIdent(TypeTag.VOID),
            List.<JCTypeParameter>nil(),
            List.of(
                    maker.VarDef(maker.Modifiers(Flags.PARAMETER), utils.getName("out"), objectOutputClass, null),
                    maker.VarDef(maker.Modifiers(Flags.PARAMETER), utils.getName("self"), ident(classDecl.name.toString()), null),
                    maker.VarDef(maker.Modifiers(Flags.PARAMETER), utils.getName("checkClass"), maker.TypeIdent(TypeTag.BOOLEAN), null)
            ),
            List.of(ioExceptionClass),
            writeInlineBlock,
            null
    );
}
 
开发者ID:Devexperts,项目名称:egen,代码行数:17,代码来源:AutoSerializableProcessor.java

示例14: TreeScannerStateful

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
public TreeScannerStateful(CompilationTask task, JCCompilationUnit jcc) {
  	this.jcc = jcc ;
      trees = Trees.instance(task);
      treesC = (JavacTrees)trees;
              
      //Rabbit hole to Wonderland
      context = ((BasicJavacTask)task).getContext() ;
this.task = ((BasicJavacTask)task) ;
      
      //Initialize magical classes !
      make = TreeMaker.instance(context) ;
      names = Names.instance(context) ;
      syms = Symtab.instance(context);
      types = Types.instance(context) ;
      typesC = JavacTypes.instance(context) ;
      attr = Attr.instance(context) ;
      enter = Enter.instance(context) ;
      resolve = Resolve.instance(context) ;
      memberEnter = MemberEnter.instance(context) ;
javacElements = JavacElements.instance(context) ;
info = TreeInfo.instance(context) ;

      sourcePositions = trees.getSourcePositions();
      elements = ((JavacTask)task).getElements();
      elementsC = (JavacElements)elements;
}
 
开发者ID:metabrain,项目名称:java8-plugin-persitent-local-vars,代码行数:27,代码来源:TreeScannerStateful.java

示例15: attach

import com.sun.tools.javac.model.JavacElements; //导入依赖的package包/类
public void attach(Context context, ImportAnalysis2 importAnalysis, Map<Tree, Object> tree2Tag) {
    make = TreeFactory.instance(context);
    elements = JavacElements.instance(context);
    comments = CommentHandlerService.instance(context);
    model = ASTService.instance(context);
    overlay = context.get(ElementOverlay.class);
    this.importAnalysis = importAnalysis;
    this.tree2Tag = tree2Tag;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ImmutableTreeTranslator.java


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