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


Java CompilationUnitTree.getPackageName方法代码示例

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


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

示例1: addInputFile

import com.sun.source.tree.CompilationUnitTree; //导入方法依赖的package包/类
private void addInputFile( TaskEvent e )
{
  if( !_initialized )
  {
    CompilationUnitTree compilationUnit = e.getCompilationUnit();
    ExpressionTree pkg = compilationUnit.getPackageName();
    String packageQualifier = pkg == null ? "" : (pkg.toString() + '.');
    for( Tree classDecl : compilationUnit.getTypeDecls() )
    {
      if( classDecl instanceof JCTree.JCClassDecl )
      {
        _javaInputFiles.add( new Pair<>( packageQualifier + ((JCTree.JCClassDecl)classDecl).getSimpleName(), compilationUnit.getSourceFile() ) );
      }
    }
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:17,代码来源:JavacPlugin.java

示例2: computeFQNs

import com.sun.source.tree.CompilationUnitTree; //导入方法依赖的package包/类
protected void computeFQNs(final Map<JavaFileObject, List<String>> file2FQNs, CompilationUnitTree cut, CompileTuple tuple) {
    String pack;
    if (cut.getPackageName() != null) {
        pack = cut.getPackageName().toString() + "."; //XXX
    } else {
        pack = "";
    }
    String path = tuple.indexable.getRelativePath();
    int i = path.lastIndexOf('.');
    if (i >= 0)
        path = path.substring(0, i);
    path = FileObjects.convertFolder2Package(path);
    List<String> fqns = new LinkedList<String>();
    boolean hasClassesLivingElsewhere = false;
    for (Tree t : cut.getTypeDecls()) {
        if (TreeUtilities.CLASS_TREE_KINDS.contains(t.getKind())) {
            String fqn = pack + ((ClassTree) t).getSimpleName().toString();
            fqns.add(fqn);
            if (!path.equals(fqn)) {
                hasClassesLivingElsewhere = true;
            }
        }
    }
    
    if (hasClassesLivingElsewhere) {
        file2FQNs.put(tuple.jfo, fqns);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:CompileWorker.java

示例3: isEvil

import com.sun.source.tree.CompilationUnitTree; //导入方法依赖的package包/类
private boolean isEvil(Tree tree) {
        Tree.Kind kind = tree.getKind();
        switch (kind) {
            case COMPILATION_UNIT:
                CompilationUnitTree cut = (CompilationUnitTree) tree;
                return cut.getPackageName() == null;
//            case MODIFIERS:
            case PRIMITIVE_TYPE:
                return true;
            default: return false;
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:AssignComments.java

示例4: getAllImportsOfKind

import com.sun.source.tree.CompilationUnitTree; //导入方法依赖的package包/类
private static List<TreePathHandle> getAllImportsOfKind(CompilationInfo ci, ImportHintKind kind) {
    //allow only default and samepackage
    assert (kind == ImportHintKind.DEFAULT_PACKAGE || kind == ImportHintKind.SAME_PACKAGE);

    CompilationUnitTree cut = ci.getCompilationUnit();
    TreePath topLevel = new TreePath(cut);
    List<TreePathHandle> result = new ArrayList<TreePathHandle>(3);

    List<? extends ImportTree> imports = cut.getImports();
    for (ImportTree it : imports) {
        if (it.isStatic()) {
            continue; // XXX
        }
        if (it.getQualifiedIdentifier() instanceof MemberSelectTree) {
            MemberSelectTree ms = (MemberSelectTree) it.getQualifiedIdentifier();
            if (kind == ImportHintKind.DEFAULT_PACKAGE) {
                if (ms.getExpression().toString().equals(DEFAULT_PACKAGE)) {
                    result.add(TreePathHandle.create(new TreePath(topLevel, it), ci));
                }
            }
            if (kind == ImportHintKind.SAME_PACKAGE) {
                ExpressionTree packageName = cut.getPackageName();
                if (packageName != null &&
                    ms.getExpression().toString().equals(packageName.toString())) {
                    result.add(TreePathHandle.create(new TreePath(topLevel, it), ci));
                }
            }
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:Imports.java

示例5: visitCompilationUnit

import com.sun.source.tree.CompilationUnitTree; //导入方法依赖的package包/类
@Override
public Void visitCompilationUnit(CompilationUnitTree tree, Void ignore) {
    if (tree.getPackageName() != null) {
        visitDecl(tree, null);
    }
    return super.visitCompilationUnit(tree, ignore);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:DocLint.java

示例6: enclosingPackage

import com.sun.source.tree.CompilationUnitTree; //导入方法依赖的package包/类
/**Returns name of package in which the current file is located. Default package
 * is represented by an empty string.
 *
 * @return the name of the enclosing package
 */
public @NonNull String enclosingPackage() {
    CompilationUnitTree cut = ctx.getInfo().getCompilationUnit();

    return cut.getPackageName() != null ? cut.getPackageName().toString() : "";
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:Context.java

示例7: performRewrite

import com.sun.source.tree.CompilationUnitTree; //导入方法依赖的package包/类
@Override protected void performRewrite(JavaFix.TransformationContext ctx) throws Exception {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath treePath = ctx.getPath();
            TreeMaker make = wc.getTreeMaker();
            if (treePath.getLeaf().getKind() == Kind.METHOD_INVOCATION) {
                MethodInvocationTree mit = (MethodInvocationTree) treePath.getLeaf();
                CompilationUnitTree cut = wc.getCompilationUnit();
                boolean imported = false;
                String importBundleStar = cut.getPackageName() + ".Bundle.*";
                for (ImportTree it : cut.getImports()) {
                    if (it.isStatic() && it.getQualifiedIdentifier().toString().equals(importBundleStar)) {
                        imported = true;
                        break;
                    }
                }
                if (!imported) {
                    wc.rewrite(cut, make.addCompUnitImport(cut, make.Import(make.Identifier(importBundleStar), true)));
                }
                List<? extends ExpressionTree> args = mit.getArguments();
                List<? extends ExpressionTree> params;
                if (args.size() == 3 && args.get(2).getKind() == Kind.NEW_ARRAY) {
                    params = ((NewArrayTree) args.get(2)).getInitializers();
                } else {
                    params = args.subList(2, args.size());
                }
                wc.rewrite(mit, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.Identifier(toIdentifier(key)), params));
            } // else annotation value, nothing to change
            if (!isAlreadyRegistered) {
                EditableProperties ep = new EditableProperties(true);
                InputStream is = ctx.getResourceContent(bundleProperties);
                try {
                    ep.load(is);
                } finally {
                    is.close();
                }
                List<ExpressionTree> lines = new ArrayList<ExpressionTree>();
                for (String comment : ep.getComment(key)) {
                    lines.add(make.Literal(comment));
                }
                lines.add(make.Literal(key + '=' + ep.remove(key)));
                TypeElement nbBundleMessages = wc.getElements().getTypeElement("org.openide.util.NbBundle.Messages");
                if (nbBundleMessages == null) {
                    throw new IllegalArgumentException("cannot resolve org.openide.util.NbBundle.Messages");
                }
                GeneratorUtilities gu = GeneratorUtilities.get(wc);
                Tree enclosing = findEnclosingElement(wc, treePath);
                Tree modifiers;
                Tree nueModifiers;
                ExpressionTree[] linesA = lines.toArray(new ExpressionTree[lines.size()]);
                switch (enclosing.getKind()) {
                case METHOD:
                    modifiers = wc.resolveRewriteTarget(((MethodTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                case VARIABLE:
                    modifiers = wc.resolveRewriteTarget(((VariableTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                case COMPILATION_UNIT:
                    modifiers = wc.resolveRewriteTarget(enclosing);
                    nueModifiers = gu.appendToAnnotationValue((CompilationUnitTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                default:
                    modifiers = wc.resolveRewriteTarget(((ClassTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                }
                wc.rewrite(modifiers, nueModifiers);
            // XXX remove NbBundle import if now unused
            OutputStream os = ctx.getResourceOutput(bundleProperties);
            try {
                ep.store(os);
            } finally {
                os.close();
            }
        }
    // XXX after JavaFix rewrite, Savable.save (on DataObject.find(src)) no longer works (JG13 again)
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:78,代码来源:UseNbBundleMessages.java

示例8: visitCompilationUnit

import com.sun.source.tree.CompilationUnitTree; //导入方法依赖的package包/类
@Override
public Void visitCompilationUnit(CompilationUnitTree node, Void unused) {
    boolean first = true;
    if (node.getPackageName() != null) {
        markForPartialFormat();
        visitPackage(node.getPackageName(), node.getPackageAnnotations());
        builder.forcedBreak();
        first = false;
    }
    if (!node.getImports().isEmpty()) {
        if (!first) {
            builder.blankLineWanted(BlankLineWanted.YES);
        }
        for (ImportTree importDeclaration : node.getImports()) {
            markForPartialFormat();
            builder.blankLineWanted(PRESERVE);
            scan(importDeclaration, null);
            builder.forcedBreak();
        }
        first = false;
    }
    dropEmptyDeclarations();
    for (Tree type : node.getTypeDecls()) {
        if (type.getKind() == Tree.Kind.IMPORT) {
            // javac treats extra semicolons in the import list as type declarations
            // TODO(cushon): remove this if https://bugs.openjdk.java.net/browse/JDK-8027682 is fixed
            continue;
        }
        if (!first) {
            builder.blankLineWanted(BlankLineWanted.YES);
        }
        markForPartialFormat();
        scan(type, null);
        builder.forcedBreak();
        first = false;
        dropEmptyDeclarations();
    }
    // set a partial format marker at EOF to make sure we can format the entire file
    markForPartialFormat();
    return null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:42,代码来源:JavaInputAstVisitor.java


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