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

The following examples show how to use com.sun.tools.javac.util.List#isEmpty() . 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: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Validate the proposed container 'repeatable' on the
 * annotation type symbol 's'. Report errors at position
 * 'pos'.
 *
 * @param s The (annotation)type declaration annotated with a @Repeatable
 * @param repeatable the @Repeatable on 's'
 * @param pos where to report errors
 */
public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) {
    Assert.check(types.isSameType(repeatable.type, syms.repeatableType));

    Type t = null;
    List<Pair<MethodSymbol,Attribute>> l = repeatable.values;
    if (!l.isEmpty()) {
        Assert.check(l.head.fst.name == names.value);
        t = ((Attribute.Class)l.head.snd).getValue();
    }

    if (t == null) {
        // errors should already have been reported during Annotate
        return;
    }

    validateValue(t.tsym, s, pos);
    validateRetention(t.tsym, s, pos);
    validateDocumented(t.tsym, s, pos);
    validateInherited(t.tsym, s, pos);
    validateTarget(t.tsym, s, pos);
    validateDefault(t.tsym, pos);
}
 
Example 2
Source File: Infer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/** Instantiate undetermined type variable to its minimal upper bound.
 *  Throw a NoInstanceException if this not possible.
 */
void maximizeInst(UndetVar that, Warner warn) throws NoInstanceException {
    List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
    if (that.inst == null) {
        if (hibounds.isEmpty())
            that.inst = syms.objectType;
        else if (hibounds.tail.isEmpty())
            that.inst = hibounds.head;
        else
            that.inst = types.glb(hibounds);
    }
    if (that.inst == null ||
        that.inst.isErroneous())
        throw ambiguousNoInstanceException
            .setMessage("no.unique.maximal.instance.exists",
                        that.qtype, hibounds);
}
 
Example 3
Source File: Check.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate the proposed container 'repeatable' on the
 * annotation type symbol 's'. Report errors at position
 * 'pos'.
 *
 * @param s The (annotation)type declaration annotated with a @Repeatable
 * @param repeatable the @Repeatable on 's'
 * @param pos where to report errors
 */
public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) {
    Assert.check(types.isSameType(repeatable.type, syms.repeatableType));

    Type t = null;
    List<Pair<MethodSymbol,Attribute>> l = repeatable.values;
    if (!l.isEmpty()) {
        Assert.check(l.head.fst.name == names.value);
        t = ((Attribute.Class)l.head.snd).getValue();
    }

    if (t == null) {
        // errors should already have been reported during Annotate
        return;
    }

    validateValue(t.tsym, s, pos);
    validateRetention(t.tsym, s, pos);
    validateDocumented(t.tsym, s, pos);
    validateInherited(t.tsym, s, pos);
    validateTarget(t.tsym, s, pos);
    validateDefault(t.tsym, pos);
}
 
Example 4
Source File: JavacParser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected JCCase switchBlockStatementGroup() {
    int pos = token.pos;
    List<JCStatement> stats;
    JCCase c;
    switch (token.kind) {
    case CASE:
        nextToken();
        JCExpression pat = parseExpression();
        accept(COLON);
        stats = blockStatements();
        c = F.at(pos).Case(pat, stats);
        if (stats.isEmpty())
            storeEnd(c, S.prevToken().endPos);
        return c;
    case DEFAULT:
        nextToken();
        accept(COLON);
        stats = blockStatements();
        c = F.at(pos).Case(null, stats);
        if (stats.isEmpty())
            storeEnd(c, S.prevToken().endPos);
        return c;
    }
    throw new AssertionError("should not reach here");
}
 
Example 5
Source File: SymbolMetadata.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public SymbolMetadata appendUniqueTypes(List<Attribute.TypeCompound> l) {
    if (l.isEmpty()) {
        ; // no-op
    } else if (type_attributes.isEmpty()) {
        type_attributes = l;
    } else {
        // TODO: in case we expect a large number of annotations, this
        // might be inefficient.
        for (Attribute.TypeCompound tc : l) {
            if (!type_attributes.contains(tc))
                type_attributes = type_attributes.append(tc);
        }
    }
    return this;
}
 
Example 6
Source File: JCTree.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public JCLambda(List<JCVariableDecl> params,
                JCTree body) {
    this.params = params;
    this.body = body;
    if (params.isEmpty() ||
        params.head.vartype != null) {
        paramKind = ParameterKind.EXPLICIT;
    } else {
        paramKind = ParameterKind.IMPLICIT;
    }
}
 
Example 7
Source File: Types.java    From javaide with GNU General Public License v3.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 8
Source File: Check.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Remove type set from type set list.
 */
List<Type> excl(Type t, List<Type> ts) {
    if (ts.isEmpty()) {
        return ts;
    } else {
        List<Type> ts1 = excl(t, ts.tail);
        if (types.isSubtype(ts.head, t)) return ts1;
        else if (ts1 == ts.tail) return ts;
        else return ts1.prepend(ts.head);
    }
}
 
Example 9
Source File: BridgeHarness.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Remove an element from a list
 */
static <Z> List<Z> drop(List<Z> lz, Z z) {
    if (lz.head == z) {
        return drop(lz.tail, z);
    } else if (lz.isEmpty()) {
        return lz;
    } else {
        return drop(lz.tail, z).prepend(lz.head);
    }
}
 
Example 10
Source File: ListBufferTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void assertEndsWithNil(List<?> list) {
    while (!list.isEmpty()) {
        list = list.tail;
    }

    if (list != List.nil()) throw new IllegalStateException("Not ending with List.nil()");
}
 
Example 11
Source File: ListBufferTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void assertEndsWithNil(List<?> list) {
    while (!list.isEmpty()) {
        list = list.tail;
    }

    if (list != List.nil()) throw new IllegalStateException("Not ending with List.nil()");
}
 
Example 12
Source File: Lower.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** Construct a tree that represents the outer instance
 *  {@code C.this}. Never pick the current `this'.
 *  @param pos           The source code position to be used for the tree.
 *  @param c             The qualifier class.
 */
JCExpression makeOuterThis(DiagnosticPosition pos, TypeSymbol c) {
    List<VarSymbol> ots = outerThisStack;
    if (ots.isEmpty()) {
        log.error(pos, "no.encl.instance.of.type.in.scope", c);
        Assert.error();
        return makeNull();
    }
    VarSymbol ot = ots.head;
    JCExpression tree = access(make.at(pos).Ident(ot));
    TypeSymbol otc = ot.type.tsym;
    while (otc != c) {
        do {
            ots = ots.tail;
            if (ots.isEmpty()) {
                log.error(pos,
                          "no.encl.instance.of.type.in.scope",
                          c);
                Assert.error(); // should have been caught in Attr
                return tree;
            }
            ot = ots.head;
        } while (ot.owner != otc);
        if (otc.owner.kind != PCK && !otc.hasOuterInstance()) {
            chk.earlyRefError(pos, c);
            Assert.error(); // should have been caught in Attr
            return makeNull();
        }
        tree = access(make.at(pos).Select(tree, ot));
        otc = ot.type.tsym;
    }
    return tree;
}
 
Example 13
Source File: BridgeHarness.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Remove an element from a list
 */
static <Z> List<Z> drop(List<Z> lz, Z z) {
    if (lz.head == z) {
        return drop(lz.tail, z);
    } else if (lz.isEmpty()) {
        return lz;
    } else {
        return drop(lz.tail, z).prepend(lz.head);
    }
}
 
Example 14
Source File: SymbolMetadata.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public SymbolMetadata appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
    if (l.isEmpty()) {
        ; // no-op
    } else if (init_type_attributes.isEmpty()) {
        init_type_attributes = l;
    } else {
        init_type_attributes = init_type_attributes.appendList(l);
    }
    return this;
}
 
Example 15
Source File: TypeAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void findPosition(JCTree tree, JCTree frame, List<JCAnnotation> annotations) {
    if (!annotations.isEmpty()) {
        /*
        System.err.println("Finding pos for: " + annotations);
        System.err.println("    tree: " + tree + " kind: " + tree.getKind());
        System.err.println("    frame: " + frame + " kind: " + frame.getKind());
        */
        TypeAnnotationPosition p = new TypeAnnotationPosition();
        p.onLambda = currentLambda;
        resolveFrame(tree, frame, frames.toList(), p);
        setTypeAnnotationPos(annotations, p);
    }
}
 
Example 16
Source File: MemberEnter.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/** Construct method type from method signature.
 *  @param typarams    The method's type parameters.
 *  @param params      The method's value parameters.
 *  @param res             The method's result type,
 *                 null if it is a constructor.
 *  @param thrown      The method's thrown exceptions.
 *  @param env             The method's (local) environment.
 */
Type signature(List<JCTypeParameter> typarams,
               List<JCVariableDecl> params,
               JCTree res,
               List<JCExpression> thrown,
               Env<AttrContext> env) {

    // Enter and attribute type parameters.
    List<Type> tvars = enter.classEnter(typarams, env);
    attr.attribTypeVariables(typarams, env);

    // Enter and attribute value parameters.
    ListBuffer<Type> argbuf = new ListBuffer<Type>();
    for (List<JCVariableDecl> l = params; l.nonEmpty(); l = l.tail) {
        memberEnter(l.head, env);
        argbuf.append(l.head.vartype.type);
    }

    // Attribute result type, if one is given.
    Type restype = res == null ? syms.voidType : attr.attribType(res, env);

    // Attribute thrown exceptions.
    ListBuffer<Type> thrownbuf = new ListBuffer<Type>();
    for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail) {
        Type exc = attr.attribType(l.head, env);
        if (exc.tag != TYPEVAR)
            exc = chk.checkClassType(l.head.pos(), exc);
        thrownbuf.append(exc);
    }
    Type mtype = new MethodType(argbuf.toList(),
                                restype,
                                thrownbuf.toList(),
                                syms.methodClass);
    return tvars.isEmpty() ? mtype : new ForAll(tvars, mtype);
}
 
Example 17
Source File: JavaCompiler.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public List<JCCompilationUnit> initModules(List<JCCompilationUnit> roots) {
    modules.initModules(roots);
    if (roots.isEmpty()) {
        enterDone();
    }
    return roots;
}
 
Example 18
Source File: Lower.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Similar to makeOwnerThis but will never pick "this".
 */
JCExpression makeOwnerThisN(DiagnosticPosition pos, Symbol sym, boolean preciseMatch) {
    Symbol c = sym.owner;
    List<VarSymbol> ots = outerThisStack;
    if (ots.isEmpty()) {
        log.error(pos, "no.encl.instance.of.type.in.scope", c);
        Assert.error();
        return makeNull();
    }
    VarSymbol ot = ots.head;
    JCExpression tree = access(make.at(pos).Ident(ot));
    TypeSymbol otc = ot.type.tsym;
    while (!(preciseMatch ? sym.isMemberOf(otc, types) : otc.isSubClass(sym.owner, types))) {
        do {
            ots = ots.tail;
            if (ots.isEmpty()) {
                log.error(pos,
                    "no.encl.instance.of.type.in.scope",
                    c);
                Assert.error();
                return tree;
            }
            ot = ots.head;
        } while (ot.owner != otc);
        tree = access(make.at(pos).Select(tree, ot));
        otc = ot.type.tsym;
    }
    return tree;
}
 
Example 19
Source File: TList.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void test_isEmpty() {
    System.err.println("test isEmpty()");
    for (Map.Entry<java.util.List<String>,List<String>> e: examples.entrySet()) {
        java.util.List<String> ref = e.getKey();
        List<String> l = e.getValue();
        boolean expect = ref.isEmpty();
        boolean found = l.isEmpty();
        if (expect != found)
            throw new AssertionError();
    }
}
 
Example 20
Source File: HandleWither.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCMethodDecl createWither(long access, JavacNode field, JavacTreeMaker maker, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) {
	String witherName = toWitherName(field);
	if (witherName == null) return null;
	
	JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
	
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
	List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
	
	Name methodName = field.toName(witherName);
	List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
	
	long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
	JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
	
	JCExpression selfType = cloneSelfType(field);
	if (selfType == null) return null;
	
	ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
	for (JavacNode child : field.up().down()) {
		if (child.getKind() != Kind.FIELD) continue;
		JCVariableDecl childDecl = (JCVariableDecl) child.get();
		// Skip fields that start with $
		if (childDecl.name.toString().startsWith("$")) continue;
		long fieldFlags = childDecl.mods.flags;
		// Skip static fields.
		if ((fieldFlags & Flags.STATIC) != 0) continue;
		// Skip initialized final fields.
		if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue;
		if (child.get() == field.get()) {
			args.append(maker.Ident(fieldDecl.name));
		} else {
			args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD));
		}
	}
	
	JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null);
	JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
	JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
	JCReturn returnStatement = maker.Return(conditional);
	
	if (nonNulls.isEmpty()) {
		statements.append(returnStatement);
	} else {
		JCStatement nullCheck = generateNullCheck(maker, field, source);
		if (nullCheck != null) statements.append(nullCheck);
		statements.append(returnStatement);
	}
	
	JCExpression returnType = cloneSelfType(field);
	
	JCBlock methodBody = maker.Block(0, statements.toList());
	List<JCTypeParameter> methodGenericParams = List.nil();
	List<JCVariableDecl> parameters = List.of(param);
	List<JCExpression> throwsClauses = List.nil();
	JCExpression annotationMethodDefaultValue = null;
	
	List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);
	
	if (isFieldDeprecated(field)) {
		annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
	}
	JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType,
			methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext());
	copyJavadoc(field, decl, CopyJavadoc.WITHER);
	return decl;
}