Search in sources :

Example 1 with N4JSSourceFolderSnapshotForPackageJson

use of org.eclipse.n4js.workspace.N4JSSourceFolderSnapshotForPackageJson in project n4js by eclipse.

the class N4JSLanguageHelper method isDirectoryWithPackageJson.

private boolean isDirectoryWithPackageJson(IResourceDescriptions index, TModule targetModule, QualifiedName targetQN) {
    // NOTE: the following approach would be a more elegant implementation of this method, but would require a
    // different computation of FQNs for package.json files in source folders (in N4JSQualifiedNameProvider):
    // @formatter:off
    // Iterable<IEObjectDescription> matchingPackageJsonDesc = index.getExportedObjects(
    // JSONPackage.Literals.JSON_DOCUMENT,
    // targetQN.append(N4JSQualifiedNameProvider.PACKAGE_JSON_SEGMENT), false);
    // if (matchingPackageJsonDesc.iterator().hasNext()) {
    // return true;
    // }
    // @formatter:on
    N4JSProjectConfigSnapshot targetProject = replaceDefinitionProjectByDefinedProject(targetModule, workspaceAccess.findProjectContaining(targetModule), true);
    if (targetProject == null) {
        return false;
    }
    int segCount = targetQN.getSegments().size();
    String[] segments = new String[segCount + 1];
    for (int i = 0; i < segCount; i++) {
        segments[i] = targetQN.getSegments().get(i);
    }
    segments[segCount] = N4JSGlobals.PACKAGE_JSON;
    for (N4JSSourceFolderSnapshot srcFolder : targetProject.getSourceFolders()) {
        if (srcFolder instanceof N4JSSourceFolderSnapshotForPackageJson) {
            continue;
        }
        FileURI packageJsonURI = srcFolder.getPathAsFileURI().appendSegments(segments);
        if (index.getResourceDescription(packageJsonURI.toURI()) != null) {
            return true;
        }
    }
    return false;
}
Also used : FileURI(org.eclipse.n4js.workspace.locations.FileURI) N4JSSourceFolderSnapshotForPackageJson(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshotForPackageJson) N4JSProjectConfigSnapshot(org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot) N4JSSourceFolderSnapshot(org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot)

Aggregations

N4JSProjectConfigSnapshot (org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot)1 N4JSSourceFolderSnapshot (org.eclipse.n4js.workspace.N4JSSourceFolderSnapshot)1 N4JSSourceFolderSnapshotForPackageJson (org.eclipse.n4js.workspace.N4JSSourceFolderSnapshotForPackageJson)1 FileURI (org.eclipse.n4js.workspace.locations.FileURI)1