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);
}
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);
}
}
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();
}
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;
}
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));
}
}
Aggregations