예제 #1
0
  public static void addEGLPathToJavaPathIfNecessary(
      IJavaProject javaProject, IProject currProject, Set<IProject> seen, List<String> classpath) {
    if (seen.contains(currProject)) {
      return;
    }
    seen.add(currProject);

    try {
      if (currProject.hasNature(EGLCore.NATURE_ID)) {
        IEGLProject eglProject = EGLCore.create(currProject);
        for (IEGLPathEntry pathEntry : eglProject.getResolvedEGLPath(true)) {
          if (pathEntry.getEntryKind() == IEGLPathEntry.CPE_PROJECT) {
            IPath path = pathEntry.getPath();
            IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
            try {
              if (resource != null
                  && resource.getType() == IResource.PROJECT
                  && !seen.contains(resource)
                  && ((IProject) resource).hasNature(JavaCore.NATURE_ID)
                  && !javaProject.isOnClasspath(resource)) {
                classpath.add(getWorkspaceProjectClasspathEntry(resource.getName()));
                addEGLPathToJavaPathIfNecessary(javaProject, (IProject) resource, seen, classpath);
              }
            } catch (CoreException ce) {
            }
          }
        }
      }
    } catch (EGLModelException e) {
    } catch (CoreException e) {
    }
  }
  /*
   * Removes the classpath entry equal to the given path from the given project's classpath.
   */
  protected void removeEntryFromClasspath(IPath rootPath, IEGLProject project)
      throws EGLModelException {

    IEGLPathEntry[] classpath = project.getRawEGLPath();
    IEGLPathEntry[] newClasspath = null;
    int cpLength = classpath.length;
    int newCPIndex = -1;

    for (int i = 0; i < cpLength; i++) {
      IEGLPathEntry entry = classpath[i];
      if (rootPath.equals(entry.getPath())) {
        if (newClasspath == null) {
          newClasspath = new IEGLPathEntry[cpLength];
          System.arraycopy(classpath, 0, newClasspath, 0, i);
          newCPIndex = i;
        }
      } else if (newClasspath != null) {
        newClasspath[newCPIndex++] = entry;
      }
    }

    if (newClasspath != null) {
      if (newCPIndex < newClasspath.length) {
        System.arraycopy(
            newClasspath, 0, newClasspath = new IEGLPathEntry[newCPIndex], 0, newCPIndex);
      }
      project.setRawEGLPath(newClasspath, fMonitor);
    }
  }
 /*
  * Renames the classpath entries equal to the given path in all Java projects.
  */
 protected void updateReferringProjectClasspaths(IPath rootPath, IEGLProject projectOfRoot)
     throws EGLModelException {
   IEGLModel model = this.getEGLModel();
   IEGLProject[] projects = model.getEGLProjects();
   for (int i = 0, length = projects.length; i < length; i++) {
     IEGLProject project = projects[i];
     if (project.equals(projectOfRoot)) continue;
     renameEntryInClasspath(rootPath, project);
   }
 }
  protected void executeOperation() throws EGLModelException {

    IPackageFragmentRoot root = (IPackageFragmentRoot) this.getElementToProcess();
    IEGLPathEntry rootEntry = root.getRawEGLPathEntry();
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

    // move resource
    if (!root.isExternal()
        && (this.updateModelFlags & IPackageFragmentRoot.NO_RESOURCE_MODIFICATION) == 0) {
      moveResource(root, rootEntry, workspaceRoot);
    }

    // update refering projects classpath excluding orignating project
    IEGLProject originatingProject = root.getEGLProject();
    if ((this.updateModelFlags & IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_EGLPATH) != 0) {
      updateReferringProjectClasspaths(rootEntry.getPath(), originatingProject);
    }

    boolean isRename = this.destination.segment(0).equals(originatingProject.getElementName());
    boolean updateOriginating =
        (this.updateModelFlags & IPackageFragmentRoot.ORIGINATING_PROJECT_EGLPATH) != 0;
    boolean updateDestination =
        (this.updateModelFlags & IPackageFragmentRoot.DESTINATION_PROJECT_EGLPATH) != 0;

    // update originating classpath
    if (updateOriginating) {
      if (isRename && updateDestination) {
        renameEntryInClasspath(rootEntry.getPath(), originatingProject);
      } else {
        removeEntryFromClasspath(rootEntry.getPath(), originatingProject);
      }
    }

    // update destination classpath
    if (updateDestination) {
      if (!isRename || !updateOriginating) {
        addEntryToEGLPath(rootEntry, workspaceRoot);
      } // else reference has been updated when updating originating project classpath
    }
  }
예제 #5
0
파일: ClassFile.java 프로젝트: eclipse/edt
 public SourceMapper getSourceMapper() {
   /*
    * case 1: if the binary project is imported into workspace, and the eglar file is in this imported binary project,
    * code enters here when:
    *   1) have decided this classfile is under BP but no corresponding source file found in the source folder. Enter
    *      case #3 directly
    *   2) need to decide if this classfile is under BP (if is BP but no source file available, enter case #3 eventually)
    * case 2: if project A refers binary project B, and binary project B is used in Target Platform and remains external,
    * corresponding eglar file of B will be attached as a library of A. To open an ir in project B's eglar, first look
    * for external source folder for project B. if B has external source folder and corresponding source file found for
    * the ir, then create SourceMapper using the external source folder location; otherwise, goto case #3
    * case 3: source folder (either internal or external) not available, or no corresponding source file found in the source
    * folder, then use the source attachment location to create SourceMapper, which should be the same as its parent's
    * SourceMapper (eventually, this should be the same as the eglar SourceMapper)
    *
    */
   // case 1:
   if (sourceFileSearchRequired
       && ResourcesPlugin.getWorkspace().getRoot().findMember(this.getPath())
           != null) { // non-external eglar file
     IPath projPath =
         this.getEGLProject().getProject().getLocation(); // absolute location in file system
     if (org.eclipse.edt.ide.core.internal.model.util.Util.isBinaryProject(
         new File(projPath.toString()))) { // is binary project
       String[] eglSourceFolders =
           org.eclipse.edt.ide.core.internal.model.util.Util.getEGLSourceFolders(
               new File(this.getEGLProject().getProject().getLocation().toString()));
       for (String eglSourceFolder : eglSourceFolders) {
         IResource sourceFolder = this.getEGLProject().getProject().findMember(eglSourceFolder);
         if (sourceFolder != null
             && sourceFolder.exists()
             && sourceFolder.getType() == IResource.FOLDER) {
           String pkgPath;
           try {
             pkgPath = this.getPackageDeclarations()[0].getElementName();
             pkgPath = pkgPath.replace(".", File.separator);
             IResource fullPkgFolder = ((IFolder) sourceFolder).findMember(pkgPath);
             if (fullPkgFolder != null
                 && fullPkgFolder.exists()
                 && fullPkgFolder.getType() == IResource.FOLDER) { // package matches
               ClassFileElementInfo elementInfo = ((ClassFileElementInfo) this.getElementInfo());
               String srcName = elementInfo.getEglFileName();
               IResource sourceFile = ((IFolder) fullPkgFolder).findMember(srcName);
               if (sourceFile == null) {
                 IPath path = new Path(srcName);
                 srcName = path.lastSegment();
                 sourceFile = ((IFolder) fullPkgFolder).findMember(srcName);
               }
               if (sourceFile != null
                   && sourceFile.exists()
                   && sourceFile.getType()
                       == IResource.FILE) { // egl source matches, use the source
                 return new SourceMapper(
                     sourceFile.getFullPath(), null, getEGLProject().getOptions(true));
               }
             }
           } catch (EGLModelException e) {
             e.printStackTrace();
           }
         }
       }
     }
   }
   // case 2:
   if (ResourcesPlugin.getWorkspace().getRoot().findMember(this.getPath())
       == null) { // external eglar file
     String eglarPath = this.getPath().toString();
     IEGLProject eglProj = this.getEGLProject();
     boolean isInBinaryProj = false;
     try {
       IEGLPathEntry[] pathEntries = eglProj.getResolvedEGLPath(true);
       for (IEGLPathEntry entry : pathEntries) {
         // if the entry path represents a binary project, and the entry path
         // is the one we want to open, then look for the binary project's source folder
         if (entry.isBinaryProject() && entry.getPath().equals(this.getPath())) {
           isInBinaryProj = true;
           break;
         }
       }
     } catch (EGLModelException e1) {
       e1.printStackTrace();
     }
     if (isInBinaryProj) { // is in binary project
       if (org.eclipse.edt.ide.core.internal.model.Util.isEGLARFileName(eglarPath)) {
         int index = eglarPath.lastIndexOf("/");
         if (index == -1) {
           index = eglarPath.lastIndexOf(File.separator);
         }
         if (index != -1) {
           String projRootPath = eglarPath.substring(0, index);
           String[] eglSourceFolders =
               org.eclipse.edt.ide.core.internal.model.util.Util.getEGLSourceFolders(
                   new File(projRootPath));
           for (String eglSourceFolder : eglSourceFolders) {
             String sourcePath = projRootPath + File.separator + eglSourceFolder;
             // try to find the source file
             try {
               String pkgPath = this.getPackageDeclarations()[0].getElementName();
               index = pkgPath.indexOf(".");
               while (index != -1) {
                 sourcePath += File.separator + pkgPath.substring(0, index);
                 pkgPath = pkgPath.substring(index + 1);
                 index = pkgPath.indexOf(".");
               }
               sourcePath += File.separator + pkgPath;
               // the ir file name is not always equal to the source egl file, as one egl file can
               // relate to
               // several ir files (depends on how many Parts in the egl file)
               String srcName = ((ClassFileElementInfo) this.getElementInfo()).getEglFileName();
               if (pkgPath.trim().length() > 0) sourcePath += File.separator;
               sourcePath += srcName;
               return new SourceMapper(
                   new Path(sourcePath), null, getEGLProject().getOptions(true));
             } catch (EGLModelException e) {
               e.printStackTrace();
             }
           }
         }
       }
     }
   }
   // case 3:
   return super.getSourceMapper();
 }