Search in sources :

Example 41 with JvmIdentifiableElement

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

the class AbstractMultiModeOutlineTreeProvider method computeDecoratedText.

protected Object computeDecoratedText(final Object modelElement, final int inheritanceDepth) {
    Object supertext = super.getText(modelElement);
    if (!(supertext instanceof StyledString)) {
        return supertext;
    }
    StyledString styledText = (StyledString) supertext;
    if (inheritanceDepth > 0) {
        styledText = applyStylerToFirstSegment(styledText, ColoringLabelProvider.INHERITED_STYLER);
    }
    if (modelElement instanceof JvmIdentifiableElement) {
        JvmIdentifiableElement jvmElement = (JvmIdentifiableElement) modelElement;
        if (!getAssociations().getSourceElements(jvmElement).isEmpty() && !getAssociations().isPrimaryJvmElement(jvmElement)) {
            styledText = applyStylerToFirstSegment(styledText, StyledString.QUALIFIER_STYLER);
        }
    }
    if (isShowInherited()) {
        if (modelElement instanceof IResolvedFeature) {
            String qualifier = createQualifier((IResolvedFeature) modelElement);
            appendQualifier(styledText, qualifier);
        } else if (modelElement instanceof JvmMember) {
            String qualifier = createQualifier((JvmMember) modelElement);
            appendQualifier(styledText, qualifier);
        } else if (modelElement instanceof XtendMember) {
            XtendMember xtendMember = (XtendMember) modelElement;
            if (xtendMember.eContainer() instanceof XtendTypeDeclaration) {
                String qualifiedName = createQualifier((XtendTypeDeclaration) xtendMember.eContainer(), '.');
                appendQualifier(styledText, qualifiedName);
            } else if (xtendMember instanceof XtendTypeDeclaration) {
                XtendFile xtendFile = EcoreUtil2.getContainerOfType(xtendMember, XtendFile.class);
                String qualifiedName = xtendFile.getPackage() == null ? "(default package)" : xtendFile.getPackage();
                appendQualifier(styledText, qualifiedName);
            }
        }
    }
    return styledText;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) EObject(org.eclipse.emf.ecore.EObject) JvmMember(org.eclipse.xtext.common.types.JvmMember) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) IResolvedFeature(org.eclipse.xtext.xbase.typesystem.override.IResolvedFeature)

Example 42 with JvmIdentifiableElement

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

the class AbstractMultiModeOutlineTreeProvider method createNodeForFeature.

protected XtendFeatureNode createNodeForFeature(IOutlineNode parentNode, final JvmDeclaredType inferredType, EObject featureElement, int inheritanceDepth) {
    boolean synthetic = false;
    if (featureElement instanceof JvmFeature) {
        synthetic = typeExtensions.isSynthetic((JvmIdentifiableElement) featureElement);
    }
    Object text = computeDecoratedText(featureElement, inheritanceDepth);
    ImageDescriptor image = getImageDescriptor(featureElement);
    if (isShowInherited()) {
        return getOutlineNodeFactory().createXtendFeatureNode(parentNode, featureElement, image, text, true, synthetic, inheritanceDepth);
    }
    return getOutlineNodeFactory().createXtendFeatureNode(parentNode, featureElement, image, text, true, synthetic, inheritanceDepth);
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) EObject(org.eclipse.emf.ecore.EObject) JavaElementImageDescriptor(org.eclipse.jdt.ui.JavaElementImageDescriptor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)

Example 43 with JvmIdentifiableElement

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

the class XtendQuickfixProvider method specifyTypeExplicitly.

@Fix(IssueCodes.API_TYPE_INFERENCE)
public void specifyTypeExplicitly(Issue issue, IssueResolutionAcceptor acceptor) {
    acceptor.accept(issue, "Infer type", "Infer type", null, new ISemanticModification() {

        @Override
        public void apply(EObject element, IModificationContext context) throws Exception {
            EStructuralFeature featureAfterType = null;
            JvmIdentifiableElement jvmElement = null;
            if (element instanceof XtendFunction) {
                XtendFunction function = (XtendFunction) element;
                if (function.getCreateExtensionInfo() == null) {
                    featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__NAME;
                } else {
                    featureAfterType = XtendPackage.Literals.XTEND_FUNCTION__CREATE_EXTENSION_INFO;
                }
                jvmElement = associations.getDirectlyInferredOperation((XtendFunction) element);
            } else if (element instanceof XtendField) {
                featureAfterType = XtendPackage.Literals.XTEND_FIELD__NAME;
                jvmElement = associations.getJvmField((XtendField) element);
            }
            if (jvmElement != null) {
                LightweightTypeReference type = batchTypeResolver.resolveTypes(element).getActualType(jvmElement);
                INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(element, featureAfterType), null);
                if (node == null) {
                    throw new IllegalStateException("Could not determine node for " + element);
                }
                if (type == null) {
                    throw new IllegalStateException("Could not determine type for " + element);
                }
                ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) element.eResource(), node.getOffset(), 0);
                appendable.append(type);
                appendable.append(" ");
                appendable.commitChanges();
            }
        }
    });
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) INode(org.eclipse.xtext.nodemodel.INode) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) ISemanticModification(org.eclipse.xtext.ui.editor.model.edit.ISemanticModification) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) XtextResource(org.eclipse.xtext.resource.XtextResource) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) XtendField(org.eclipse.xtend.core.xtend.XtendField) EObject(org.eclipse.emf.ecore.EObject) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 44 with JvmIdentifiableElement

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

the class XtendReferenceFinder method addReferenceToTypeFromStaticImport.

protected void addReferenceToTypeFromStaticImport(final XAbstractFeatureCall sourceCandidate, final Predicate<URI> targetURISet, final IReferenceFinder.Acceptor acceptor) {
    final JvmIdentifiableElement feature = sourceCandidate.getFeature();
    if ((feature instanceof JvmMember)) {
        final JvmDeclaredType type = ((JvmMember) feature).getDeclaringType();
        this.addReferenceIfTarget(type, targetURISet, sourceCandidate, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor);
    }
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 45 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement 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)

Aggregations

JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)91 Test (org.junit.Test)65 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)63 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)60 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)58 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)39 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)26 EObject (org.eclipse.emf.ecore.EObject)13 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)9 XExpression (org.eclipse.xtext.xbase.XExpression)9 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)7 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)7 XtendField (org.eclipse.xtend.core.xtend.XtendField)5 JvmType (org.eclipse.xtext.common.types.JvmType)5 XtextResource (org.eclipse.xtext.resource.XtextResource)5 Resource (org.eclipse.emf.ecore.resource.Resource)4 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)4 JvmMember (org.eclipse.xtext.common.types.JvmMember)4 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)3