Java Code Examples for com.sun.tools.javac.util.List#prepend()

The following examples show how to use com.sun.tools.javac.util.List#prepend() . 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: JavacProcessingEnvironment.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void visitClassDef(JCClassDecl node) {
    super.visitClassDef(node);
    // remove generated constructor that may have been added during attribution:
    List<JCTree> beforeConstructor = List.nil();
    List<JCTree> defs = node.defs;
    while (defs.nonEmpty() && !defs.head.hasTag(Tag.METHODDEF)) {
        beforeConstructor = beforeConstructor.prepend(defs.head);
        defs = defs.tail;
    }
    if (defs.nonEmpty() &&
        (((JCMethodDecl) defs.head).mods.flags & Flags.GENERATEDCONSTR) != 0) {
        defs = defs.tail;
        while (beforeConstructor.nonEmpty()) {
            defs = defs.prepend(beforeConstructor.head);
            beforeConstructor = beforeConstructor.tail;
        }
        node.defs = defs;
    }
    if (node.sym != null) {
        node.sym.completer = new ImplicitCompleter(topLevel);
    }
    node.sym = null;
}
 
Example 2
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
    ClassReader reader = ClassReader.instance(context);
    Names names = Names.instance(context);
    List<ClassSymbol> list = List.nil();

    for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
        Name name = names.fromString(entry.getKey());
        JavaFileObject file = entry.getValue();
        if (file.getKind() != JavaFileObject.Kind.CLASS)
            throw new AssertionError(file);
        ClassSymbol cs;
        if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
            Name packageName = Convert.packagePart(name);
            PackageSymbol p = reader.enterPackage(packageName);
            if (p.package_info == null)
                p.package_info = reader.enterClass(Convert.shortName(name), p);
            cs = p.package_info;
            if (cs.classfile == null)
                cs.classfile = file;
        } else
            cs = reader.enterClass(name, file);
        list = list.prepend(cs);
    }
    return list.reverse();
}
 
Example 3
Source File: JavacProcessingEnvironment.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
    ClassReader reader = ClassReader.instance(context);
    Names names = Names.instance(context);
    List<ClassSymbol> list = List.nil();

    for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
        Name name = names.fromString(entry.getKey());
        JavaFileObject file = entry.getValue();
        if (file.getKind() != JavaFileObject.Kind.CLASS)
            throw new AssertionError(file);
        ClassSymbol cs;
        if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
            Name packageName = Convert.packagePart(name);
            PackageSymbol p = reader.enterPackage(packageName);
            if (p.package_info == null)
                p.package_info = reader.enterClass(Convert.shortName(name), p);
            cs = p.package_info;
            if (cs.classfile == null)
                cs.classfile = file;
        } else
            cs = reader.enterClass(name, file);
        list = list.prepend(cs);
    }
    return list.reverse();
}
 
Example 4
Source File: Gen.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
List<Pair<List<Attribute.TypeCompound>, JCExpression>> catchTypesWithAnnotationsFromMulticatch(JCTypeUnion tree, List<TypeCompound> first) {
    List<JCExpression> alts = tree.alternatives;
    List<Pair<List<TypeCompound>, JCExpression>> res = List.of(new Pair<>(first, alts.head));
    alts = alts.tail;

    while(alts != null && alts.head != null) {
        JCExpression alt = alts.head;
        if (alt instanceof JCAnnotatedType) {
            JCAnnotatedType a = (JCAnnotatedType)alt;
            res = res.prepend(new Pair<>(annotate.fromAnnotations(a.annotations), alt));
        } else {
            res = res.prepend(new Pair<>(List.nil(), alt));
        }
        alts = alts.tail;
    }
    return res.reverse();
}
 
Example 5
Source File: JavacProcessingEnvironment.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Enter a set of generated class files. */
private List<ClassSymbol> enterClassFiles(Map<String, JavaFileObject> classFiles) {
    ClassReader reader = ClassReader.instance(context);
    Names names = Names.instance(context);
    List<ClassSymbol> list = List.nil();

    for (Map.Entry<String,JavaFileObject> entry : classFiles.entrySet()) {
        Name name = names.fromString(entry.getKey());
        JavaFileObject file = entry.getValue();
        if (file.getKind() != JavaFileObject.Kind.CLASS)
            throw new AssertionError(file);
        ClassSymbol cs;
        if (isPkgInfo(file, JavaFileObject.Kind.CLASS)) {
            Name packageName = Convert.packagePart(name);
            PackageSymbol p = reader.enterPackage(packageName);
            if (p.package_info == null)
                p.package_info = reader.enterClass(Convert.shortName(name), p);
            cs = p.package_info;
            if (cs.classfile == null)
                cs.classfile = file;
        } else
            cs = reader.enterClass(name, file);
        list = list.prepend(cs);
    }
    return list.reverse();
}
 
Example 6
Source File: SymbolArchive.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
void addZipEntry(ZipEntry entry) {
    String name = entry.getName();
    if (!name.startsWith(prefix.path)) {
        return;
    }
    name = name.substring(prefix.path.length());
    int i = name.lastIndexOf('/');
    RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1));
    String basename = name.substring(i + 1);
    if (basename.length() == 0) {
        return;
    }
    List<String> list = map.get(dirname);
    if (list == null)
        list = List.nil();
    list = list.prepend(basename);
    map.put(dirname, list);
}
 
Example 7
Source File: SymbolArchive.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
void addZipEntry(ZipEntry entry) {
    String name = entry.getName();
    if (!name.startsWith(prefix.path)) {
        return;
    }
    name = name.substring(prefix.path.length());
    int i = name.lastIndexOf('/');
    RelativeDirectory dirname = new RelativeDirectory(name.substring(0, i+1));
    String basename = name.substring(i + 1);
    if (basename.length() == 0) {
        return;
    }
    List<String> list = map.get(dirname);
    if (list == null)
        list = List.nil();
    list = list.prepend(basename);
    map.put(dirname, list);
}
 
Example 8
Source File: JavacProcessingEnvironment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private List<ClassSymbol> getTopLevelClassesFromClasses(List<? extends ClassSymbol> syms) {
    List<ClassSymbol> classes = List.nil();
    for (ClassSymbol sym : syms) {
        if (!isPkgInfo(sym)) {
            classes = classes.prepend(sym);
        }
    }
    return classes.reverse();
}
 
Example 9
Source File: Lower.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** Return a list of trees that load the free variables in given list,
 *  in reverse order.
 *  @param pos          The source code position to be used for the trees.
 *  @param freevars     The list of free variables.
 */
List<JCExpression> loadFreevars(DiagnosticPosition pos, List<VarSymbol> freevars) {
    List<JCExpression> args = List.nil();
    for (List<VarSymbol> l = freevars; l.nonEmpty(); l = l.tail)
        args = args.prepend(loadFreevar(pos, l.head));
    return args;
}
 
Example 10
Source File: Types.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
List<Type> subst(List<Type> ts) {
    if (from.tail == null)
        return ts;
    boolean wild = false;
    if (ts.nonEmpty() && from.nonEmpty()) {
        Type head1 = subst(ts.head);
        List<Type> tail1 = subst(ts.tail);
        if (head1 != ts.head || tail1 != ts.tail)
            return tail1.prepend(head1);
    }
    return ts;
}
 
Example 11
Source File: Types.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Insert a type in a closure
 */
public List<Type> insert(List<Type> cl, Type t) {
    if (cl.isEmpty() || t.tsym.precedes(cl.head.tsym, this)) {
        return cl.prepend(t);
    } else if (cl.head.tsym.precedes(t.tsym, this)) {
        return insert(cl.tail, t).prepend(cl.head);
    } else {
        return cl;
    }
}
 
Example 12
Source File: SymbolMetadata.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private List<Attribute.TypeCompound> getTypePlaceholders() {
    List<Attribute.TypeCompound> res = List.<Attribute.TypeCompound>nil();
    for (Attribute.TypeCompound a : type_attributes) {
        if (a instanceof Placeholder) {
            res = res.prepend(a);
        }
    }
    return res.reverse();
}
 
Example 13
Source File: JavacProcessingEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private List<PackageSymbol> getPackageInfoFilesFromClasses(List<? extends ClassSymbol> syms) {
    List<PackageSymbol> packages = List.nil();
    for (ClassSymbol sym : syms) {
        if (isPkgInfo(sym)) {
            packages = packages.prepend((PackageSymbol) sym.owner);
        }
    }
    return packages.reverse();
}
 
Example 14
Source File: SymbolMetadata.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private List<Attribute.TypeCompound> getTypePlaceholders() {
    List<Attribute.TypeCompound> res = List.<Attribute.TypeCompound>nil();
    for (Attribute.TypeCompound a : type_attributes) {
        if (a instanceof Placeholder) {
            res = res.prepend(a);
        }
    }
    return res.reverse();
}
 
Example 15
Source File: SymbolMetadata.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private List<Attribute.TypeCompound> getTypePlaceholders() {
    List<Attribute.TypeCompound> res = List.<Attribute.TypeCompound>nil();
    for (Attribute.TypeCompound a : type_attributes) {
        if (a instanceof Placeholder) {
            res = res.prepend(a);
        }
    }
    return res.reverse();
}
 
Example 16
Source File: Check.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void checkNonCyclic1(DiagnosticPosition pos, Type t, List<TypeVar> seen) {
    final TypeVar tv;
    if  (t.hasTag(TYPEVAR) && (t.tsym.flags() & UNATTRIBUTED) != 0)
        return;
    if (seen.contains(t)) {
        tv = (TypeVar)t.unannotatedType();
        tv.bound = types.createErrorType(t);
        log.error(pos, "cyclic.inheritance", t);
    } else if (t.hasTag(TYPEVAR)) {
        tv = (TypeVar)t.unannotatedType();
        seen = seen.prepend(tv);
        for (Type b : types.getBounds(tv))
            checkNonCyclic1(pos, b, seen);
    }
}
 
Example 17
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
    List<ClassSymbol> classes = List.nil();
    for (JCCompilationUnit unit : units) {
        for (JCTree node : unit.defs) {
            if (node.hasTag(JCTree.Tag.CLASSDEF)) {
                ClassSymbol sym = ((JCClassDecl) node).sym;
                Assert.checkNonNull(sym);
                classes = classes.prepend(sym);
            }
        }
    }
    return classes.reverse();
}
 
Example 18
Source File: Lower.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
List<JCVariableDecl> freevarDefs(int pos, List<VarSymbol> freevars, Symbol owner,
        long additionalFlags) {
    long flags = FINAL | SYNTHETIC | additionalFlags;
    List<JCVariableDecl> defs = List.nil();
    for (List<VarSymbol> l = freevars; l.nonEmpty(); l = l.tail) {
        VarSymbol v = l.head;
        VarSymbol proxy = new VarSymbol(
            flags, proxyName(v.name), v.erasure(types), owner);
        proxies.enter(proxy);
        JCVariableDecl vd = make.at(pos).VarDef(proxy, null);
        vd.vartype = access(vd.vartype);
        defs = defs.prepend(vd);
    }
    return defs;
}
 
Example 19
Source File: HandleGetter.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCMethodDecl createGetter(long access, JavacNode field, JavacTreeMaker treeMaker, JCTree source, boolean lazy, List<JCAnnotation> onMethod) {
	JCVariableDecl fieldNode = (JCVariableDecl) field.get();
	
	// Remember the type; lazy will change it
	JCExpression methodType = copyType(treeMaker, fieldNode);
	// Generate the methodName; lazy will change the field type
	Name methodName = field.toName(toGetterName(field));
	
	List<JCStatement> statements;
	JCTree toClearOfMarkers = null;
	if (lazy && !inNetbeansEditor(field)) {
		toClearOfMarkers = fieldNode.init;
		statements = createLazyGetterBody(treeMaker, field, source);
	} else {
		statements = createSimpleGetterBody(treeMaker, field);
	}
	
	JCBlock methodBody = treeMaker.Block(0, statements);
	
	List<JCTypeParameter> methodGenericParams = List.nil();
	List<JCVariableDecl> parameters = List.nil();
	List<JCExpression> throwsClauses = List.nil();
	JCExpression annotationMethodDefaultValue = null;
	
	List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
	List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
	
	List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field);
	
	List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod).appendList(nonNulls).appendList(nullables);
	if (isFieldDeprecated(field)) {
		annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
	}
	
	JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType,
			methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source, field.getContext());
	
	if (toClearOfMarkers != null) recursiveSetGeneratedBy(toClearOfMarkers, null, null);
	decl.mods.annotations = decl.mods.annotations.appendList(delegates);
	
	copyJavadoc(field, decl, CopyJavadoc.GETTER);
	return decl;
}
 
Example 20
Source File: Lower.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Return access symbol for a private or protected symbol from an inner class.
 *  @param sym        The accessed private symbol.
 *  @param tree       The accessing tree.
 *  @param enclOp     The closest enclosing operation node of tree,
 *                    null if tree is not a subtree of an operation.
 *  @param protAccess Is access to a protected symbol in another
 *                    package?
 *  @param refSuper   Is access via a (qualified) C.super?
 */
MethodSymbol accessSymbol(Symbol sym, JCTree tree, JCTree enclOp,
                          boolean protAccess, boolean refSuper) {
    ClassSymbol accOwner = refSuper && protAccess
        // For access via qualified super (T.super.x), place the
        // access symbol on T.
        ? (ClassSymbol)((JCFieldAccess) tree).selected.type.tsym
        // Otherwise pretend that the owner of an accessed
        // protected symbol is the enclosing class of the current
        // class which is a subclass of the symbol's owner.
        : accessClass(sym, protAccess, tree);

    Symbol vsym = sym;
    if (sym.owner != accOwner) {
        vsym = sym.clone(accOwner);
        actualSymbols.put(vsym, sym);
    }

    Integer anum              // The access number of the access method.
        = accessNums.get(vsym);
    if (anum == null) {
        anum = accessed.length();
        accessNums.put(vsym, anum);
        accessSyms.put(vsym, new MethodSymbol[NCODES]);
        accessed.append(vsym);
        // System.out.println("accessing " + vsym + " in " + vsym.location());
    }

    int acode;                // The access code of the access method.
    List<Type> argtypes;      // The argument types of the access method.
    Type restype;             // The result type of the access method.
    List<Type> thrown;        // The thrown exceptions of the access method.
    switch (vsym.kind) {
    case VAR:
        acode = accessCode(tree, enclOp);
        if (acode >= FIRSTASGOPcode) {
            OperatorSymbol operator = binaryAccessOperator(acode);
            if (operator.opcode == string_add)
                argtypes = List.of(syms.objectType);
            else
                argtypes = operator.type.getParameterTypes().tail;
        } else if (acode == ASSIGNcode)
            argtypes = List.of(vsym.erasure(types));
        else
            argtypes = List.nil();
        restype = vsym.erasure(types);
        thrown = List.nil();
        break;
    case MTH:
        acode = DEREFcode;
        argtypes = vsym.erasure(types).getParameterTypes();
        restype = vsym.erasure(types).getReturnType();
        thrown = vsym.type.getThrownTypes();
        break;
    default:
        throw new AssertionError();
    }

    // For references via qualified super, increment acode by one,
    // making it odd.
    if (protAccess && refSuper) acode++;

    // Instance access methods get instance as first parameter.
    // For protected symbols this needs to be the instance as a member
    // of the type containing the accessed symbol, not the class
    // containing the access method.
    if ((vsym.flags() & STATIC) == 0) {
        argtypes = argtypes.prepend(vsym.owner.erasure(types));
    }
    MethodSymbol[] accessors = accessSyms.get(vsym);
    MethodSymbol accessor = accessors[acode];
    if (accessor == null) {
        accessor = new MethodSymbol(
            STATIC | SYNTHETIC,
            accessName(anum.intValue(), acode),
            new MethodType(argtypes, restype, thrown, syms.methodClass),
            accOwner);
        enterSynthetic(tree.pos(), accessor, accOwner.members());
        accessors[acode] = accessor;
    }
    return accessor;
}