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


Java JCClassDecl类代码示例

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


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

示例1: makeClassDoc

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
@Override
protected void makeClassDoc(ClassSymbol clazz, TreePath treePath) {
    if (clazz.type.hasTag(TypeTag.UNKNOWN)) {
        return;
    }
    ClassDocImpl result = classMap.get(clazz);
    if (result != null) {
        if (treePath != null) setTreePath(result, treePath);
        return;
    }
    if (isAnnotationType((JCClassDecl)treePath.getLeaf())) {	// flags of clazz may not yet be set
        result = new JavadocAnnotation(this, clazz, treePath);
    } else {
        result = new JavadocClass(this, clazz, treePath);
    }
    classMap.put(clazz, result);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JavadocEnv.java

示例2: visitClassDef

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
@Override
public void visitClassDef(JCClassDecl tree) {
    TypeSymbol currentClassPrev = currentClass;
    currentClass = tree.sym;
    List<Pair<TypeSymbol, Symbol>> prevOuterThisStack = outerThisStack;
    try {
        if (currentClass != null) {
            if (currentClass.hasOuterInstance())
                outerThisDef(currentClass);
            super.visitClassDef(tree);
        }
    } finally {
        outerThisStack = prevOuterThisStack;
        currentClass = currentClassPrev;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:PostFlowAnalysis.java

示例3: test223701

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
public void test223701() throws Exception {
    File testFile = new File(work, "Test.java");
    final String origin =
                   "/*a*/\npackage test;\n" +
                   "class Test {\n" +
                   "}";
    TestUtilities.copyStringToFile(testFile, origin);
    JavaSource src = getJavaSource(testFile);

    Task<WorkingCopy> task = new Task<WorkingCopy>() {
        public void run(final WorkingCopy workingCopy) throws Exception {
            workingCopy.toPhase(JavaSource.Phase.PARSED);
            ClassTree ct = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
            ((JCClassDecl) ct).pos = 1;//"great" positions apparently produced by some code-generating tools (read: Lombok)
            GeneratorUtilities.get(workingCopy).importComments(ct, workingCopy.getCompilationUnit());
        }
    };
    src.runModificationTask(task);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:CommentCollectorTest.java

示例4: dumpSymFile

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
private void dumpSymFile(
        @NonNull final JavaFileManager jfm,
        @NonNull final JavacTaskImpl jti,
        @NullAllowed final ClassSymbol cs,
        @NonNull final Set<File> alreadyCreated,
        @NonNull final File classes,
        @NonNull final HashMap<ClassSymbol, JCClassDecl> syms2trees) throws IOException {
    if (cs == null) {
        //ClassDecl has no symbol because compilation was cancelled
        //by low memory before ENTER done.
        return;
    }        
    JavaFileObject file = jfm.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT,
            cs.flatname.toString(), JavaFileObject.Kind.CLASS, cs.sourcefile);
    if (file instanceof FileObjects.FileBase && !alreadyCreated.contains(((FileObjects.FileBase)file).getFile())) {
        TreeLoader.dumpSymFile(jfm, jti, cs, classes, syms2trees);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:MultiPassCompileWorker.java

示例5: printSource

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
/**
 * Emit plain Java source for a class.
 *
 * @param env  The attribution environment of the outermost class
 *             containing this class.
 * @param cdef The class definition to be printed.
 */
JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
    JavaFileObject outFile
            = fileManager.getJavaFileForOutput(CLASS_OUTPUT,
            cdef.sym.flatname.toString(),
            JavaFileObject.Kind.SOURCE,
            null);
    if (inputFiles.contains(outFile)) {
        log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile);
        return null;
    } else {
        BufferedWriter out = new BufferedWriter(outFile.openWriter());
        try {
            new Pretty(out, true).printUnit(env.toplevel, cdef);
            if (verbose)
                log.printVerbose("wrote.file", outFile);
        } finally {
            out.close();
        }
        return outFile;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:29,代码来源:JavaCompiler.java

示例6: printSource

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
/** Emit plain Java source for a class.
 *  @param env    The attribution environment of the outermost class
 *                containing this class.
 *  @param cdef   The class definition to be printed.
 */
JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
    JavaFileObject outFile
       = fileManager.getJavaFileForOutput(CLASS_OUTPUT,
                                           cdef.sym.flatname.toString(),
                                           JavaFileObject.Kind.SOURCE,
                                           null);
    if (inputFiles.contains(outFile)) {
        log.error(cdef.pos(), Errors.SourceCantOverwriteInputFile(outFile));
        return null;
    } else {
        try (BufferedWriter out = new BufferedWriter(outFile.openWriter())) {
            new Pretty(out, true).printUnit(env.toplevel, cdef);
            if (verbose)
                log.printVerbose("wrote.file", outFile);
        }
        return outFile;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:JavaCompiler.java

示例7: getElement

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public Symbol getElement(TreePath path) {
    JCTree tree = (JCTree) path.getLeaf();
    Symbol sym = TreeInfo.symbolFor(tree);
    if (sym == null) {
        for (TreePath p = path; p != null; p = p.getParentPath()) {
            JCTree t = (JCTree) p.getLeaf();
            if (t.hasTag(JCTree.Tag.CLASSDEF)) {
                JCClassDecl ct = (JCClassDecl) t;
                if (ct.sym != null) {
                    if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
                        attr.attribClass(ct.pos(), ct.sym);
                        sym = TreeInfo.symbolFor(tree);
                    }
                    break;
                }
            }
        }
    }
    return sym;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:JavacTrees.java

示例8: handleFlowResults

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
private void handleFlowResults(Queue<Env<AttrContext>> queue, ListBuffer<Element> elems) {
    for (Env<AttrContext> env: queue) {
        switch (env.tree.getTag()) {
            case CLASSDEF:
                JCClassDecl cdef = (JCClassDecl) env.tree;
                if (cdef.sym != null)
                    elems.append(cdef.sym);
                break;
            case MODULEDEF:
                JCModuleDecl mod = (JCModuleDecl) env.tree;
                if (mod.sym != null)
                    elems.append(mod.sym);
                break;
            case PACKAGEDEF:
                JCCompilationUnit unit = env.toplevel;
                if (unit.packge != null)
                    elems.append(unit.packge);
                break;
        }
    }
    genList.addAll(queue);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:JavacTaskImpl.java

示例9: visitClassDef

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
@Override
public void visitClassDef(JCClassDecl tree) {
    if ((tree.mods.flags & (INTERFACE | ENUM)) == 0 &&
            !tree.getMembers().stream()
            .anyMatch(t -> t.getKind() == Tree.Kind.METHOD &&
            ((MethodTree) t).getName() == tree.name.table.names.init)) {
        // Generate a default constructor, since
        // this is a regular class and there are no constructors
        ListBuffer<JCTree> ndefs = new ListBuffer<>();
        ndefs.addAll(tree.defs);
        ndefs.add(make.MethodDef(make.Modifiers(PUBLIC),
                tree.name.table.names.init,
                null, List.nil(), List.nil(), List.nil(),
                resolutionExceptionBlock(), null));
        tree.defs = ndefs.toList();
    }
    super.visitClassDef(tree);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Corraller.java

示例10: printSource

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
/** Emit plain Java source for a class.
 *  @param env    The attribution environment of the outermost class
 *                containing this class.
 *  @param cdef   The class definition to be printed.
 */
JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
    JavaFileObject outFile
       = fileManager.getJavaFileForOutput(CLASS_OUTPUT,
                                           cdef.sym.flatname.toString(),
                                           JavaFileObject.Kind.SOURCE,
                                           null);
    if (inputFiles.contains(outFile)) {
        log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile);
        return null;
    } else {
        try (BufferedWriter out = new BufferedWriter(outFile.openWriter())) {
            new Pretty(out, true).printUnit(env.toplevel, cdef);
            if (verbose)
                log.printVerbose("wrote.file", outFile);
        }
        return outFile;
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:24,代码来源:JavaCompiler.java

示例11: getElement

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public Symbol getElement(TreePath path) {
    JCTree tree = (JCTree) path.getLeaf();
    Symbol sym = TreeInfo.symbolFor(tree);
    if (sym == null) {
        if (TreeInfo.isDeclaration(tree)) {
            for (TreePath p = path; p != null; p = p.getParentPath()) {
                JCTree t = (JCTree) p.getLeaf();
                if (t.hasTag(JCTree.Tag.CLASSDEF)) {
                    JCClassDecl ct = (JCClassDecl) t;
                    if (ct.sym != null) {
                        if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
                            attr.attribClass(ct.pos(), ct.sym);
                            sym = TreeInfo.symbolFor(tree);
                        }
                        break;
                    }
                }
            }
        }
    }
    return sym;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:24,代码来源:JavacTrees.java

示例12: process

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
@Override
public void process(Element element) {
    if (element instanceof TypeElement) {
        String qualifiedName = ((TypeElement)element).getQualifiedName().toString();
        String exclusionRule = getExclusionRule(qualifiedName);
        if (exclusionRule != null) {
            Logger.note(getClass(), "process", "not instrumenting class '" + qualifiedName + "', '"+exclusionRule+"' is excluded");
            return;
        }
    }

    JCClassDecl klass = toJCClassDecl(element);
    final String className = klass.getSimpleName().toString();
    Logger.note(getClass(), "process", "instrumenting class: " + className);

    // NOTE(snorbi07): IMPORTANT: this only does the processing of TOP LEVEL classes (class source files)!
    // Inner classes are part of the parent classes source tree and processed as such.
    processClass(klass);
}
 
开发者ID:GoodGrind,项目名称:ghostwriter,代码行数:20,代码来源:Javac7Instrumenter.java

示例13: toJCClassDecl

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
protected JCClassDecl toJCClassDecl(Element element) {
     /*
* Cast the JSR269 tree node to its compiler internal type. The
* difference between JSR269 tree nodes and internal tree node is, that
* JSR269 stops at method level, whereas internally all AST elements are
* accessible. We need full access in order to inject entering/leaving
* statements.
*/
     JCTree tree = (JCTree) trees.getTree(element);
     if (!(tree instanceof JCClassDecl)) {
         throw new IllegalArgumentException("Expected type: "
                 + JCClassDecl.class.getSimpleName() + ". Got: "
                 + Element.class.getSimpleName());
     }
     JCClassDecl klass = (JCClassDecl) tree;

     return klass;
 }
 
开发者ID:GoodGrind,项目名称:ghostwriter,代码行数:19,代码来源:Javac7Instrumenter.java

示例14: buildTree

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
/** {@inheritDoc} */
@Override protected JavacNode buildTree(JCTree node, Kind kind) {
	switch (kind) {
	case COMPILATION_UNIT:
		return buildCompilationUnit((JCCompilationUnit) node);
	case TYPE:
		return buildType((JCClassDecl) node);
	case FIELD:
		return buildField((JCVariableDecl) node);
	case INITIALIZER:
		return buildInitializer((JCBlock) node);
	case METHOD:
		return buildMethod((JCMethodDecl) node);
	case ARGUMENT:
		return buildLocalVar((JCVariableDecl) node, kind);
	case LOCAL:
		return buildLocalVar((JCVariableDecl) node, kind);
	case STATEMENT:
		return buildStatementOrExpression(node);
	case ANNOTATION:
		return buildAnnotation((JCAnnotation) node, false);
	default:
		throw new AssertionError("Did not expect: " + kind);
	}
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:26,代码来源:JavacAST.java

示例15: buildType

import com.sun.tools.javac.tree.JCTree.JCClassDecl; //导入依赖的package包/类
private JavacNode buildType(JCClassDecl type) {
	if (setAndGetAsHandled(type)) return null;
	List<JavacNode> childNodes = new ArrayList<JavacNode>();
	
	for (JCAnnotation annotation : type.mods.annotations) addIfNotNull(childNodes, buildAnnotation(annotation, false));
	for (JCTree def : type.defs) {
		/* A def can be:
		 *   JCClassDecl for inner types
		 *   JCMethodDecl for constructors and methods
		 *   JCVariableDecl for fields
		 *   JCBlock for (static) initializers
		 */
		if (def instanceof JCMethodDecl) addIfNotNull(childNodes, buildMethod((JCMethodDecl)def));
		else if (def instanceof JCClassDecl) addIfNotNull(childNodes, buildType((JCClassDecl)def));
		else if (def instanceof JCVariableDecl) addIfNotNull(childNodes, buildField((JCVariableDecl)def));
		else if (def instanceof JCBlock) addIfNotNull(childNodes, buildInitializer((JCBlock)def));
	}
	
	return putInMap(new JavacNode(this, type, childNodes, Kind.TYPE));
}
 
开发者ID:git03394538,项目名称:lombok-ianchiu,代码行数:21,代码来源:JavacAST.java


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