Search in sources :

Example 11 with JvmFeature

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

the class SyntheticNameClashResolver method resolveNameClashes.

public void resolveNameClashes(JvmGenericType type) {
    Multimap<String, JvmIdentifiableElement> classScope = HashMultimap.create();
    List<JvmMember> renameableMembers = newArrayList();
    int i = 1;
    for (JvmMember member : type.getMembers()) {
        String simpleName = member.getSimpleName();
        if (simpleName != null) {
            if (!isRenameable(member))
                classScope.put(simpleName, member);
            else
                renameableMembers.add(member);
        }
        if (member instanceof JvmFeature) {
            for (JvmGenericType localType : ((JvmFeature) member).getLocalClasses()) {
                localType.setSimpleName(localType.getSimpleName() + '_' + (i++));
            }
        }
    }
    for (JvmMember renameable : renameableMembers) {
        String simpleName = renameable.getSimpleName();
        if (collides(renameable, simpleName, classScope)) {
            int count = 0;
            String currentName;
            do {
                if (count == Integer.MAX_VALUE)
                    throw new IllegalStateException("Cannot find a collision-free name for " + renameable.getIdentifier());
                currentName = simpleName + "_" + ++count;
            } while (collides(renameable, currentName, classScope));
            renameable.setSimpleName(currentName);
            classScope.put(currentName, renameable);
        } else {
            classScope.put(simpleName, renameable);
        }
    }
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 12 with JvmFeature

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

the class EclipseXtendOutlineSourceContext method markCreateExtensionJvmFeaturesAsProcessed.

protected void markCreateExtensionJvmFeaturesAsProcessed(final JvmMember member) {
    final EObject function = this._iXtendJvmAssociations.getPrimarySourceElement(member);
    if ((function instanceof XtendFunction)) {
        CreateExtensionInfo _createExtensionInfo = ((XtendFunction) function).getCreateExtensionInfo();
        boolean _tripleNotEquals = (_createExtensionInfo != null);
        if (_tripleNotEquals) {
            final Function1<JvmFeature, Boolean> _function = (JvmFeature it) -> {
                return Boolean.valueOf((!Objects.equal(it, member)));
            };
            final Function1<JvmFeature, Boolean> _function_1 = (JvmFeature it) -> {
                return Boolean.valueOf((it.getSimpleName().startsWith(XtendJvmModelInferrer.CREATE_CHACHE_VARIABLE_PREFIX) || it.getSimpleName().startsWith(XtendJvmModelInferrer.CREATE_INITIALIZER_PREFIX)));
            };
            Iterable<JvmFeature> _filter = IterableExtensions.<JvmFeature>filter(IterableExtensions.<JvmFeature>filter(Iterables.<JvmFeature>filter(this._iXtendJvmAssociations.getJvmElements(function), JvmFeature.class), _function), _function_1);
            for (final JvmFeature jvmFeature : _filter) {
                super.markAsProcessed(jvmFeature);
            }
        }
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmFeature(org.eclipse.xtext.common.types.JvmFeature) EObject(org.eclipse.emf.ecore.EObject) CreateExtensionInfo(org.eclipse.xtend.core.xtend.CreateExtensionInfo)

Aggregations

JvmFeature (org.eclipse.xtext.common.types.JvmFeature)12 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)6 EObject (org.eclipse.emf.ecore.EObject)4 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)3 XImportDeclaration (org.eclipse.xtext.xtype.XImportDeclaration)3 StyledString (org.eclipse.jface.viewers.StyledString)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 JvmMember (org.eclipse.xtext.common.types.JvmMember)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 LinkedList (java.util.LinkedList)1 EList (org.eclipse.emf.common.util.EList)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 JavaElementImageDescriptor (org.eclipse.jdt.ui.JavaElementImageDescriptor)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 Region (org.eclipse.jface.text.Region)1 Image (org.eclipse.swt.graphics.Image)1 CreateExtensionInfo (org.eclipse.xtend.core.xtend.CreateExtensionInfo)1 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)1