Search in sources :

Example 21 with QualifiedName

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

the class ReferenceUpdater method needsUpdating.

protected boolean needsUpdating(IReferenceUpdaterContext context, IUpdatableReference ref) {
    QualifiedName fqn = getQualifiedName(ref);
    if (fqn == null) {
        return false;
    }
    EObject target = ref.getTargetEObject();
    Deltas deltas = context.getEObjectDescriptionDeltas();
    Delta delta = deltas.getDelta(target);
    if (delta != null && !containsReferenceText(delta, fqn)) {
        return true;
    }
    Delta targetDelta = findContainingDelta(deltas, target);
    if (targetDelta != null && targetDelta.getObject() == target) {
        return true;
    }
    Delta sourceDelta = findContainingDelta(deltas, ref.getSourceEObject());
    return !Objects.equal(sourceDelta, targetDelta);
}
Also used : Deltas(org.eclipse.xtext.ide.serializer.impl.EObjectDescriptionDeltaProvider.Deltas) Delta(org.eclipse.xtext.ide.serializer.impl.EObjectDescriptionDeltaProvider.Delta) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject)

Example 22 with QualifiedName

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

the class ReferenceUpdater method updateReference.

@Override
public void updateReference(ITextRegionDiffBuilder rewriter, IUpdatableReference upd) {
    IUpdatableReference updatable = upd;
    if (rewriter.isModified(updatable.getReferenceRegion())) {
        return;
    }
    IScope scope = scopeProvider.getScope(updatable.getSourceEObject(), updatable.getEReference());
    ISemanticRegion region = updatable.getReferenceRegion();
    QualifiedName oldName = nameConverter.toQualifiedName(region.getText());
    IEObjectDescription oldDesc = scope.getSingleElement(oldName);
    if (oldDesc != null && oldDesc.getEObjectOrProxy() == updatable.getTargetEObject()) {
        return;
    }
    String newName = findValidName(updatable, scope);
    if (newName != null) {
        rewriter.replace(region, newName);
    }
}
Also used : IUpdatableReference(org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 23 with QualifiedName

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

the class XtextLinkingService method getPackage.

private List<EObject> getPackage(ReferencedMetamodel context, ILeafNode text) {
    String nsUri = getMetamodelNsURI(text);
    if (nsUri == null)
        return Collections.emptyList();
    Grammar grammar = GrammarUtil.getGrammar(context);
    Set<Grammar> visitedGrammars = new HashSet<Grammar>();
    for (Grammar usedGrammar : grammar.getUsedGrammars()) {
        List<EObject> result = getPackage(nsUri, usedGrammar, visitedGrammars);
        if (result != null)
            return result;
    }
    QualifiedName packageNsURI = QualifiedName.create(nsUri);
    EPackage pack = findPackageInScope(context, packageNsURI);
    if (pack == null) {
        pack = findPackageInAllDescriptions(context, packageNsURI);
        if (pack == null) {
            pack = loadEPackage(nsUri, context.eResource().getResourceSet());
        }
    }
    if (pack != null)
        return Collections.<EObject>singletonList(pack);
    return Collections.emptyList();
}
Also used : EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Grammar(org.eclipse.xtext.Grammar) HashSet(java.util.HashSet) EPackage(org.eclipse.emf.ecore.EPackage)

Example 24 with QualifiedName

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

the class XtextResourceDescriptionStrategy method createEObjectDescriptions.

@Override
public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
    if (eObject instanceof Grammar) {
        String grammarName = ((Grammar) eObject).getName();
        if (!Strings.isEmpty(grammarName)) {
            QualifiedName qualifiedName = defaultQualifiedNameConverter.toQualifiedName(grammarName);
            acceptor.accept(EObjectDescription.create(qualifiedName, eObject));
        }
    } else if (eObject instanceof AbstractMetamodelDeclaration || eObject instanceof AbstractRule)
        return super.createEObjectDescriptions(eObject, acceptor);
    return eObject instanceof Grammar;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) Grammar(org.eclipse.xtext.Grammar) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 25 with QualifiedName

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

the class NamesAreUniqueValidatorTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    context = Maps.newHashMap();
    validator = new NamesAreUniqueValidator() {

        @Override
        protected Map<Object, Object> getContext() {
            return context;
        }
    };
    validator.setResourceServiceProviderRegistry(this);
    validator.setHelper(this);
    final DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
    strategy.setQualifiedNameProvider(new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            return QualifiedName.create(SimpleAttributeResolver.NAME_RESOLVER.getValue(obj));
        }
    });
    resourceDescriptionManager = new DefaultResourceDescriptionManager() {

        @Override
        public IResourceDescription getResourceDescription(Resource resource) {
            DefaultResourceDescription resourceDescription = new DefaultResourceDescription(resource, strategy);
            return resourceDescription;
        }
    };
    callCount = 0;
    resource = new ResourceImpl();
    resource.getContents().add(EcoreFactory.eINSTANCE.createEClass());
    resource.getContents().add(EcoreFactory.eINSTANCE.createEClass());
    resource.getContents().add(EcoreFactory.eINSTANCE.createEClass());
    for (int i = 0; i < resource.getContents().size(); i++) {
        EClass clazz = (EClass) resource.getContents().get(i);
        clazz.setName(String.valueOf(i));
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) DefaultResourceDescription(org.eclipse.xtext.resource.impl.DefaultResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Resource(org.eclipse.emf.ecore.resource.Resource) DefaultResourceDescriptionManager(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager) EClass(org.eclipse.emf.ecore.EClass) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) EObject(org.eclipse.emf.ecore.EObject) DefaultResourceDescriptionStrategy(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy) Map(java.util.Map)

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