Search in sources :

Example 6 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class AbstractTransformer method makeAtLocalContainer.

protected List<JCAnnotation> makeAtLocalContainer(List<String> path, String companionClassName) {
    if (path.isEmpty())
        return List.nil();
    ListBuffer<JCExpression> array = new ListBuffer<JCTree.JCExpression>();
    for (String val : path) array.add(make().Literal(val));
    JCExpression pathAttr = make().Assign(naming.makeUnquotedIdent("path"), make().NewArray(null, null, array.toList()));
    JCExpression companionAttr = make().Assign(naming.makeUnquotedIdent("companionClassName"), make().Literal(companionClassName == null ? "" : companionClassName));
    return makeModelAnnotation(syms().ceylonAtLocalContainerType, List.of(pathAttr, companionAttr));
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 7 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class AbstractTransformer method makeNonEmptyTest.

JCExpression makeNonEmptyTest(JCExpression firstTimeExpr) {
    Interface sequence = typeFact().getSequenceDeclaration();
    JCExpression sequenceType = makeJavaType(sequence.getType(), JT_NO_PRIMITIVES | JT_RAW);
    return make().TypeTest(firstTimeExpr, sequenceType);
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Example 8 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class AbstractTransformer method makeAtClass.

List<JCAnnotation> makeAtClass(Type thisType, Type extendedType, boolean hasConstructors) {
    boolean isBasic = true;
    boolean isIdentifiable = true;
    boolean isAnything = extendedType == null && thisType != null && thisType.isExactly(typeFact().getAnythingType());
    if (isAnything) {
        // special for Anything
        isBasic = isIdentifiable = false;
    } else if (thisType != null) {
        isBasic = thisType.getSupertype(typeFact.getBasicDeclaration()) != null;
        // if isBasic, then isIdentifiable remains true
        if (!isBasic)
            isIdentifiable = thisType.getSupertype(typeFact.getIdentifiableDeclaration()) != null;
    }
    String extendedTypeSig = null;
    if (isAnything) {
        extendedTypeSig = "";
    } else if (extendedType != null && !extendedType.isExactly(typeFact.getBasicType())) {
        extendedTypeSig = serialiseTypeSignature(extendedType);
    }
    List<JCExpression> attributes = List.nil();
    if (extendedTypeSig != null) {
        JCExpression extendsAttribute = make().Assign(naming.makeUnquotedIdent("extendsType"), make().Literal(extendedTypeSig));
        attributes = attributes.prepend(extendsAttribute);
    }
    if (!isBasic) {
        JCExpression basicAttribute = make().Assign(naming.makeUnquotedIdent("basic"), makeBoolean(false));
        attributes = attributes.prepend(basicAttribute);
    }
    if (!isIdentifiable) {
        JCExpression identifiableAttribute = make().Assign(naming.makeUnquotedIdent("identifiable"), makeBoolean(false));
        attributes = attributes.prepend(identifiableAttribute);
    }
    if (hasConstructors) {
        JCExpression constructorsAttribute = make().Assign(naming.makeUnquotedIdent("constructors"), makeBoolean(true));
        attributes = attributes.prepend(constructorsAttribute);
    }
    return makeModelAnnotation(syms().ceylonAtClassType, attributes);
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)

Example 9 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class AbstractTransformer method makeLocalIdentityInstance.

// Creates a "foo foo = new foo(parameter);"
JCTree.JCVariableDecl makeLocalIdentityInstance(JCExpression typeExpr, String varName, String className, boolean isShared, JCTree.JCExpression parameter) {
    JCExpression initValue = makeNewClass(className, false, parameter);
    int modifiers = isShared ? 0 : FINAL;
    JCTree.JCVariableDecl var = make().VarDef(make().Modifiers(modifiers), names().fromString(Naming.quoteLocalValueName(varName)), typeExpr, initValue);
    return var;
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) JCVariableDecl(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 10 with JCExpression

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression in project ceylon by eclipse.

the class AbstractTransformer method unboxOptionalString.

private JCExpression unboxOptionalString(JCExpression value) {
    if (isStringLiteral(value)) {
        // If it's already a String literal, why call .toString on it?
        return value;
    }
    Naming.SyntheticName name = naming.temp();
    JCExpression type = makeJavaType(typeFact().getStringType(), JT_NO_PRIMITIVES);
    JCExpression expr = make().Conditional(make().Binary(JCTree.Tag.NE, name.makeIdent(), makeNull()), unboxString(name.makeIdent()), makeNull());
    return makeLetExpr(name, null, type, value, expr);
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) SyntheticName(org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)

Aggregations

JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)224 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)95 Type (org.eclipse.ceylon.model.typechecker.model.Type)95 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)74 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)53 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)53 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)45 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)41 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)39 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)38 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)33 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)32 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)30 JCVariableDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)28 Function (org.eclipse.ceylon.model.typechecker.model.Function)26 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)22 Value (org.eclipse.ceylon.model.typechecker.model.Value)22 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)21 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)21 Class (org.eclipse.ceylon.model.typechecker.model.Class)17