Java Code Examples for com.sun.tools.javac.util.ListBuffer#addAll()

The following examples show how to use com.sun.tools.javac.util.ListBuffer#addAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void completeAutomaticModule(ModuleSymbol msym) throws CompletionFailure {
    ListBuffer<Directive> directives = new ListBuffer<>();

    directives.addAll(msym.directives);

    ListBuffer<RequiresDirective> requires = new ListBuffer<>();

    for (ModuleSymbol ms : allModules()) {
        if (ms == syms.unnamedModule || ms == msym)
            continue;
        Set<RequiresFlag> flags = (ms.flags_field & Flags.AUTOMATIC_MODULE) != 0 ?
                EnumSet.of(RequiresFlag.TRANSITIVE) : EnumSet.noneOf(RequiresFlag.class);
        RequiresDirective d = new RequiresDirective(ms, flags);
        directives.add(d);
        requires.add(d);
    }

    RequiresDirective requiresUnnamed = new RequiresDirective(syms.unnamedModule);
    directives.add(requiresUnnamed);
    requires.add(requiresUnnamed);

    msym.requires = requires.toList();
    msym.directives = directives.toList();
}
 
Example 2
private void completeAutomaticModule(ModuleSymbol msym) throws CompletionFailure {
    ListBuffer<Directive> directives = new ListBuffer<>();

    directives.addAll(msym.directives);

    ListBuffer<RequiresDirective> requires = new ListBuffer<>();

    for (ModuleSymbol ms : allModules()) {
        if (ms == syms.unnamedModule || ms == msym)
            continue;
        Set<RequiresFlag> flags = (ms.flags_field & Flags.AUTOMATIC_MODULE) != 0 ?
                EnumSet.of(RequiresFlag.TRANSITIVE) : EnumSet.noneOf(RequiresFlag.class);
        RequiresDirective d = new RequiresDirective(ms, flags);
        directives.add(d);
        requires.add(d);
    }

    RequiresDirective requiresUnnamed = new RequiresDirective(syms.unnamedModule);
    directives.add(requiresUnnamed);
    requires.add(requiresUnnamed);

    msym.requires = requires.toList();
    msym.directives = directives.toList();
}
 
Example 3
@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);
}
 
Example 4
@Override @DefinedBy(Api.COMPILER_TREE)
public DCDocComment newDocCommentTree(List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
    ListBuffer<DCTree> lb = new ListBuffer<>();
    lb.addAll(cast(fullBody));
    List<DCTree> fBody = lb.toList();

    // A dummy comment to keep the diagnostics logic happy.
    Comment c = new Comment() {
        @Override
        public String getText() {
            return null;
        }

        @Override
        public int getSourcePos(int index) {
            return Position.NOPOS;
        }

        @Override
        public CommentStyle getStyle() {
            return CommentStyle.JAVADOC;
        }

        @Override
        public boolean isDeprecated() {
            return false;
        }
    };
    Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody);
    DCDocComment tree = new DCDocComment(c, fBody, pair.fst, pair.snd, cast(tags));
    return tree;
}
 
Example 5
/**
 * Performs speculative attribution of a lambda body and returns the speculative lambda tree,
 * in the absence of a target-type. Since {@link Attr#visitLambda(JCLambda)} cannot type-check
 * lambda bodies w/o a suitable target-type, this routine 'unrolls' the lambda by turning it
 * into a regular block, speculatively type-checks the block and then puts back the pieces.
 */
JCLambda attribSpeculativeLambda(JCLambda that, Env<AttrContext> env, ResultInfo resultInfo) {
    ListBuffer<JCStatement> stats = new ListBuffer<>();
    stats.addAll(that.params);
    if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) {
        stats.add(make.Return((JCExpression)that.body));
    } else {
        stats.add((JCBlock)that.body);
    }
    JCBlock lambdaBlock = make.Block(0, stats.toList());
    Env<AttrContext> localEnv = attr.lambdaEnv(that, env);
    try {
        localEnv.info.returnResult = resultInfo;
        JCBlock speculativeTree = (JCBlock)attribSpeculative(lambdaBlock, localEnv, resultInfo);
        List<JCVariableDecl> args = StreamSupport.stream(speculativeTree.getStatements())
                .filter(s -> s.hasTag(Tag.VARDEF))
                .map(t -> (JCVariableDecl)t)
                .collect(List.collector());
        JCTree lambdaBody = speculativeTree.getStatements().last();
        if (lambdaBody.hasTag(Tag.RETURN)) {
            lambdaBody = ((JCReturn)lambdaBody).expr;
        }
        JCLambda speculativeLambda = make.Lambda(args, lambdaBody);
        attr.preFlow(speculativeLambda);
        flow.analyzeLambda(env, speculativeLambda, make, false);
        return speculativeLambda;
    } finally {
        localEnv.info.scope.leave();
    }
}
 
Example 6
@Override @DefinedBy(Api.COMPILER_TREE)
public DCDocComment newDocCommentTree(List<? extends DocTree> fullBody, List<? extends DocTree> tags) {
    ListBuffer<DCTree> lb = new ListBuffer<>();
    lb.addAll(cast(fullBody));
    List<DCTree> fBody = lb.toList();

    // A dummy comment to keep the diagnostics logic happy.
    Comment c = new Comment() {
        @Override
        public String getText() {
            return null;
        }

        @Override
        public int getSourcePos(int index) {
            return Position.NOPOS;
        }

        @Override
        public CommentStyle getStyle() {
            return CommentStyle.JAVADOC;
        }

        @Override
        public boolean isDeprecated() {
            return false;
        }
    };
    Pair<List<DCTree>, List<DCTree>> pair = splitBody(fullBody);
    DCDocComment tree = new DCDocComment(c, fBody, pair.fst, pair.snd, cast(tags));
    return tree;
}
 
Example 7
Source Project: nomulus   File: JavadocWrapper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Obtains a Javadoc root document object for the specified source path and package/Java names.
 * If the source path is null, then the working directory is assumed as the source path.
 *
 * <p>If a list of package names is provided, then Javadoc will run on these packages and all
 * their subpackages, based out of the specified source path.
 *
 * <p>If a list of file names is provided, then Javadoc will also run on these Java source files.
 * The specified source path is not considered in this case.
 *
 * @see <a href="http://relation.to/12969.lace">Testing Java doclets</a>
 * @see <a href="http://www.docjar.com/docs/api/com/sun/tools/javadoc/JavadocTool.html">JavadocTool</a>
 */
private static RootDoc createRootDoc(
    @Nullable String sourcePath,
    Collection<String> packageNames,
    Collection<String> fileNames,
    long visibilityMask,
    boolean quiet) throws IOException {
  // Create a context to hold settings for Javadoc.
  Context context = new Context();

  // Redirect Javadoc stdout/stderr to null writers, since otherwise the Java compiler
  // issues lots of errors for classes that are imported and visible to blaze but not
  // visible locally to the compiler.
  // TODO(b/19124943): Find a way to ignore those errors so we can show real ones?
  Messager.preRegister(
      context,
      JavadocWrapper.class.getName(),
      new PrintWriter(CharStreams.nullWriter()),     // For errors.
      new PrintWriter(CharStreams.nullWriter()),     // For warnings.
      new PrintWriter(CharStreams.nullWriter()));    // For notices.

  // Set source path option for Javadoc.
  try (JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8)) {
    List<File> sourcePathFiles = new ArrayList<>();
    if (sourcePath != null) {
      for (String sourcePathEntry : Splitter.on(':').split(sourcePath)) {
        sourcePathFiles.add(new File(sourcePathEntry));
      }
    }
    fileManager.setLocation(StandardLocation.SOURCE_PATH, sourcePathFiles);

    // Create an instance of Javadoc.
    JavadocTool javadocTool = JavadocTool.make0(context);

    // Convert the package and file lists to a format Javadoc can understand.
    ListBuffer<String> subPackages = new ListBuffer<>();
    subPackages.addAll(packageNames);
    ListBuffer<String> javaNames = new ListBuffer<>();
    javaNames.addAll(fileNames);

    // Invoke Javadoc and ask it for a RootDoc containing the specified packages.
    return javadocTool.getRootDocImpl(
        Locale.US.toString(),                    // Javadoc comment locale
        UTF_8.name(),                            // Source character encoding
        new ModifierFilter(visibilityMask),      // Element visibility filter
        javaNames.toList(),                      // Included Java file names
        com.sun.tools.javac.util.List.nil(),     // Doclet options
        com.sun.tools.javac.util.List.nil(),     // Source files
        false,                                   // Don't use BreakIterator
        subPackages.toList(),                    // Included sub-package names
        com.sun.tools.javac.util.List.nil(),     // Excluded package names
        false,                                   // Read source files, not classes
        false,                                   // Don't run legacy doclet
        quiet);                                  // If asked, run Javadoc quietly
  }
}