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;
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations