Search in sources :

Example 1 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-eclipse by eclipse.

the class XbaseWithAnnotationsProposalProvider method completeXAnnotationElementValuePair_Element.

@Override
public void completeXAnnotationElementValuePair_Element(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    XAnnotation annotationReference = null;
    if (model instanceof XAnnotationElementValuePair) {
        annotationReference = (XAnnotation) model.eContainer();
    } else if (model instanceof XAnnotation) {
        annotationReference = (XAnnotation) model;
    }
    if (annotationReference != null) {
        JvmType annotationType = annotationReference.getAnnotationType();
        if (annotationType != null && !annotationType.eIsProxy() && annotationType instanceof JvmAnnotationType) {
            // do not propose features like #toString, #hashCode etc
            JvmAnnotationType casted = (JvmAnnotationType) annotationType;
            final Set<JvmOperation> operations = Sets.newHashSet(casted.getDeclaredOperations());
            Predicate<IEObjectDescription> predicate = Predicates.and(new Predicate<IEObjectDescription>() {

                @Override
                public boolean apply(IEObjectDescription in) {
                    return operations.contains(in.getEObjectOrProxy());
                }
            }, getFeatureDescriptionPredicate(context));
            lookupCrossReference(((CrossReference) assignment.getTerminal()), context, acceptor, predicate);
        }
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XAnnotationElementValuePair(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) CrossReference(org.eclipse.xtext.CrossReference) JvmType(org.eclipse.xtext.common.types.JvmType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 2 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ErrorTest method testErrorModel_015.

@Test
public void testErrorModel_015() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("@ class Node {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration node = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    final XAnnotation annotation = IterableExtensions.<XAnnotation>head(node.getAnnotations());
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(annotation);
    Assert.assertNotNull(resolvedTypes.getActualType(annotation));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Example 3 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ErrorTest method testErrorModel_018.

@Test
public void testErrorModel_018() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def m(@");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
    final XtendFunction function = ((XtendFunction) _head);
    final XtendParameter param = IterableExtensions.<XtendParameter>head(function.getParameters());
    final XAnnotation annotation = IterableExtensions.<XAnnotation>head(param.getAnnotations());
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(annotation);
    Assert.assertNotNull(resolvedTypes.getActualType(annotation));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Example 4 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ErrorTest method testErrorModel_005.

@Test
public void testErrorModel_005() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("@");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration typeDeclaration = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    final EList<XAnnotation> annotations = typeDeclaration.getAnnotations();
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XAnnotation>head(annotations));
    Assert.assertNotNull(resolvedTypes.getActualType(IterableExtensions.<XAnnotation>head(annotations)));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Example 5 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ErrorTest method testErrorModel_006.

@Test
public void testErrorModel_006() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("@Data class A {}");
    _builder.newLine();
    _builder.append("@");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration typeDeclaration = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
    final EList<XAnnotation> annotations = typeDeclaration.getAnnotations();
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XAnnotation>head(annotations));
    Assert.assertNotNull(resolvedTypes.getActualType(IterableExtensions.<XAnnotation>head(annotations)));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Aggregations

XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)26 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)13 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)13 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 Test (org.junit.Test)12 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)11 EObject (org.eclipse.emf.ecore.EObject)4 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)4 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)4 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)4 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)4 XtendAnnotationTarget (org.eclipse.xtend.core.xtend.XtendAnnotationTarget)3 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)3 JvmType (org.eclipse.xtext.common.types.JvmType)3 XtendField (org.eclipse.xtend.core.xtend.XtendField)2 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)2 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 EObjectDiagnosticImpl (org.eclipse.xtext.validation.EObjectDiagnosticImpl)2 XAnnotationElementValuePair (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair)2