use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class VirtualBaseTypeScope 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) {
// only virtualBase children.
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 OriginAwareScope method getSingleElement.
/**
* Enhanced query-Method marking the originating import as used.
*
* @see org.eclipse.xtext.scoping.IScope#getSingleElement(org.eclipse.xtext.naming.QualifiedName)
*/
@Override
public IEObjectDescription getSingleElement(QualifiedName name) {
IEObjectDescription ret = delegatee.getSingleElement(name);
if (ret == null)
return null;
ImportSpecifier origin = origins.get(ret);
if (origin != null) {
EObject script = EcoreUtil.getRootContainer(origin);
if ((script instanceof Script) && ((Script) script).isFlaggedUsageMarkingFinished()) {
// do nothing as linking phase is over
} else {
// return usage aware description
return getUsageAwareDescription(ret);
}
}
return ret;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class ComposedMemberDescriptionWithError method initialize.
private boolean initialize() {
if (message == null) {
IEObjectDescription[] descriptions = new IEObjectDescription[subScopes.length];
// use string here, since EnumLiteral is
MapOfIndexes<String> indexesPerMemberType = new MapOfIndexes<>();
// not a TMember!
MapOfIndexes<String> indexesPerCode = new MapOfIndexes<>();
List<String> missingFrom = new ArrayList<>();
final QualifiedName name = getName();
boolean readOnlyField = false;
for (int i = 0; i < max; i++) {
IEObjectDescription description = subScopes[i].getSingleElement(name);
if (description != null) {
descriptions[i] = description;
EObject eobj = description.getEObjectOrProxy();
String type = getMemberTypeName(eobj);
indexesPerMemberType.add(type, i);
if (description instanceof IEObjectDescriptionWithError) {
String subCode = ((IEObjectDescriptionWithError) description).getIssueCode();
indexesPerCode.add(subCode, i);
}
if ("field".equals(type)) {
readOnlyField |= !((TField) eobj).isWriteable();
}
} else {
missingFrom.add(getNameForSubScope(i));
}
}
return initMessageAndCode(missingFrom, indexesPerMemberType, name, readOnlyField, descriptions, indexesPerCode);
}
return false;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class ComposedMemberScope method getAllLocalElements.
/**
* Returns all elements of union. No erroneous descriptions (instances of IEObjectDescriptionWithError) will be
* considered here, as we assume this method to be called from content assist and we do not want to show wrong
* elements. These descriptions will be returned by {@link #getSingleElement(QualifiedName)} though to show errors
* in case of explicit references to these members.
*/
@Override
protected Iterable<IEObjectDescription> getAllLocalElements() {
// collect all names from subScopes
final Set<String> names = new HashSet<>();
for (IScope currSubScope : subScopes) {
try {
for (IEObjectDescription currDesc : currSubScope.getAllElements()) {
// omit erroneous bindings (they will be provided in getSingleLocalElement... though)
if (!(currDesc instanceof IEObjectDescriptionWithError)) {
String name = currDesc.getName().getLastSegment();
names.add(name);
}
}
} catch (UnsupportedOperationException e) {
// according to API doc of IScope#getAllElements(), scopes are free to throw an
// UnsupportedOperationException --> therefore we catch and ignore this here
}
}
List<IEObjectDescription> descriptions = new ArrayList<>(names.size());
for (String name : names) {
IEObjectDescription description = getSingleLocalElementByName(QualifiedName.create(name));
if (description != null && !(description instanceof IEObjectDescriptionWithError)) {
descriptions.add(description);
}
}
return descriptions;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class ComposedMemberScope method getSingleLocalElementByName.
/**
* Returns description for given element, name is assumed to consist of a single segment containing the simple name
* of the member. If no subScope contains a member with given name, null is returned. In other error cases (no or
* wrong access, mixed types etc.), {@link IEObjectDescriptionWithError}, and in particular
* {@link UnionMemberDescriptionWithError}, will be returned.
*/
@Override
protected IEObjectDescription getSingleLocalElementByName(QualifiedName qualifiedName) {
String name = qualifiedName.getLastSegment();
TMember member = getOrCreateComposedMember(name);
if (member == null) {
// no such member, no need for "merging" descriptions, there won't be any
return null;
}
if (isErrorPlaceholder(member)) {
return createComposedMemberDescriptionWithErrors(EObjectDescription.create(member.getName(), member));
}
IEObjectDescription description = getCheckedDescription(name, member);
return description;
}
Aggregations