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

The following examples show how to use com.sun.tools.javac.util.ListBuffer#append() . 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
Source File: JavacFileManager.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public ClassLoader getClassLoader(Location location) {
    nullCheck(location);
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return null;
    ListBuffer<URL> lb = new ListBuffer<URL>();
    for (File f: path) {
        try {
            lb.append(f.toURI().toURL());
        } catch (MalformedURLException e) {
            throw new AssertionError(e);
        }
    }

    return getClassLoader(lb.toArray(new URL[lb.size()]));
}
 
Example 2
Source File: HandleBuilder.java    From EasyMPermission with MIT License 6 votes vote down vote up
private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JCTree source) {
	JavacTreeMaker maker = type.getTreeMaker();
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	
	for (BuilderFieldData bfd : builderFields) {
		if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
			bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, type, source, statements);
		}
	}
	
	statements.append(maker.Exec(maker.Assign(maker.Select(maker.Ident(type.toName("this")), type.toName("$lombokUnclean")), maker.Literal(CTC_BOOLEAN, false))));
	JCBlock body = maker.Block(0, statements.toList());
	return maker.MethodDef(maker.Modifiers(Flags.PUBLIC), type.toName("$lombokClean"), maker.Type(Javac.createVoidType(maker, CTC_VOID)), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null);
	/*
	 * 		if (shouldReturnThis) {
		methodType = cloneSelfType(field);
	}
	
	if (methodType == null) {
		//WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6.
		methodType = treeMaker.Type(Javac.createVoidType(treeMaker, CTC_VOID));
		shouldReturnThis = false;
	}

	 */
}
 
Example 3
Source File: TypeAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void locateNestedTypes(Type type, TypeAnnotationPosition p) {
    // The number of "steps" to get from the full type to the
    // left-most outer type.
    ListBuffer<TypePathEntry> depth = new ListBuffer<>();

    Type encl = type.getEnclosingType();
    while (encl != null &&
            encl.getKind() != TypeKind.NONE &&
            encl.getKind() != TypeKind.ERROR) {
        depth = depth.append(TypePathEntry.INNER_TYPE);
        encl = encl.getEnclosingType();
    }
    if (depth.nonEmpty()) {
        p.location = p.location.prependList(depth.toList());
    }
}
 
Example 4
Source File: CommandLine.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Process Win32-style command files for the specified command line
 * arguments and return the resulting arguments. A command file argument
 * is of the form '@file' where 'file' is the name of the file whose
 * contents are to be parsed for additional arguments. The contents of
 * the command file are parsed using StreamTokenizer and the original
 * '@file' argument replaced with the resulting tokens. Recursive command
 * files are not supported. The '@' character itself can be quoted with
 * the sequence '@@'.
 */
public static String[] parse(String[] args)
        throws IOException {
    ListBuffer<String> newArgs = new ListBuffer<String>();
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.length() > 1 && arg.charAt(0) == '@') {
            arg = arg.substring(1);
            if (arg.charAt(0) == '@') {
                newArgs.append(arg);
            } else {
                loadCmdFile(arg, newArgs);
            }
        } else {
            newArgs.append(arg);
        }
    }
    return newArgs.toList().toArray(new String[newArgs.length()]);
}
 
Example 5
Source File: AnnoConstruct.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private Attribute.Compound[] unpackContained(Attribute.Compound container) {
    // Pack them in an array
    Attribute[] contained0 = null;
    if (container != null)
        contained0 = unpackAttributes(container);
    ListBuffer<Attribute.Compound> compounds = new ListBuffer<>();
    if (contained0 != null) {
        for (Attribute a : contained0)
            if (a instanceof Attribute.Compound)
                compounds = compounds.append((Attribute.Compound)a);
    }
    return compounds.toArray(new Attribute.Compound[compounds.size()]);
}
 
Example 6
Source File: Comment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return param tags in this comment.  If typeParams is true
 * include only type param tags, otherwise include only ordinary
 * param tags.
 */
private ParamTag[] paramTags(boolean typeParams) {
    ListBuffer<ParamTag> found = new ListBuffer<>();
    for (Tag next : tagList) {
        if (next instanceof ParamTag) {
            ParamTag p = (ParamTag)next;
            if (typeParams == p.isTypeParameter()) {
                found.append(p);
            }
        }
    }
    return found.toArray(new ParamTag[found.length()]);
}
 
Example 7
Source File: TreeCopier.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public <T extends JCTree> List<T> copy(List<T> trees, P p) {
    if (trees == null)
        return null;
    ListBuffer<T> lb = new ListBuffer<T>();
    for (T tree: trees)
        lb.append(copy(tree, p));
    return lb.toList();
}
 
Example 8
Source File: InferenceContext.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
List<Type> asInstTypes(List<Type> ts) {
    ListBuffer<Type> buf = new ListBuffer<>();
    for (Type t : ts) {
        buf.append(asInstType(t));
    }
    return buf.toList();
}
 
Example 9
Source File: TreeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MemberReferenceTree MemberReference(ReferenceMode refMode, CharSequence name, ExpressionTree expression, List<? extends ExpressionTree> typeArguments) {
    ListBuffer<JCExpression> targs;
    
    if (typeArguments != null) {
        targs = new ListBuffer<JCExpression>();
        for (ExpressionTree t : typeArguments)
            targs.append((JCExpression)t);
    } else {
        targs = null;
    }
    
    return make.at(NOPOS).Reference(refMode, names.fromString(name.toString()), (JCExpression) expression, targs != null ? targs.toList() : null);
}
 
Example 10
Source File: ExecutableMemberDocImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return exceptions this method or constructor throws.
 *
 * @return an array of ClassDoc[] representing the exceptions
 * thrown by this method.
 */
public ClassDoc[] thrownExceptions() {
    ListBuffer<ClassDocImpl> l = new ListBuffer<ClassDocImpl>();
    for (Type ex : sym.type.getThrownTypes()) {
        ex = env.types.erasure(ex);
        //### Will these casts succeed in the face of static semantic
        //### errors in the documented code?
        ClassDocImpl cdi = env.getClassDoc((ClassSymbol)ex.tsym);
        if (cdi != null) l.append(cdi);
    }
    return l.toArray(new ClassDocImpl[l.length()]);
}
 
Example 11
Source File: JavacGuavaSingularizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName) {
	JavacTreeMaker maker = builderType.getTreeMaker();
	List<JCExpression> jceBlank = List.nil();
	boolean mapMode = isMap();
	
	JCExpression varType = chainDotsString(builderType, data.getTargetFqn());
	varType = addTypeArgs(mapMode ? 2 : 1, false, builderType, varType, data.getTypeArgs(), source);
	
	JCExpression empty; {
		//ImmutableX.of()
		JCExpression emptyMethod = chainDots(builderType, "com", "google", "common", "collect", getSimpleTargetTypeName(data), "of");
		List<JCExpression> invokeTypeArgs = createTypeArgs(mapMode ? 2 : 1, false, builderType, data.getTypeArgs(), source);
		empty = maker.Apply(invokeTypeArgs, emptyMethod, jceBlank);
	}
	
	JCExpression invokeBuild; {
		//this.pluralName.build();
		invokeBuild = maker.Apply(jceBlank, chainDots(builderType, "this", data.getPluralName().toString(), "build"), jceBlank);
	}
	
	JCExpression isNull; {
		//this.pluralName == null
		isNull = maker.Binary(CTC_EQUAL, maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()), maker.Literal(CTC_BOT, null));
	}
	
	JCExpression init = maker.Conditional(isNull, empty, invokeBuild); // this.pluralName == null ? ImmutableX.of() : this.pluralName.build()
	
	JCStatement jcs = maker.VarDef(maker.Modifiers(0), data.getPluralName(), varType, init);
	statements.append(jcs);
}
 
Example 12
Source File: Printer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * * Get a localized string representation for all the symbols in the input list.
 *
 * @param ts symbols to be displayed
 * @param locale the locale in which the string is to be rendered
 * @return localized string representation
 */
public String visitSymbols(List<Symbol> ts, Locale locale) {
    ListBuffer<String> sbuf = new ListBuffer<>();
    for (Symbol t : ts) {
        sbuf.append(visit(t, locale));
    }
    return sbuf.toList().toString();
}
 
Example 13
Source File: TreeCopier.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public <T extends JCTree> List<T> copy(List<T> trees, P p) {
    if (trees == null)
        return null;
    ListBuffer<T> lb = new ListBuffer<T>();
    for (T tree: trees)
        lb.append(copy(tree, p));
    return lb.toList();
}
 
Example 14
Source File: InferenceContext.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
final List<Type> asUndetVars(List<Type> ts) {
    ListBuffer<Type> buf = new ListBuffer<>();
    for (Type t : ts) {
        buf.append(asUndetVar(t));
    }
    return buf.toList();
}
 
Example 15
Source File: RootDocImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize classes information. Those classes are input from
 * command line.
 *
 * @param env the compilation environment
 * @param classes a list of ClassDeclaration
 */
private void setClasses(DocEnv env, List<JCClassDecl> classes) {
    ListBuffer<ClassDocImpl> result = new ListBuffer<ClassDocImpl>();
    for (JCClassDecl def : classes) {
        //### Do we want modifier check here?
        if (env.shouldDocument(def.sym)) {
            ClassDocImpl cd = env.getClassDoc(def.sym);
            if (cd != null) {
                cd.isIncluded = true;
                result.append(cd);
            } //else System.out.println(" (classdoc is null)");//DEBUG
        } //else System.out.println(" (env.shouldDocument() returned false)");//DEBUG
    }
    cmdLineClasses = result.toList();
}
 
Example 16
Source File: ClassDocImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return interfaces implemented by this class or interfaces
 * extended by this interface.
 *
 * @return An array of ClassDocImpl representing the interfaces.
 * Return an empty array if there are no interfaces.
 */
public ClassDoc[] interfaces() {
    ListBuffer<ClassDocImpl> ta = new ListBuffer<>();
    for (Type t : env.types.interfaces(type)) {
        ta.append(env.getClassDoc((ClassSymbol)t.tsym));
    }
    //### Cache ta here?
    return ta.toArray(new ClassDocImpl[ta.length()]);
}
 
Example 17
Source File: ExecutableMemberDocImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return exceptions this method or constructor throws.
 *
 * @return an array of ClassDoc[] representing the exceptions
 * thrown by this method.
 */
public ClassDoc[] thrownExceptions() {
    ListBuffer<ClassDocImpl> l = new ListBuffer<>();
    for (Type ex : sym.type.getThrownTypes()) {
        ex = env.types.erasure(ex);
        //### Will these casts succeed in the face of static semantic
        //### errors in the documented code?
        ClassDocImpl cdi = env.getClassDoc((ClassSymbol)ex.tsym);
        if (cdi != null) l.append(cdi);
    }
    return l.toArray(new ClassDocImpl[l.length()]);
}
 
Example 18
Source File: DeferredLintHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**Associate the given logger with the current position as set by {@link #setPos(DiagnosticPosition) }.
 * Will be invoked when {@link #flush(DiagnosticPosition) } will be invoked with the same position.
 * <br>
 * Will invoke the logger synchronously if {@link #immediate() } was called
 * instead of {@link #setPos(DiagnosticPosition) }.
 */
public void report(LintLogger logger) {
    if (currentPos == IMMEDIATE_POSITION) {
        logger.report();
    } else {
        ListBuffer<LintLogger> loggers = loggersQueue.get(currentPos);
        if (loggers == null) {
            loggersQueue.put(currentPos, loggers = new ListBuffer<>());
        }
        loggers.append(logger);
    }
}
 
Example 19
Source File: ClassDocImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return interfaces implemented by this class or interfaces
 * extended by this interface.
 *
 * @return An array of ClassDocImpl representing the interfaces.
 * Return an empty array if there are no interfaces.
 */
public ClassDoc[] interfaces() {
    ListBuffer<ClassDocImpl> ta = new ListBuffer<ClassDocImpl>();
    for (Type t : env.types.interfaces(type)) {
        ta.append(env.getClassDoc((ClassSymbol)t.tsym));
    }
    //### Cache ta here?
    return ta.toArray(new ClassDocImpl[ta.length()]);
}
 
Example 20
Source File: JavacFileManager.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
    ListBuffer<File> files = new ListBuffer<File>();
    for (String name : names)
        files.append(new File(nullCheck(name)));
    return getJavaFileObjectsFromFiles(files.toList());
}