use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class N4JSResource method discardStateFromDescription.
/**
* Returns the {@link TModule} from the contents list and optionally proxifies the instance. Robust against broken
* state of the resource, e.g. can handle cases where the second element in the list is not of type TModule.
*
* @param unload
* set to true if the module should be proxified.
* @return the module at index 1 of the contents list (if any). Otherwise null.
* @throws IllegalStateException
* if the contents list has more than two elements.
*/
protected TModule discardStateFromDescription(boolean unload) {
ModuleAwareContentsList theContents = (ModuleAwareContentsList) contents;
if (theContents != null && !theContents.isEmpty()) {
if (theContents.size() == 2) {
EObject eObject = theContents.get(1);
if (eObject instanceof TModule) {
TModule module = (TModule) eObject;
if (unload) {
getUnloader().unloadRoot(module);
}
return module;
}
getUnloader().unloadRoot(eObject);
return null;
} else if (theContents.size() > 2) {
throw new IllegalStateException("Unexpected size: " + theContents);
}
}
return null;
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class N4JSResourceDescription method getImportedNames.
@Override
public Iterable<QualifiedName> getImportedNames() {
if (null == lazyImportedNames) {
synchronized (this) {
if (null == lazyImportedNames) {
// get imported names collected during global scoping
// the scope provider registers every request in scoping so that by this
// also all names are collected that cannot be resolved
Iterable<QualifiedName> superImportedNames = super.getImportedNames();
// use sorted set to ensure order of items
final SortedSet<QualifiedName> importedNames;
if (superImportedNames != null) {
importedNames = Sets.newTreeSet(superImportedNames);
} else {
importedNames = Sets.<QualifiedName>newTreeSet();
}
// import our own module name to get a proper change notification
Resource resource = getResource();
List<EObject> contents = resource.getContents();
if (contents.size() > 1) {
TModule module = (TModule) contents.get(1);
importedNames.add(qualifiedNameProvider.getFullyQualifiedName(module));
}
final Set<EObject> crossRefTypes = Sets.newHashSet();
IAcceptor<EObject> acceptor = getCrossRefTypeAcceptor(crossRefTypes);
crossReferenceComputer.computeCrossRefs(resource, acceptor);
for (EObject type : crossRefTypes) {
if (type instanceof Type) {
handleType(importedNames, type);
} else if (type instanceof TVariable) {
handleTVariable(importedNames, (TVariable) type);
} else if (type instanceof TEnumLiteral) {
handleTEnumLiteral(importedNames, (TEnumLiteral) type);
}
}
this.lazyImportedNames = importedNames;
}
}
}
return lazyImportedNames;
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class N4JSResourceDescriptionStrategy method createEObjectDescriptions.
@Override
public boolean createEObjectDescriptions(final EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
if (getQualifiedNameProvider() == null)
return false;
if (eObject instanceof TModule) {
TModule module = (TModule) eObject;
internalCreateEObjectDescriptionForRoot(module, acceptor);
for (Type type : module.getTopLevelTypes()) {
internalCreateEObjectDescription(type, acceptor);
}
for (TVariable variable : module.getVariables()) {
internalCreateEObjectDescription(variable, acceptor);
}
}
// export is only possible for top-level elements
return false;
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class UserdataMapper method getDeserializedModuleFromDescription.
/**
* Reads the TModule stored in the given IEObjectDescription.
*/
public static TModule getDeserializedModuleFromDescription(IEObjectDescription eObjectDescription, URI uri) {
final String serializedData = eObjectDescription.getUserData(USERDATA_KEY_SERIALIZED_SCRIPT);
if (Strings.isNullOrEmpty(serializedData)) {
return null;
}
final XMIResource xres = new XMIResourceImpl(uri);
try {
final boolean binary = !serializedData.startsWith("<");
final ByteArrayInputStream bais = new ByteArrayInputStream(binary ? XMLTypeFactory.eINSTANCE.createBase64Binary(serializedData) : serializedData.getBytes(TRANSFORMATION_CHARSET_NAME));
xres.load(bais, getOptions(uri, binary));
} catch (Exception e) {
// $NON-NLS-1$
LOGGER.warn("error deserializing module from IEObjectDescription: " + uri);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("error deserializing module from IEObjectDescription=" + eObjectDescription + ": " + uri, // $NON-NLS-1$
e);
}
// IDE, so the format could be out of date (after an update of the IDE))
return null;
}
final List<EObject> contents = xres.getContents();
if (contents.isEmpty() || !(contents.get(0) instanceof TModule)) {
return null;
}
final TModule module = (TModule) contents.get(0);
xres.getContents().clear();
return module;
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class AbstractTypeVisibilityChecker method isPublicInternalVisible.
private boolean isPublicInternalVisible(Resource contextResource, final T element) {
if (contextResource != null) {
final TModule contextModule = N4JSResource.getModule(contextResource);
final TModule elementModule = N4JSResource.getModule(element.eResource());
return elementModule == null || Strings.equal(contextModule.getVendorID(), elementModule.getVendorID());
}
return false;
}
Aggregations