コード例 #1
0
ファイル: ClassFile.java プロジェクト: eclipse/edt
 public IPart getPart() {
   try {
     IPart[] parts = getAllParts();
     if (parts.length > 0) {
       return parts[0];
     }
   } catch (EGLModelException e) {
     e.printStackTrace();
   }
   return null;
 }
コード例 #2
0
ファイル: ClassFile.java プロジェクト: eclipse/edt
  // find current ClassFile's corresponding eclipse file from source folder
  public IFile getFileInSourceFolder() {
    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) { // source folder exists
        String pkgPath = "";
        IResource fullPkgFolder = null;
        try {
          ClassFileElementInfo elementInfo = ((ClassFileElementInfo) this.getElementInfo());
          String[] pkgs = elementInfo.getCaseSensitivePackageName();
          if (pkgs != null && pkgs.length > 0) {
            for (int i = 0; i < pkgs.length - 1; i++) {
              pkgPath += pkgs[i];
              pkgPath += File.separator;
            }
            pkgPath += pkgs[pkgs.length - 1];
            fullPkgFolder = ((IFolder) sourceFolder).findMember(pkgPath);
          } else {
            fullPkgFolder = sourceFolder;
          }

          if (fullPkgFolder != null
              && fullPkgFolder.exists()
              && fullPkgFolder.getType() == IResource.FOLDER) { // package matches
            String srcName =
                elementInfo
                    .getEglFileName(); // srcName should represent the source file name eliminating
            // package name
            int index = srcName.lastIndexOf("/");
            if (index != -1) {
              srcName = srcName.substring(index);
            }
            IResource sourceFile = ((IFolder) fullPkgFolder).findMember(srcName);
            if (sourceFile != null
                && sourceFile.exists()
                && sourceFile.getType() == IResource.FILE) { // egl source matches
              return (IFile) sourceFile;
            }
          }
        } catch (EGLModelException e) {
          e.printStackTrace();
        }
      }
    }

    return null;
  }
コード例 #3
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();
 }