Search in sources :

Example 6 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-eclipse by eclipse.

the class AbstractScopeResourceDescriptionsTest method assertExportedObject.

protected void assertExportedObject(Resource resource, String name) {
    IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(resource);
    IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(resource.getURI());
    assertNotNull(resourceDescription);
    QualifiedName qname = QualifiedName.create(name);
    assertFalse(isEmpty(resourceDescription.getExportedObjects(EcorePackage.Literals.EOBJECT, qname, false)));
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 7 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-eclipse by eclipse.

the class XtextCallHierarchyLabelProvider method _getStyledText.

protected StyledString _getStyledText(final XtextCallHierarchyNode it) {
    IEObjectDescription _element = it.getElement();
    boolean _tripleEquals = (_element == null);
    if (_tripleEquals) {
        return this.hierarchyLabelProvider.getStyledText(it);
    }
    QualifiedName _qualifiedName = it.getElement().getQualifiedName();
    String _plus = ("" + _qualifiedName);
    final StyledString styledString = new StyledString(_plus);
    IEObjectDescription _grammarDescription = it.getGrammarDescription();
    boolean _tripleEquals_1 = (_grammarDescription == null);
    if (_tripleEquals_1) {
        return styledString;
    }
    QualifiedName _qualifiedName_1 = it.getGrammarDescription().getQualifiedName();
    String _plus_1 = (" - " + _qualifiedName_1);
    StyledString _styledString = new StyledString(_plus_1, StyledString.QUALIFIER_STYLER);
    return styledString.append(_styledString);
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 8 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-eclipse by eclipse.

the class XtextProposalProvider method getStyledDisplayString.

@Override
protected StyledString getStyledDisplayString(IEObjectDescription description) {
    if (EcorePackage.Literals.EPACKAGE == description.getEClass()) {
        if ("true".equals(description.getUserData("nsURI"))) {
            String name = description.getUserData("name");
            if (name == null) {
                return new StyledString(description.getName().toString());
            }
            String string = name + " - " + description.getName();
            return new StyledString(string);
        }
    } else if (XtextPackage.Literals.GRAMMAR == description.getEClass()) {
        QualifiedName qualifiedName = description.getQualifiedName();
        if (qualifiedName.getSegmentCount() > 1) {
            return new StyledString(qualifiedName.getLastSegment() + " - " + qualifiedName.toString());
        }
        return new StyledString(qualifiedName.toString());
    } else if (XtextPackage.Literals.ABSTRACT_RULE.isSuperTypeOf(description.getEClass())) {
        EObject object = description.getEObjectOrProxy();
        if (!object.eIsProxy()) {
            AbstractRule rule = (AbstractRule) object;
            Grammar grammar = GrammarUtil.getGrammar(rule);
            if (description instanceof EnclosingGrammarAwareDescription) {
                if (grammar == ((EnclosingGrammarAwareDescription) description).getGrammar()) {
                    return getStyledDisplayString(rule, null, rule.getName());
                }
            }
            return getStyledDisplayString(rule, grammar.getName() + "." + rule.getName(), description.getName().toString().replace(".", "::"));
        }
    }
    return super.getStyledDisplayString(description);
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 9 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-eclipse by eclipse.

the class XtextProposalProvider method createClassifierProposals.

private void createClassifierProposals(AbstractMetamodelDeclaration declaration, EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    String alias = declaration.getAlias();
    QualifiedName prefix = (!Strings.isEmpty(alias)) ? QualifiedName.create(getValueConverter().toString(alias, grammarAccess.getValidIDRule().getName())) : null;
    boolean createDatatypeProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, AbstractRule.class);
    boolean createEnumProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, EnumRule.class);
    boolean createClassProposals = modelOrContainerIs(model, ParserRule.class, CrossReference.class, Action.class);
    Function<IEObjectDescription, ICompletionProposal> factory = new DefaultProposalCreator(context, null, classifierQualifiedNameConverter);
    for (EClassifier classifier : declaration.getEPackage().getEClassifiers()) {
        if (classifier instanceof EDataType && createDatatypeProposals || classifier instanceof EEnum && createEnumProposals || classifier instanceof EClass && createClassProposals) {
            String classifierName = getValueConverter().toString(classifier.getName(), grammarAccess.getValidIDRule().getName());
            QualifiedName proposalQualifiedName = (prefix != null) ? prefix.append(classifierName) : QualifiedName.create(classifierName);
            IEObjectDescription description = EObjectDescription.create(proposalQualifiedName, classifier);
            ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) factory.apply(description);
            if (proposal != null) {
                if (prefix != null)
                    proposal.setDisplayString(classifier.getName() + " - " + alias);
                proposal.setPriority(proposal.getPriority() * 2);
            }
            acceptor.accept(proposal);
        }
    }
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EDataType(org.eclipse.emf.ecore.EDataType) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EClassifier(org.eclipse.emf.ecore.EClassifier) StyledString(org.eclipse.jface.viewers.StyledString) EEnum(org.eclipse.emf.ecore.EEnum) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EnumRule(org.eclipse.xtext.EnumRule) EClass(org.eclipse.emf.ecore.EClass) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 10 with QualifiedName

use of org.eclipse.xtext.naming.QualifiedName in project xtext-eclipse by eclipse.

the class EcoreRefactoringParticipant method getRenamedElementsOrProxies.

@Override
protected List<EObject> getRenamedElementsOrProxies(EObject originalTarget) {
    if (originalTarget instanceof ParserRule) {
        TypeRef returnType = ((ParserRule) originalTarget).getType();
        if (returnType != null && returnType.getClassifier() != null && !Strings.isEmpty(returnType.getClassifier().getName()) && equal(((ParserRule) originalTarget).getName(), returnType.getClassifier().getName()) && returnType.getClassifier().eClass() != null && returnType.getClassifier().getEPackage() != null && !Strings.isEmpty(returnType.getClassifier().getEPackage().getNsURI())) {
            String packageNsURI = returnType.getClassifier().getEPackage().getNsURI();
            QualifiedName classifierQualifiedName = QualifiedName.create(packageNsURI, returnType.getClassifier().getName());
            URI platformResourceURI = findPlatformResourceURI(classifierQualifiedName, EcorePackage.Literals.ECLASS);
            if (platformResourceURI == null) {
                if (returnType.getMetamodel() instanceof ReferencedMetamodel)
                    getStatus().add(ERROR, "Return type '{0}' is not indexed.", returnType.getClassifier());
            } else {
                EObject classifierProxy = EcoreFactory.eINSTANCE.create(returnType.getClassifier().eClass());
                ((InternalEObject) classifierProxy).eSetProxyURI(platformResourceURI);
                if (!isDisableWarning)
                    getStatus().add(WARNING, "Renaming EClass '{0}' in ecore file. Please rerun the Ecore generator.", returnType.getClassifier());
                return singletonList(classifierProxy);
            }
        }
    }
    return null;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) TypeRef(org.eclipse.xtext.TypeRef) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) URI(org.eclipse.emf.common.util.URI) ReferencedMetamodel(org.eclipse.xtext.ReferencedMetamodel) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Aggregations

QualifiedName (org.eclipse.xtext.naming.QualifiedName)215 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)78 EObject (org.eclipse.emf.ecore.EObject)46 Test (org.junit.Test)46 URI (org.eclipse.emf.common.util.URI)24 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)21 IScope (org.eclipse.xtext.scoping.IScope)21 EClass (org.eclipse.emf.ecore.EClass)18 Resource (org.eclipse.emf.ecore.resource.Resource)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)13 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 Set (java.util.Set)10 StyledString (org.eclipse.jface.viewers.StyledString)8 JvmType (org.eclipse.xtext.common.types.JvmType)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Grammar (org.eclipse.xtext.Grammar)6 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)6 HashMap (java.util.HashMap)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5