use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.
the class StaticPolyfillHelper method findStaticPolyfiller.
/**
* Find the corresponding static-polyfill to this {@code @@PolyfillAware} resource in the same project. returns null
* if not found or this resource has no {@code @@PolyfillAware} annotation.
*/
public URI findStaticPolyfiller(Resource resource) {
// ensure right resource
if (resource instanceof N4JSResource) {
final N4JSResource res = (N4JSResource) resource;
if (!isContainedInStaticPolyfillAware(res.getScript()))
return null;
final QualifiedName qnFilled = qualifiedNameConverter.toQualifiedName(res.getModule().getQualifiedName());
final IN4JSProject project = projectResolver.resolveProject(res.getURI());
final QualifiedName fqn = qnFilled;
// see Req.155#4: "Both
final Optional<String> fileExtension = Optional.of(res.getURI().fileExtension());
// extensions are
// equal."
final IN4JSSourceContainer filledSrcContainer = n4jsCore.findN4JSSourceContainer(res.getURI()).get();
for (IN4JSSourceContainer srcConti : project.getSourceContainers()) {
if (!Objects.equals(filledSrcContainer, srcConti)) {
final URI uri = srcConti.findArtifact(fqn, fileExtension);
if (uri != null) {
return uri;
}
}
}
}
return null;
}
use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.
the class N4JSDReader method readScripts.
/**
* Reads all N4JSD files in project and scans for types. No further information is added yet. Reads all types into a
* map with fully qualified type name (inclusive module spec) as key, the type info only contains the types, no
* other information yet.
*
* @param specInfoByName
* map of fqn of types or reqid keys to their corresponding spec info.
* @throws InterruptedException
* thrown when user cancels the operation
*/
private void readScripts(Multimap<String, SpecInfo> specInfoByName, IN4JSProject project, ResourceSet resSet, SubMonitorMsg monitor) throws InterruptedException {
ImmutableList<? extends IN4JSSourceContainer> srcCont = project.getSourceContainers();
List<IN4JSSourceContainer> srcContFilter = new LinkedList<>();
int count = 0;
for (IN4JSSourceContainer container : srcCont) {
if (container.isSource() || container.isTest()) {
count += Iterables.size(container);
srcContFilter.add(container);
}
}
SubMonitorMsg sub = monitor.convert(count);
for (IN4JSSourceContainer container : srcContFilter) {
for (URI uri : container) {
String ext = uri.fileExtension();
if ("n4js".equals(ext) || "n4jsd".equals(ext)) {
try {
Resource resource = resSet.getResource(uri, true);
if (resource != null) {
Script script = (Script) (resource.getContents().isEmpty() ? null : resource.getContents().get(0));
if (script == null) {
// throw new IllegalStateException("Error parsing " + uri);
continue;
}
N4JSResource.postProcess(resource);
for (Type type : getRealTopLevelTypes(script)) {
createTypeSpecInfo(type, specInfoByName);
}
for (TVariable tvar : script.getModule().getVariables()) {
createTVarSpecInfo(tvar, specInfoByName);
}
}
} catch (Exception ex) {
ex.printStackTrace();
String msg = "Error processing " + uri + ": " + ex.getMessage();
throw new IllegalArgumentException(msg, ex);
}
}
sub.worked(1);
sub.checkCanceled();
}
}
}
use of org.eclipse.n4js.projectModel.IN4JSSourceContainer in project n4js by eclipse.
the class N4JSDReader method getTestTypes.
private List<Type> getTestTypes(IN4JSProject project, ResourceSet resSet, SubMonitorMsg monitor) throws InterruptedException {
List<Type> testTypes = new ArrayList<>();
ImmutableList<? extends IN4JSSourceContainer> srcCont = project.getSourceContainers();
// count container
int count = 0;
for (IN4JSSourceContainer container : srcCont) {
if (container.isTest()) {
count += Iterables.size(container);
}
}
SubMonitorMsg sub = monitor.convert(count);
// scan for types
for (IN4JSSourceContainer container : srcCont) {
if (container.isTest()) {
for (URI uri : container) {
String ext = uri.fileExtension();
if ("n4js".equals(ext)) {
Resource resource = resSet.getResource(uri, true);
if (resource != null) {
Script script = (Script) (resource.getContents().isEmpty() ? null : resource.getContents().get(0));
if (script == null) {
throw new IllegalStateException("Error parsing " + uri);
}
N4JSResource.postProcess(resource);
for (Type type : getRealTopLevelTypes(script)) {
testTypes.add(type);
}
}
}
sub.worked(1);
sub.checkCanceled();
}
}
}
return testTypes;
}
Aggregations