Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
  /** Infinite loop performing resource indexing */
  public void run() {

    long idlingStart = -1;
    activateProcessing();
    try {
      while (this.thread != null) {
        try {
          IJob job;
          if ((job = currentJob()) == null) {
            if (idlingStart < 0) idlingStart = System.currentTimeMillis();
            notifyIdle(System.currentTimeMillis() - idlingStart);
            Thread.sleep(500);
            continue;
          } else {
            idlingStart = -1;
          }
          if (VERBOSE) {
            JobManager.verbose(awaitingJobsCount() + " awaiting jobs"); // $NON-NLS-1$
            JobManager.verbose("STARTING background job - " + job); // $NON-NLS-1$
          }
          try {
            executing = true;
            /*boolean status = */ job.execute(null);
            // if (status == FAILED) request(job);
          } finally {
            executing = false;
            if (VERBOSE) {
              JobManager.verbose("FINISHED background job - " + job); // $NON-NLS-1$
            }
            moveToNextJob();
            if (this.awaitingClients == 0) {
              Thread.sleep(50);
            }
          }
        } catch (InterruptedException e) { // background indexing was interrupted
        }
      }
    } catch (RuntimeException e) {
      if (this.thread != null) { // if not shutting down
        // log exception
        org.eclipse.edt.ide.core.internal.model.Util.log(
            e, "Background Indexer Crash Recovery"); // $NON-NLS-1$

        // keep job manager alive
        this.discardJobs(null);
        this.thread = null;
        this
            .reset(); // this will fork a new thread with no waiting jobs, some indexes will be
                      // inconsistent
      }
      throw e;
    } catch (Error e) {
      if (this.thread != null && !(e instanceof ThreadDeath)) {
        // log exception
        org.eclipse.edt.ide.core.internal.model.Util.log(
            e, "Background Indexer Crash Recovery"); // $NON-NLS-1$

        // keep job manager alive
        this.discardJobs(null);
        this.thread = null;
        this
            .reset(); // this will fork a new thread with no waiting jobs, some indexes will be
                      // inconsistent
      }
      throw e;
    }
  }