Exemplo n.º 1
0
  public static ISourceModule resolveSourceModule(FileStoreEditorInput input) {
    final ISourceModule[] modules = new ISourceModule[1];
    final IPath filePath = URIUtil.toPath(input.getURI());
    IScriptModel scriptModel = DLTKCore.create(ResourcesPlugin.getWorkspace().getRoot());
    try {
      scriptModel.accept(
          new IModelElementVisitor() {

            public boolean visit(IModelElement element) {
              boolean shouldDescend = (modules[0] == null);

              if (shouldDescend == true) {
                if (element instanceof ExternalProjectFragment) {
                  ExternalProjectFragment fragment = (ExternalProjectFragment) element;

                  try {
                    if (filePath
                            .removeLastSegments(1)
                            .toFile()
                            .getCanonicalPath()
                            .startsWith(fragment.getPath().toFile().getCanonicalPath())
                        == true) {
                      IPath folderPath =
                          new Path(filePath.removeLastSegments(1).toFile().getCanonicalPath());
                      folderPath =
                          folderPath.removeFirstSegments(
                              new Path(fragment.getPath().toFile().getCanonicalPath())
                                  .segmentCount());
                      IScriptFolder folder = fragment.getScriptFolder(folderPath);
                      if ((folder != null) && (folder.exists() == true)) {
                        ISourceModule module = folder.getSourceModule(filePath.lastSegment());
                        if (module != null) {
                          modules[0] = module;
                        }
                      }
                    }
                  } catch (IOException ixcn) {
                    ixcn.printStackTrace();
                  }

                  shouldDescend = false;
                } else {
                  shouldDescend =
                      ((element instanceof IScriptProject) || (element instanceof IScriptModel));
                }
              }

              return shouldDescend;
            }
          });
    } catch (ModelException mxcn) {
      mxcn.printStackTrace();
    }

    return modules[0];
  }
 @Override
 public Set<IScriptProject> collectProjects() {
   final Set<IScriptProject> projects = new HashSet<IScriptProject>();
   final IScriptModel model = DLTKCore.create(ResourcesPlugin.getWorkspace().getRoot());
   try {
     for (IScriptProject project : model.getScriptProjects(TclNature.NATURE_ID)) {
       InstrumentationUtils.collectProjects(model, projects, project);
     }
   } catch (CoreException e) {
     if (DLTKCore.DEBUG) {
       e.printStackTrace();
     }
   }
   return projects;
 }
Exemplo n.º 3
0
  /**
   * Add a path to current script search scope or all project fragment roots if null. Use project
   * resolved classpath to retrieve and store access restriction on each classpath entry. Recurse if
   * dependent projects are found.
   *
   * @param scriptProject Project used to get resolved classpath entries
   * @param pathToAdd Path to add in case of single element or null if user want to add all project
   *     package fragment roots
   * @param includeMask Mask to apply on buildpath entries
   * @param visitedProjects Set to avoid infinite recursion
   * @param referringEntry Project raw entry in referring project buildpath
   * @throws ModelException May happen while getting script model info
   */
  void add(
      ScriptProject scriptProject,
      IPath pathToAdd,
      int includeMask,
      HashSet<IProject> visitedProjects,
      IBuildpathEntry referringEntry)
      throws ModelException {
    if (!natureFilter(scriptProject)) {
      return;
    }
    IProject project = scriptProject.getProject();
    if (!project.isAccessible() || !visitedProjects.add(project)) return;

    IPath projectPath = project.getFullPath();
    String projectPathString = projectPath.toString();
    this.addEnclosingProjectOrArchive(projectPath);

    // Iterate via project fragments without buildpath entries
    IProjectFragment[] fragments = scriptProject.getProjectFragments();
    for (int i = 0; i < fragments.length; i++) {
      if (fragments[i].getRawBuildpathEntry() == null) {
        add(fragments[i]);
      }
    }

    IBuildpathEntry[] entries = scriptProject.getResolvedBuildpath();
    IScriptModel model = scriptProject.getModel();
    ModelManager.PerProjectInfo perProjectInfo = scriptProject.getPerProjectInfo();
    for (int i = 0, length = entries.length; i < length; i++) {
      IBuildpathEntry entry = entries[i];
      AccessRuleSet access = null;
      BuildpathEntry cpEntry = (BuildpathEntry) entry;
      if (referringEntry != null) {
        // Add only exported entries.
        // Source folder are implicitly exported.
        if (!entry.isExported() && entry.getEntryKind() != IBuildpathEntry.BPE_SOURCE) continue;
        cpEntry = cpEntry.combineWith((BuildpathEntry) referringEntry);
        // cpEntry =
        // ((BuildpathEntry)referringEntry).combineWith(cpEntry);
      }
      access = cpEntry.getAccessRuleSet();
      switch (entry.getEntryKind()) {
        case IBuildpathEntry.BPE_LIBRARY:
          IBuildpathEntry rawEntry = null;
          Map<IPath, IBuildpathEntry> rootPathToRawEntries = perProjectInfo.rootPathToRawEntries;
          if (rootPathToRawEntries != null) {
            rawEntry = rootPathToRawEntries.get(entry.getPath());
          }
          if (rawEntry == null) {
            break;
          }
          switch (rawEntry.getEntryKind()) {
            case IBuildpathEntry.BPE_LIBRARY:
            case IBuildpathEntry.BPE_VARIABLE:
              if ((includeMask & APPLICATION_LIBRARIES) != 0) {
                IPath path = entry.getPath();
                if (pathToAdd == null || pathToAdd.equals(path)) {
                  String pathToString = path.toString();
                  add(
                      projectPath.toString(),
                      "",
                      pathToString,
                      false /* not a package */,
                      access); //$NON-NLS-1$
                  addEnclosingProjectOrArchive(path);
                }
              }
              break;
            case IBuildpathEntry.BPE_CONTAINER:
              IBuildpathContainer container =
                  DLTKCore.getBuildpathContainer(rawEntry.getPath(), scriptProject);
              if (container == null) break;
              if ((container.getKind() == IBuildpathContainer.K_APPLICATION
                      && (includeMask & APPLICATION_LIBRARIES) != 0)
                  || (includeMask & SYSTEM_LIBRARIES) != 0) {
                IPath path = entry.getPath();
                if (pathToAdd == null || pathToAdd.equals(path)) {
                  String pathToString = path.toString();
                  add(
                      projectPath.toString(),
                      "",
                      pathToString,
                      false /* not a package */,
                      access); //$NON-NLS-1$
                  addEnclosingProjectOrArchive(path);
                }
              }
              break;
          }
          break;
        case IBuildpathEntry.BPE_PROJECT:
          if ((includeMask & REFERENCED_PROJECTS) != 0) {
            IPath path = entry.getPath();
            if (pathToAdd == null || pathToAdd.equals(path)) {
              add(
                  (ScriptProject) model.getScriptProject(entry.getPath().lastSegment()),
                  null,
                  includeMask,
                  visitedProjects,
                  cpEntry);
            }
          }
          break;
        case IBuildpathEntry.BPE_SOURCE:
          if ((includeMask & SOURCES) != 0) {
            IPath path = entry.getPath();
            if (pathToAdd == null || pathToAdd.equals(path)) {
              add(
                  projectPath.toString(),
                  Util.relativePath(path, 1 /*
														 * remove project
														 * segment
														 */),
                  projectPathString,
                  false /*
                         * not a package
                         */,
                  access);
            }
          }
          break;
      }
    }
  }
 private Object[] getNonJavaProjects(final IScriptModel model) throws ModelException {
   return model.getForeignResources();
 }