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


Java JCTree.JCCompilationUnit方法代码示例

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


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

示例1: getResourceName

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@CheckForNull
private static String getResourceName (@NullAllowed final CompilationUnitTree cu) {
    if (cu instanceof JCTree.JCCompilationUnit) {
        JavaFileObject jfo = ((JCTree.JCCompilationUnit)cu).sourcefile;
        if (jfo != null) {
            URI uri = jfo.toUri();
            if (uri != null && uri.isAbsolute()) {
                try {
                    FileObject fo = URLMapper.findFileObject(uri.toURL());
                    if (fo != null) {
                        ClassPath cp = ClassPath.getClassPath(fo,ClassPath.SOURCE);
                        if (cp != null) {
                            return cp.getResourceName(fo,'.',false);
                        }
                    }
                } catch (MalformedURLException e) {
                    Exceptions.printStackTrace(e);
                }
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:SourceAnalyzerFactory.java

示例2: resolve

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
 * Resolves an {@link Element} from the {@link ElementHandle}.
 * @param compilationInfo representing the {@link javax.tools.CompilationTask}
 * in which the {@link Element} should be resolved.
 * @return resolved subclass of {@link Element} or null if the elment does not exist on
 * the classpath/sourcepath of {@link javax.tools.CompilationTask}.
 */
@SuppressWarnings ("unchecked")     // NOI18N
public @CheckForNull T resolve (@NonNull final CompilationInfo compilationInfo) {
    Parameters.notNull("compilationInfo", compilationInfo); // NOI18N
    ModuleElement module = compilationInfo.getFileObject() != null
            ? ((JCTree.JCCompilationUnit)compilationInfo.getCompilationUnit()).modle
            : null;
    T result = resolveImpl (module, compilationInfo.impl.getJavacTask());
    if (result == null) {
        if (log.isLoggable(Level.INFO))
            log.log(Level.INFO, "Cannot resolve: {0}", toString()); //NOI18N                
    } else {
        if (log.isLoggable(Level.FINE))
            log.log(Level.FINE, "Resolved element = {0}", result);
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ElementHandle.java

示例3: parse

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Nullable
public JCTree.JCCompilationUnit parse(final String src) {
    if (!canParse) return null;
    long time = System.currentTimeMillis();

    SimpleJavaFileObject source = new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
        @Override
        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
            return src;
        }
    };
    Log.instance(context).useSource(source);
    Parser parser = parserFactory.newParser(src,
        /*keepDocComments=*/ true,
        /*keepEndPos=*/ true,
        /*keepLineMap=*/ true);
    JCTree.JCCompilationUnit unit;
    unit = parser.parseCompilationUnit();
    unit.sourcefile = source;
    android.util.Log.d(TAG, "parse: time " + (System.currentTimeMillis() - time) + " ms");
    return unit;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:23,代码来源:JavaParser.java

示例4: started

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public void started( TaskEvent te )
{
  if( JreUtil.isJava8() )
  {
    return;
  }

  CompilationUnitTree compilationUnit = te.getCompilationUnit();
  if( !(compilationUnit instanceof JCTree.JCCompilationUnit) )
  {
    return;
  }

  if( _done )
  {
    return;
  }

  _done = true;

  openModule( _ctx, "jdk.compiler" );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:24,代码来源:BootstrapPlugin.java

示例5: processAnnotations

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public void processAnnotations(List<JCTree.JCCompilationUnit> roots, Collection<String> classnames) {
    if (roots.isEmpty()) {
        super.processAnnotations(roots, classnames);
    } else {
        setOrigin(roots.head.sourcefile.toUri().toString());
        try {
            super.processAnnotations(roots, classnames);
        } finally {
            setOrigin("");
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:NBJavaCompiler.java

示例6: hijackJavacCompilerForJava9

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private void hijackJavacCompilerForJava9( TaskEvent te )
{
  if( IS_JAVA_8 )
  {
    return;
  }

  CompilationUnitTree compilationUnit = te.getCompilationUnit();
  if( !(compilationUnit instanceof JCTree.JCCompilationUnit) )
  {
    return;
  }

  Symbol module = (Symbol)ReflectUtil.field( compilationUnit, "modle" ).get();
  if( module == null || _seenModules.contains( module ) )
  {
    return;
  }

  _seenModules.add( module );

  BootstrapPlugin.openModule( _ctx, "jdk.compiler" );

  // Override javac's Resolve (lol)
  ReflectUtil.method( ReflectUtil.type( "manifold.internal.javac.ManResolve" ), "instance", Context.class ).invokeStatic( _ctx );

  // Override javac's ClassFinder
  ReflectUtil.method( ReflectUtil.type( "manifold.internal.javac.ManClassFinder" ), "instance", Context.class ).invokeStatic( _ctx );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:30,代码来源:JavacPlugin.java

示例7: test1

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public void test1() {
    Context context = new Context();
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
    context.put(DiagnosticListener.class, diagnostics);
    Options.instance(context).put("allowStringFolding", "false");
    JCTree.JCCompilationUnit unit;
    JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8);
    try {
        fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.<File>of());
    } catch (IOException e) {
        // impossible
        throw new IOError(e);
    }
    SimpleJavaFileObject source =
            new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
                @Override
                public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
                    return src;
                }
            };
    Log.instance(context).useSource(source);
    ParserFactory parserFactory = ParserFactory.instance(context);
    Parser parser =
            parserFactory.newParser(
                    src,
        /*keepDocComments=*/ true,
        /*keepEndPos=*/ true,
        /*keepLineMap=*/ true);
    unit = parser.parseCompilationUnit();
    unit.sourcefile = source;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:32,代码来源:TestJavacParser.java

示例8: test4

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public void test4() {
    Context context = new Context();
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
    context.put(DiagnosticListener.class, diagnostics);
    Options.instance(context).put("allowStringFolding", "false");
    JCTree.JCCompilationUnit unit;
    JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8);
    try {
        fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.<File>of());
    } catch (IOException e) {
        // impossible
        throw new IOError(e);
    }
    SimpleJavaFileObject source =
            new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
                @Override
                public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
                    return src;
                }
            };
    Log.instance(context).useSource(source);
    ParserFactory parserFactory = ParserFactory.instance(context);
    Parser parser =
            parserFactory.newParser(
                    src,
        /*keepDocComments=*/ true,
        /*keepEndPos=*/ true,
        /*keepLineMap=*/ true);
    unit = parser.parseCompilationUnit();
    unit.sourcefile = source;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:32,代码来源:TestJavacParser.java

示例9: resolveMethod

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private static Symbol.MethodSymbol resolveMethod( JCDiagnostic.DiagnosticPosition pos, Context ctx, JCTree.JCCompilationUnit compUnit, Name name, Type qual, List<Type> args )
{
  Resolve rs = Resolve.instance( ctx );
  AttrContext attrContext = new AttrContext();
  Env<AttrContext> env = new AttrContextEnv( pos.getTree(), attrContext );
  env.toplevel = compUnit;
  return rs.resolveInternalMethod( pos, env, qual, name, args, null );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:9,代码来源:ExtensionTransformer.java

示例10: getDocComment

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public String getDocComment(TreePath path) {
    CompilationUnitTree t = path.getCompilationUnit();
    Tree leaf = path.getLeaf();
    if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
        JCCompilationUnit cu = (JCCompilationUnit) t;
        if (cu.docComments != null) {
            return cu.docComments.getCommentText((JCTree) leaf);
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:JavacTrees.java

示例11: getDocCommentTree

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public DocCommentTree getDocCommentTree(TreePath path) {
    CompilationUnitTree t = path.getCompilationUnit();
    Tree leaf = path.getLeaf();
    if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
        JCCompilationUnit cu = (JCCompilationUnit) t;
        if (cu.docComments != null) {
            return cu.docComments.getCommentTree((JCTree) leaf);
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:JavacTrees.java

示例12: getDocComment

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public String getDocComment(TreePath path) {
    CompilationUnitTree t = path.getCompilationUnit();
    Tree leaf = path.getLeaf();
    if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
        JCCompilationUnit cu = (JCCompilationUnit) t;
        if (cu.docComments != null) {
            return cu.docComments.getCommentText((JCTree) leaf);
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:JavacTrees.java

示例13: getDocCommentTree

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public DocCommentTree getDocCommentTree(TreePath path) {
    CompilationUnitTree t = path.getCompilationUnit();
    Tree leaf = path.getLeaf();
    if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) {
        JCCompilationUnit cu = (JCCompilationUnit) t;
        if (cu.docComments != null) {
            return cu.docComments.getCommentTree((JCTree) leaf);
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:JavacTrees.java

示例14: getClassDecl

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public JCTree.JCClassDecl getClassDecl( Tree node )
{
  if( node == null || node instanceof JCTree.JCCompilationUnit )
  {
    return null;
  }

  if( node instanceof JCTree.JCClassDecl )
  {
    return (JCTree.JCClassDecl)node;
  }

  return getClassDecl( getParent( node ) );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:15,代码来源:CompiledTypeProcessor.java

示例15: hasCallHandlerMethod

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private static boolean hasCallHandlerMethod( Class rootClass )
{
  String fqn = rootClass.getCanonicalName();
  BasicJavacTask javacTask = JavaParser.instance().getJavacTask();
  Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( ManifoldHost.getGlobalModule() ).getClassSymbol( javacTask, fqn );
  Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> callHandlerSymbol = ClassSymbols.instance( ManifoldHost.getGlobalModule() ).getClassSymbol( javacTask, ICallHandler.class.getCanonicalName() );
  if( Types.instance( javacTask.getContext() ).isAssignable( classSymbol.getFirst().asType(), callHandlerSymbol.getFirst().asType() ) )
  {
    // Nominally implements ICallHandler
    return true;
  }

  return hasCallMethod( javacTask, classSymbol.getFirst() );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:15,代码来源:ExtensionTransformer.java


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