Search in sources :

Example 51 with Interface

use of com.redhat.ceylon.model.typechecker.model.Interface in project ceylon-compiler by ceylon.

the class AnnotationUtil method interopAnnotationTargeting.

/**
 * Returns the set of output program elements that the given annotation
 * could be applied to. If the {@code errors} flag is true then add
 * warnings/errors to the tree about ambigous/impossible targets.
 */
public static EnumSet<OutputElement> interopAnnotationTargeting(EnumSet<OutputElement> outputs, Tree.Annotation annotation, boolean errors) {
    Declaration annoCtor = ((Tree.BaseMemberExpression) annotation.getPrimary()).getDeclaration();
    if (annoCtor instanceof AnnotationProxyMethod) {
        AnnotationProxyMethod proxyCtor = (AnnotationProxyMethod) annoCtor;
        AnnotationProxyClass annoClass = proxyCtor.getProxyClass();
        EnumSet<OutputElement> possibleTargets;
        if (proxyCtor.getAnnotationTarget() != null) {
            possibleTargets = EnumSet.of(proxyCtor.getAnnotationTarget());
        } else {
            possibleTargets = AnnotationTarget.outputTargets(annoClass);
        }
        EnumSet<OutputElement> actualTargets = possibleTargets.clone();
        actualTargets.retainAll(outputs);
        if (actualTargets.size() > 1) {
            if (errors) {
                StringBuffer sb = new StringBuffer();
                sb.append("ambiguous annotation target: ").append(annoCtor.getName());
                sb.append(" could be applied to several targets, use one of ");
                for (Iterator<OutputElement> iterator = actualTargets.iterator(); iterator.hasNext(); ) {
                    OutputElement x = iterator.next();
                    sb.append(Naming.getDisambigAnnoCtorName((Interface) ((AnnotationProxyMethod) annoCtor).getProxyClass().iface, x));
                    if (iterator.hasNext()) {
                        sb.append(", ");
                    }
                }
                sb.append(" to disambiguate");
                annotation.addUsageWarning(Warning.ambiguousAnnotation, sb.toString(), Backend.Java);
            }
            return null;
        } else if (actualTargets.size() == 0) {
            if (errors) {
                annotation.addError("no target for " + annoCtor.getName() + " annotation: @Target of @interface " + ((AnnotationProxyClass) annoClass).iface.getName() + " lists " + possibleTargets + " but annotated element tranforms to " + outputs, Backend.Java);
            }
        }
        return actualTargets;
    } else {
        return null;
    }
}
Also used : AnnotationProxyMethod(com.redhat.ceylon.model.loader.model.AnnotationProxyMethod) OutputElement(com.redhat.ceylon.model.loader.model.OutputElement) AnnotationProxyClass(com.redhat.ceylon.model.loader.model.AnnotationProxyClass) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface)

Example 52 with Interface

use of com.redhat.ceylon.model.typechecker.model.Interface in project ceylon-compiler by ceylon.

the class TypeParserTests method testCallableOfEntry.

@Test
public void testCallableOfEntry() {
    Type type = new TypeParser(MockLoader.instance).decodeType("ceylon.language::Boolean(ceylon.language::Nothing->ceylon.language::Nothing)", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Callable<ceylon.language::Boolean,ceylon.language::Tuple<ceylon.language::Entry<ceylon.language::Nothing,ceylon.language::Nothing>,ceylon.language::Entry<ceylon.language::Nothing,ceylon.language::Nothing>,ceylon.language::Empty>>", printType(type));
    Assert.assertNull(type.getQualifyingType());
}
Also used : IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Type(com.redhat.ceylon.model.typechecker.model.Type) UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) TypeParser(com.redhat.ceylon.model.loader.TypeParser) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Test(org.junit.Test)

Example 53 with Interface

use of com.redhat.ceylon.model.typechecker.model.Interface in project ceylon-compiler by ceylon.

the class TypeParserTests method testSpreadCallableAbbrev.

@Test
public void testSpreadCallableAbbrev() {
    Type type = new TypeParser(MockLoader.instance).decodeType("a(*[b,a])", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Callable", declaration.getQualifiedNameString());
    Assert.assertEquals("a(b, a)", type.asString());
    Assert.assertNull(type.getQualifyingType());
}
Also used : IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Type(com.redhat.ceylon.model.typechecker.model.Type) UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) TypeParser(com.redhat.ceylon.model.loader.TypeParser) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Test(org.junit.Test)

Example 54 with Interface

use of com.redhat.ceylon.model.typechecker.model.Interface in project ceylon-compiler by ceylon.

the class TypeParserTests method testSequentialAbbrev.

@Test
public void testSequentialAbbrev() {
    Type type = new TypeParser(MockLoader.instance).decodeType("[a*]", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Sequential", declaration.getQualifiedNameString());
    Assert.assertEquals("a[]", type.asString());
    Assert.assertNull(type.getQualifyingType());
}
Also used : IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Type(com.redhat.ceylon.model.typechecker.model.Type) UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) TypeParser(com.redhat.ceylon.model.loader.TypeParser) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Test(org.junit.Test)

Example 55 with Interface

use of com.redhat.ceylon.model.typechecker.model.Interface in project ceylon-compiler by ceylon.

the class TypeParserTests method testPossiblyEmptyIterableAbbrev.

@Test
public void testPossiblyEmptyIterableAbbrev() {
    Type type = new TypeParser(MockLoader.instance).decodeType("{a*}", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Iterable", declaration.getQualifiedNameString());
    Assert.assertEquals("{a*}", type.asString());
    Assert.assertNull(type.getQualifyingType());
}
Also used : IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Type(com.redhat.ceylon.model.typechecker.model.Type) UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) TypeParser(com.redhat.ceylon.model.loader.TypeParser) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Test(org.junit.Test)

Aggregations

Interface (com.redhat.ceylon.model.typechecker.model.Interface)56 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)53 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)35 Type (com.redhat.ceylon.model.typechecker.model.Type)30 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)21 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)20 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)18 JCTree (com.sun.tools.javac.tree.JCTree)18 Class (com.redhat.ceylon.model.typechecker.model.Class)17 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)17 LazyInterface (com.redhat.ceylon.model.loader.model.LazyInterface)14 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)12 Scope (com.redhat.ceylon.model.typechecker.model.Scope)10 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)10 Function (com.redhat.ceylon.model.typechecker.model.Function)9 Value (com.redhat.ceylon.model.typechecker.model.Value)9 TypeParser (com.redhat.ceylon.model.loader.TypeParser)8 Constructor (com.redhat.ceylon.model.typechecker.model.Constructor)8 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)8 IntersectionType (com.redhat.ceylon.model.typechecker.model.IntersectionType)8