Search in sources :

Example 26 with XAnnotation

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

the class XbaseWithAnnotationsProposalProvider method completeXAnnotation_Value.

@Override
public void completeXAnnotation_Value(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (model instanceof XAnnotation) {
        JvmType annotationType = ((XAnnotation) model).getAnnotationType();
        if (annotationType != null && !annotationType.eIsProxy() && annotationType instanceof JvmAnnotationType) {
            JvmAnnotationType casted = (JvmAnnotationType) annotationType;
            List<JvmOperation> operations = Lists.newArrayList(casted.getDeclaredOperations());
            if (operations.size() == 1) {
                JvmOperation singleOperation = operations.get(0);
                if ("value".equals(singleOperation.getSimpleName())) {
                    // TODO propose qualified enum literals + import
                    super.completeXAnnotation_Value(model, assignment, context, acceptor);
                    if ("java.lang.Class".equals(getRawReturnType(singleOperation))) {
                        // eager proposals for classes if the expected type is a suptype of class
                        // TODO evaluate the bounds of the class
                        completeJavaTypes(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, // force
                        true, getQualifiedNameValueConverter(), createVisibilityFilter(context), acceptor);
                    } else {
                        proposeDeclaringTypeForStaticInvocation(model, assignment, context, acceptor);
                    }
                }
            }
        }
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) JvmType(org.eclipse.xtext.common.types.JvmType)

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