Java Code Examples for com.sun.tools.javac.util.Assert#error()

The following examples show how to use com.sun.tools.javac.util.Assert#error() . These examples are extracted from open source projects. 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
void checkDefaultInterface(TypeElement te) {
    System.err.println("Checking " + te.getSimpleName());
    Assert.check(te.getModifiers().contains(Modifier.ABSTRACT));
    for (Element e : te.getEnclosedElements()) {
        if (e.getSimpleName().toString().matches("(\\w)_(default|static|abstract)")) {
            boolean abstractExpected = false;
            String methodKind = e.getSimpleName().toString().substring(2);
            switch (methodKind) {
                case "default":
                case "static":
                    break;
                case "abstract":
                    abstractExpected = true;
                    break;
                default:
                    Assert.error("Cannot get here!" + methodKind);
            }
            Assert.check(e.getModifiers().contains(Modifier.ABSTRACT) == abstractExpected);
        }
    }
}
 
Example 2
/** Add all required access methods for a private symbol to enclosing class.
 *  @param sym       The symbol.
 */
void makeAccessible(Symbol sym) {
    JCClassDecl cdef = classDef(sym.owner.enclClass());
    if (cdef == null) Assert.error("class def not found: " + sym + " in " + sym.owner);
    if (sym.name == names.init) {
        cdef.defs = cdef.defs.prepend(
            accessConstructorDef(cdef.pos, sym, accessConstrs.get(sym)));
    } else {
        MethodSymbol[] accessors = accessSyms.get(sym);
        for (int i = 0; i < AccessCode.numberOfAccessCodes; i++) {
            if (accessors[i] != null)
                cdef.defs = cdef.defs.prepend(
                    accessDef(cdef.pos, sym, accessors[i], i));
        }
    }
}
 
Example 3
private JCTree directlyEnclosingLambda() {
    if (frameStack.isEmpty()) {
        return null;
    }
    List<Frame> frameStack2 = frameStack;
    while (frameStack2.nonEmpty()) {
        switch (frameStack2.head.tree.getTag()) {
            case CLASSDEF:
            case METHODDEF:
                return null;
            case LAMBDA:
                return frameStack2.head.tree;
            default:
                frameStack2 = frameStack2.tail;
        }
    }
    Assert.error();
    return null;
}
 
Example 4
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e : roundEnv.getElementsAnnotatedWith(Gen.class)) {
        Gen gen = e.getAnnotation(Gen.class);
        try {
            JavaFileObject source = processingEnv.getFiler().createSourceFile(gen.fileName());

            try (Writer out = source.openWriter()) {
                out.write(gen.content());
            }
        } catch (IOException ex) {
            throw new IllegalStateException(ex);
        }
    }

    TypeElement generated = processingEnv.getElementUtils().getTypeElement("Generated");

    if (generated != null) {
        Check check = ElementFilter.methodsIn(generated.getEnclosedElements()).get(0).getAnnotation(Check.class);

        checkCorrectException(check::classValue, "java.lang.Class<java.lang.String>");
        checkCorrectException(check::intConstValue, "boolean");
        checkCorrectException(check::enumValue, "java.lang.String");
        checkCorrectException(check::incorrectAnnotationValue, "java.lang.Deprecated");
        checkCorrectException(check::incorrectArrayValue, "<any>");
        checkCorrectException(check::incorrectClassValue, "<any>");

        seenGenerated = true;
    }

    if (roundEnv.processingOver() && !seenGenerated) {
        Assert.error("Did not see the generated class!");
    }

    return true;
}
 
Example 5
Source Project: jdk8u60   File: Processor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e : roundEnv.getElementsAnnotatedWith(Gen.class)) {
        Gen gen = e.getAnnotation(Gen.class);
        try {
            JavaFileObject source = processingEnv.getFiler().createSourceFile(gen.fileName());

            try (Writer out = source.openWriter()) {
                out.write(gen.content());
            }
        } catch (IOException ex) {
            throw new IllegalStateException(ex);
        }
    }

    TypeElement generated = processingEnv.getElementUtils().getTypeElement("Generated");

    if (generated != null) {
        Check check = ElementFilter.methodsIn(generated.getEnclosedElements()).get(0).getAnnotation(Check.class);

        checkCorrectException(check::classValue, "java.lang.Class<java.lang.String>");
        checkCorrectException(check::intConstValue, "boolean");
        checkCorrectException(check::enumValue, "java.lang.String");
        checkCorrectException(check::incorrectAnnotationValue, "java.lang.Deprecated");
        checkCorrectException(check::incorrectArrayValue, "<any>");
        checkCorrectException(check::incorrectClassValue, "<any>");

        seenGenerated = true;
    }

    if (roundEnv.processingOver() && !seenGenerated) {
        Assert.error("Did not see the generated class!");
    }

    return true;
}
 
Example 6
@Override
public void visitNewClass(JCNewClass tree) {
    if (tree.def != null &&
            !tree.def.mods.annotations.isEmpty()) {
        JCClassDecl classdecl = tree.def;
        TypeAnnotationPosition pos = new TypeAnnotationPosition();
        pos.type = TargetType.CLASS_EXTENDS;
        pos.pos = tree.pos;
        if (classdecl.extending == tree.clazz) {
            pos.type_index = -1;
        } else if (classdecl.implementing.contains(tree.clazz)) {
            pos.type_index = classdecl.implementing.indexOf(tree.clazz);
        } else {
            // In contrast to CLASS elsewhere, typarams cannot occur here.
            Assert.error("Could not determine position of tree " + tree);
        }
        Type before = classdecl.sym.type;
        separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
        copyNewClassAnnotationsToOwner(tree);
        // classdecl.sym.type now contains an annotated type, which
        // is not what we want there.
        // TODO: should we put this type somewhere in the superclass/interface?
        classdecl.sym.type = before;
    }

    scan(tree.encl);
    scan(tree.typeargs);
    scan(tree.clazz);
    scan(tree.args);

    // The class body will already be scanned.
    // scan(tree.def);
}
 
Example 7
/** 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, Errors.NoEnclInstanceOfTypeInScope(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, Errors.NoEnclInstanceOfTypeInScope(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 8
@Override
public void visitNewClass(JCNewClass tree) {
    if (tree.def != null &&
            !tree.def.mods.annotations.isEmpty()) {
        JCClassDecl classdecl = tree.def;
        TypeAnnotationPosition pos = new TypeAnnotationPosition();
        pos.type = TargetType.CLASS_EXTENDS;
        pos.pos = tree.pos;
        if (classdecl.extending == tree.clazz) {
            pos.type_index = -1;
        } else if (classdecl.implementing.contains(tree.clazz)) {
            pos.type_index = classdecl.implementing.indexOf(tree.clazz);
        } else {
            // In contrast to CLASS elsewhere, typarams cannot occur here.
            Assert.error("Could not determine position of tree " + tree);
        }
        Type before = classdecl.sym.type;
        separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
        copyNewClassAnnotationsToOwner(tree);
        // classdecl.sym.type now contains an annotated type, which
        // is not what we want there.
        // TODO: should we put this type somewhere in the superclass/interface?
        classdecl.sym.type = before;
    }

    scan(tree.encl);
    scan(tree.typeargs);
    scan(tree.clazz);
    scan(tree.args);

    // The class body will already be scanned.
    // scan(tree.def);
}
 
Example 9
@Override
public int getPreferredPosition() {
    Assert.error();
    return -1;
}
 
Example 10
@Override
public int getEndPosition(EndPosTable endPosTable) {
    Assert.error();
    return -1;
}
 
Example 11
Source Project: hottub   File: Items.java    License: GNU General Public License v2.0 4 votes vote down vote up
Item load() {
    switch (typecode) {
    case INTcode: case BYTEcode: case SHORTcode: case CHARcode:
        int ival = ((Number)value).intValue();
        if (-1 <= ival && ival <= 5)
            code.emitop0(iconst_0 + ival);
        else if (Byte.MIN_VALUE <= ival && ival <= Byte.MAX_VALUE)
            code.emitop1(bipush, ival);
        else if (Short.MIN_VALUE <= ival && ival <= Short.MAX_VALUE)
            code.emitop2(sipush, ival);
        else
            ldc();
        break;
    case LONGcode:
        long lval = ((Number)value).longValue();
        if (lval == 0 || lval == 1)
            code.emitop0(lconst_0 + (int)lval);
        else
            ldc();
        break;
    case FLOATcode:
        float fval = ((Number)value).floatValue();
        if (isPosZero(fval) || fval == 1.0 || fval == 2.0)
            code.emitop0(fconst_0 + (int)fval);
        else {
            ldc();
        }
        break;
    case DOUBLEcode:
        double dval = ((Number)value).doubleValue();
        if (isPosZero(dval) || dval == 1.0)
            code.emitop0(dconst_0 + (int)dval);
        else
            ldc();
        break;
    case OBJECTcode:
        ldc();
        break;
    default:
        Assert.error();
    }
    return stackItem[typecode];
}
 
Example 12
@Override
public int getEndPosition(EndPosTable endPosTable) {
    Assert.error();
    return -1;
}
 
Example 13
Source Project: openjdk-jdk9   File: Items.java    License: GNU General Public License v2.0 4 votes vote down vote up
Item load() {
    switch (typecode) {
    case INTcode: case BYTEcode: case SHORTcode: case CHARcode:
        int ival = ((Number)value).intValue();
        if (-1 <= ival && ival <= 5)
            code.emitop0(iconst_0 + ival);
        else if (Byte.MIN_VALUE <= ival && ival <= Byte.MAX_VALUE)
            code.emitop1(bipush, ival);
        else if (Short.MIN_VALUE <= ival && ival <= Short.MAX_VALUE)
            code.emitop2(sipush, ival);
        else
            ldc();
        break;
    case LONGcode:
        long lval = ((Number)value).longValue();
        if (lval == 0 || lval == 1)
            code.emitop0(lconst_0 + (int)lval);
        else
            ldc();
        break;
    case FLOATcode:
        float fval = ((Number)value).floatValue();
        if (isPosZero(fval) || fval == 1.0 || fval == 2.0)
            code.emitop0(fconst_0 + (int)fval);
        else {
            ldc();
        }
        break;
    case DOUBLEcode:
        double dval = ((Number)value).doubleValue();
        if (isPosZero(dval) || dval == 1.0)
            code.emitop0(dconst_0 + (int)dval);
        else
            ldc();
        break;
    case OBJECTcode:
        ldc();
        break;
    default:
        Assert.error();
    }
    return stackItem[typecode];
}
 
Example 14
@Override
public void visitTree(JCTree tree) {
    Assert.error();
}
 
Example 15
Source Project: openjdk-8   File: Items.java    License: GNU General Public License v2.0 4 votes vote down vote up
Item load() {
    switch (typecode) {
    case INTcode: case BYTEcode: case SHORTcode: case CHARcode:
        int ival = ((Number)value).intValue();
        if (-1 <= ival && ival <= 5)
            code.emitop0(iconst_0 + ival);
        else if (Byte.MIN_VALUE <= ival && ival <= Byte.MAX_VALUE)
            code.emitop1(bipush, ival);
        else if (Short.MIN_VALUE <= ival && ival <= Short.MAX_VALUE)
            code.emitop2(sipush, ival);
        else
            ldc();
        break;
    case LONGcode:
        long lval = ((Number)value).longValue();
        if (lval == 0 || lval == 1)
            code.emitop0(lconst_0 + (int)lval);
        else
            ldc();
        break;
    case FLOATcode:
        float fval = ((Number)value).floatValue();
        if (isPosZero(fval) || fval == 1.0 || fval == 2.0)
            code.emitop0(fconst_0 + (int)fval);
        else {
            ldc();
        }
        break;
    case DOUBLEcode:
        double dval = ((Number)value).doubleValue();
        if (isPosZero(dval) || dval == 1.0)
            code.emitop0(dconst_0 + (int)dval);
        else
            ldc();
        break;
    case OBJECTcode:
        ldc();
        break;
    default:
        Assert.error();
    }
    return stackItem[typecode];
}
 
Example 16
public void visitTree(JCTree tree) {
    Assert.error();
}
 
Example 17
@Override
public int getEndPosition(EndPosTable endPosTable) {
    Assert.error();
    return -1;
}
 
Example 18
/**
 * Determine whether an annotation is a declaration annotation,
 * a type annotation, or both.
 */
public AnnotationType annotationType(Attribute.Compound a, Symbol s) {
    Attribute.Compound atTarget =
        a.type.tsym.attribute(syms.annotationTargetType.tsym);
    if (atTarget == null) {
        return inferTargetMetaInfo(a, s);
    }
    Attribute atValue = atTarget.member(names.value);
    if (!(atValue instanceof Attribute.Array)) {
        Assert.error("annotationType(): bad @Target argument " + atValue +
                " (" + atValue.getClass() + ")");
        return AnnotationType.DECLARATION; // error recovery
    }
    Attribute.Array arr = (Attribute.Array) atValue;
    boolean isDecl = false, isType = false;
    for (Attribute app : arr.values) {
        if (!(app instanceof Attribute.Enum)) {
            Assert.error("annotationType(): unrecognized Attribute kind " + app +
                    " (" + app.getClass() + ")");
            isDecl = true;
            continue;
        }
        Attribute.Enum e = (Attribute.Enum) app;
        if (e.value.name == names.TYPE) {
            if (s.kind == Kinds.TYP)
                isDecl = true;
        } else if (e.value.name == names.FIELD) {
            if (s.kind == Kinds.VAR &&
                    s.owner.kind != Kinds.MTH)
                isDecl = true;
        } else if (e.value.name == names.METHOD) {
            if (s.kind == Kinds.MTH &&
                    !s.isConstructor())
                isDecl = true;
        } else if (e.value.name == names.PARAMETER) {
            if (s.kind == Kinds.VAR &&
                    s.owner.kind == Kinds.MTH &&
                    (s.flags() & Flags.PARAMETER) != 0)
                isDecl = true;
        } else if (e.value.name == names.CONSTRUCTOR) {
            if (s.kind == Kinds.MTH &&
                    s.isConstructor())
                isDecl = true;
        } else if (e.value.name == names.LOCAL_VARIABLE) {
            if (s.kind == Kinds.VAR &&
                    s.owner.kind == Kinds.MTH &&
                    (s.flags() & Flags.PARAMETER) == 0)
                isDecl = true;
        } else if (e.value.name == names.ANNOTATION_TYPE) {
            if (s.kind == Kinds.TYP &&
                    (s.flags() & Flags.ANNOTATION) != 0)
                isDecl = true;
        } else if (e.value.name == names.PACKAGE) {
            if (s.kind == Kinds.PCK)
                isDecl = true;
        } else if (e.value.name == names.TYPE_USE) {
            if (s.kind == Kinds.TYP ||
                    s.kind == Kinds.VAR ||
                    (s.kind == Kinds.MTH && !s.isConstructor() &&
                    !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
                    (s.kind == Kinds.MTH && s.isConstructor()))
                isType = true;
        } else if (e.value.name == names.TYPE_PARAMETER) {
            /* Irrelevant in this case */
            // TYPE_PARAMETER doesn't aid in distinguishing between
            // Type annotations and declaration annotations on an
            // Element
        } else {
            Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
                    " (" + e.value.name.getClass() + ")");
            isDecl = true;
        }
    }
    if (isDecl && isType) {
        return AnnotationType.BOTH;
    } else if (isType) {
        return AnnotationType.TYPE;
    } else {
        return AnnotationType.DECLARATION;
    }
}
 
Example 19
@Override
public int getStartPosition() {
    Assert.error();
    return -1;
}
 
Example 20
Source Project: javaide   File: JCTree.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void visitTree(JCTree that) {
    Assert.error();
}