Search in sources :

Example 36 with JvmMember

use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.

the class RegisterGlobalsContextImpl method setNameAndAccept.

private void setNameAndAccept(final JvmDeclaredType newType, final String qualifiedName) {
    ConditionUtils.checkQualifiedName(qualifiedName, "qualifiedName");
    JvmDeclaredType _findType = this.findType(qualifiedName);
    boolean _tripleEquals = (_findType == null);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("The type \'");
    _builder.append(qualifiedName);
    _builder.append("\' has already been registered.");
    Preconditions.checkArgument(_tripleEquals, _builder);
    this.compilationUnit.checkCanceled();
    final Pair<String, String> namespaceAndName = this.getNameParts(qualifiedName);
    final String headerText = this.compilationUnit.getFileHeaderProvider().getFileHeader(this.compilationUnit.getXtendFile().eResource());
    this.compilationUnit.getJvmTypesBuilder().setFileHeader(newType, headerText);
    String _key = namespaceAndName.getKey();
    boolean _tripleNotEquals = (_key != null);
    if (_tripleNotEquals) {
        final JvmDeclaredType parentType = this.findType(namespaceAndName.getKey());
        if ((parentType != null)) {
            EList<JvmMember> _members = parentType.getMembers();
            _members.add(newType);
            newType.setStatic(true);
        } else {
            newType.setPackageName(namespaceAndName.getKey());
            this.acceptor.<JvmDeclaredType>accept(newType);
        }
    } else {
        this.acceptor.<JvmDeclaredType>accept(newType);
    }
    newType.setSimpleName(namespaceAndName.getValue());
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 37 with JvmMember

use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.

the class CompilationUnitImpl method translate.

protected Object translate(final Object object) {
    if ((object instanceof XAnnotation[])) {
        final AnnotationReference[] result = new AnnotationReference[((Object[]) object).length];
        int _length = ((Object[]) object).length;
        ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _length, true);
        for (final Integer i : _doubleDotLessThan) {
            result[(i).intValue()] = this.translateAnnotation(((XAnnotation[]) object)[(i).intValue()]);
        }
        return result;
    }
    if ((object instanceof XAnnotation)) {
        return this.translateAnnotation(((XAnnotation) object));
    }
    if ((object instanceof JvmTypeReference[])) {
        final TypeReference[] result_1 = new TypeReference[((Object[]) object).length];
        int _length_1 = ((Object[]) object).length;
        ExclusiveRange _doubleDotLessThan_1 = new ExclusiveRange(0, _length_1, true);
        for (final Integer i_1 : _doubleDotLessThan_1) {
            Object _translate = this.translate(((Object[]) object)[(i_1).intValue()]);
            result_1[(i_1).intValue()] = ((TypeReference) _translate);
        }
        return result_1;
    }
    if ((object instanceof JvmTypeReference)) {
        return this.toTypeReference(((JvmTypeReference) object));
    }
    if ((object instanceof JvmEnumerationLiteral[])) {
        final EnumerationValueDeclaration[] result_2 = new EnumerationValueDeclaration[((Object[]) object).length];
        int _length_2 = ((Object[]) object).length;
        ExclusiveRange _doubleDotLessThan_2 = new ExclusiveRange(0, _length_2, true);
        for (final Integer i_2 : _doubleDotLessThan_2) {
            Object _translate_1 = this.translate(((Object[]) object)[(i_2).intValue()]);
            result_2[(i_2).intValue()] = ((EnumerationValueDeclaration) _translate_1);
        }
        return result_2;
    }
    if ((object instanceof JvmEnumerationLiteral)) {
        return this.toMemberDeclaration(((JvmMember) object));
    }
    return object;
}
Also used : ExclusiveRange(org.eclipse.xtext.xbase.lib.ExclusiveRange) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) EObject(org.eclipse.emf.ecore.EObject) JvmMember(org.eclipse.xtext.common.types.JvmMember) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EnumerationValueDeclaration(org.eclipse.xtend.lib.macro.declaration.EnumerationValueDeclaration)

Example 38 with JvmMember

use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.

the class TypeParameterDeclarationImpl method getTypeParameterDeclarator.

@Override
public TypeParameterDeclarator getTypeParameterDeclarator() {
    EObject _eContainer = this.getDelegate().eContainer();
    MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(((JvmMember) _eContainer));
    return ((TypeParameterDeclarator) _memberDeclaration);
}
Also used : MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) EObject(org.eclipse.emf.ecore.EObject) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 39 with JvmMember

use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.

the class CachingResourceValidatorImpl method addWarningsForOrphanedJvmElements.

private void addWarningsForOrphanedJvmElements(final Resource resource, final CancelIndicator monitor, final IAcceptor<Issue> acceptor) {
    final IssueSeverities issueSeverities = this.issueSeveritiesProvider.getIssueSeverities(resource);
    final Severity severity = issueSeverities.getSeverity(IssueCodes.ORPHAN_ELMENT);
    boolean _equals = Objects.equal(severity, Severity.IGNORE);
    if (_equals) {
        return;
    }
    Iterable<JvmDeclaredType> _filter = Iterables.<JvmDeclaredType>filter(IterableExtensions.<EObject>tail(resource.getContents()), JvmDeclaredType.class);
    for (final JvmDeclaredType jvmType : _filter) {
        final Function1<JvmMember, Boolean> _function = (JvmMember it) -> {
            boolean _isSynthetic = this._jvmTypeExtensions.isSynthetic(it);
            return Boolean.valueOf((!_isSynthetic));
        };
        Iterable<JvmMember> _iterable = IteratorExtensions.<JvmMember>toIterable(IteratorExtensions.<JvmMember>filter(Iterators.<JvmMember>filter(jvmType.eAllContents(), JvmMember.class), _function));
        for (final JvmMember jvmMember : _iterable) {
            {
                this.operationCanceledManager.checkCanceled(monitor);
                final EObject sourceElement = this._iJvmModelAssociations.getPrimarySourceElement(jvmMember);
                if ((sourceElement == null)) {
                    this.addWarningForOrphanedJvmElement(resource, jvmMember, severity, acceptor);
                }
            }
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) Severity(org.eclipse.xtext.diagnostics.Severity) JvmMember(org.eclipse.xtext.common.types.JvmMember) IssueSeverities(org.eclipse.xtext.validation.IssueSeverities)

Example 40 with JvmMember

use of org.eclipse.xtext.common.types.JvmMember in project xtext-xtend by eclipse.

the class InferredJvmModelTest method testXtendField_00.

@Test
public void testXtendField_00() throws Exception {
    XtendFile xtendFile = file("class Foo { @Inject String string }");
    JvmGenericType type = getInferredType(xtendFile);
    Iterable<JvmField> iterable = type.getDeclaredFields();
    JvmField next = iterable.iterator().next();
    assertEquals("string", next.getSimpleName());
    assertEquals(JvmVisibility.PRIVATE, next.getVisibility());
    assertEquals("java.lang.String", next.getType().getIdentifier());
    for (JvmMember member : type.getMembers()) {
        if (member instanceof JvmExecutable) {
            assertEquals(JvmVisibility.PUBLIC, member.getVisibility());
        } else {
            assertEquals(JvmVisibility.PRIVATE, member.getVisibility());
        }
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Aggregations

JvmMember (org.eclipse.xtext.common.types.JvmMember)41 Test (org.junit.Test)22 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)21 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)15 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 EObject (org.eclipse.emf.ecore.EObject)14 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)12 JvmField (org.eclipse.xtext.common.types.JvmField)12 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)8 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)7 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)6 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)6 MemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MemberDeclaration)4 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)4 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)4 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)3 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)3