use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class FQNImporter method getActualReplacementString.
/**
* Return the to-be-inserted string if an existing import is present.
*/
@Override
public String getActualReplacementString(ConfigurableCompletionProposal proposal) {
String syntacticReplacementString = proposal.getReplacementString();
if (scope != null) {
final QualifiedName qualifiedName = applyValueConverter(syntacticReplacementString);
if (qualifiedName.getSegmentCount() == 1) {
return syntacticReplacementString;
}
final IEObjectDescription element = scope.getSingleElement(qualifiedName);
if (element != null) {
EObject resolved = EcoreUtil.resolve(element.getEObjectOrProxy(), context);
if (!resolved.eIsProxy()) {
IEObjectDescription description = findApplicableDescription(resolved, qualifiedName, true);
if (description != null) {
String multisegmentProposal = applyValueConverter(description.getName());
return multisegmentProposal;
}
}
}
}
return syntacticReplacementString;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class IsInScopeWithOptionalPositionPredicate method apply.
@Override
public boolean apply(String nameWithPosition) {
String name = getNameFromNameWithPosition(nameWithPosition);
String position = getPositionFromNameWithPosition(nameWithPosition);
QualifiedName qualifiedName = converter.toQualifiedName(name);
IEObjectDescription desc = scope.getSingleElement(qualifiedName);
if (desc != null && !(desc instanceof IEObjectDescriptionWithError) && !(desc instanceof UnresolvableObjectDescription)) {
if (!Strings.isNullOrEmpty(position)) {
String nameWithPositionOfScopeELement = descriptionToNameWithPosition(currentURI, withLineNumber, desc);
String positionOfScopeElement = getPositionFromNameWithPosition(nameWithPositionOfScopeELement);
if (position.equals(positionOfScopeElement)) {
return true;
}
} else {
return true;
}
}
return false;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class BuiltInTypeScope method buildMap.
@Override
protected void buildMap(Resource resource, Map<QualifiedName, IEObjectDescription> elements) {
TypeDefs typeDefinitions = (TypeDefs) resource.getContents().get(0);
for (Type type : typeDefinitions.getTypes()) {
if (!(type instanceof VirtualBaseType)) {
IEObjectDescription description = EObjectDescription.create(type.getName(), type);
elements.put(description.getName(), description);
}
}
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class EnumerableScope method getEObjectOrProxy.
/**
* Returns a reference to the instance with the given qualified name.
*
* @return an optional reference.
*/
protected <T extends EObject> T getEObjectOrProxy(QualifiedName qn) {
IEObjectDescription description = getSingleElement(qn);
if (description == null)
throw new IllegalStateException(qn + " is not contained in this scope");
@SuppressWarnings("unchecked") T result = (T) description.getEObjectOrProxy();
return result;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class BuiltInTypeScopeTest method testLoadingBuiltInTypes.
@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
Assert.assertNotNull(anyType);
String s = "";
for (Resource resource : resourceSet.getResources()) {
if (resource.getErrors().size() > 0) {
for (Diagnostic d : resource.getErrors()) {
s += "\n " + d.getMessage() + " at " + resource.getURI() + ":" + d.getLine();
}
}
}
Assert.assertEquals("Resources definine built-in types must have no error.", "", s);
}
Aggregations