Package org.eclipse.jdt.internal.core

Examples of org.eclipse.jdt.internal.core.JavaProject


     * @param project
     * @return
     */
    private IJavaProject convertToJavaProject(IProject project) {

        return new JavaProject(project, null);
    }
View Full Code Here


    }

    char[] searchedName = name.toCharArray();
    int index = name.length();
    /* Stop at the last fragment */
    JavaProject project = (JavaProject) this.compilationUnit.getJavaProject();
    do {
      String testedName = new String(searchedName, 0, index);
      IJavaElement fragment = null;
      try {
        fragment = project.findPackageFragment(testedName);
      } catch (JavaModelException e) {
        return name;
      }
      if (fragment != null) {
        return testedName;
      }
      try {
        fragment = project.findType(testedName);
      } catch (JavaModelException e) {
        return name;
      }
      if (fragment != null) {
        index = CharOperation.lastIndexOf(Signature.C_DOT, searchedName, 0, index - 1);
View Full Code Here

    }

    // initialize pattern for polymorphic search (i.e. method reference pattern)
    this.patternLocator.initializePolymorphicSearch(this);

    JavaProject previousJavaProject = null;
    PossibleMatchSet matchSet = new PossibleMatchSet();
    Util.sort(searchDocuments, new Util.Comparer() {
      public int compare(Object a, Object b) {
        return ((SearchDocument)a).getPath().compareTo(((SearchDocument)b).getPath());
      }
    });
    int displayed = 0; // progress worked displayed
    String previousPath = null;
    SearchParticipant searchParticipant = null;
    for (int i = 0; i < docsLength; i++) {
      if (this.progressMonitor != null && this.progressMonitor.isCanceled()) {
        throw new OperationCanceledException();
      }

      // skip duplicate paths
      SearchDocument searchDocument = searchDocuments[i];
      if (searchParticipant == null) {
        searchParticipant = searchDocument.getParticipant();
      }
      searchDocuments[i] = null; // free current document
      String pathString = searchDocument.getPath();
      if (i > 0 && pathString.equals(previousPath)) {
        if (this.progressMonitor != null) {
          this.progressWorked++;
          if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep);
        }
        displayed++;
        continue;
      }
      previousPath = pathString;

      Openable openable;
      org.eclipse.jdt.core.ICompilationUnit workingCopy = null;
      if (searchDocument instanceof WorkingCopyDocument) {
        workingCopy = ((WorkingCopyDocument)searchDocument).workingCopy;
        openable = (Openable) workingCopy;
      } else {
        openable = this.handleFactory.createOpenable(pathString, this.scope);
      }
      if (openable == null) {
        if (this.progressMonitor != null) {
          this.progressWorked++;
          if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep);
        }
        displayed++;
        continue; // match is outside classpath
      }

      // create new parser and lookup environment if this is a new project
      IResource resource = null;
      JavaProject javaProject = (JavaProject) openable.getJavaProject();
      resource = workingCopy != null ? workingCopy.getResource() : openable.getResource();
      if (resource == null)
        resource = javaProject.getProject(); // case of a file in an external jar or external folder
      if (!javaProject.equals(previousJavaProject)) {
        // locate matches in previous project
        if (previousJavaProject != null) {
          try {
            locateMatches(previousJavaProject, matchSet, i-displayed);
            displayed = i;
View Full Code Here

  long start = BasicSearchEngine.VERBOSE ? System.currentTimeMillis() : -1;
  try {
    IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
    Set paths = new HashSet(projects.length * 2);
    for (int i = 0, length = projects.length; i < length; i++) {
      JavaProject javaProject = (JavaProject) projects[i];

      // Add project full path
      IPath projectPath = javaProject.getProject().getFullPath();
      paths.add(projectPath);

      // Add project libraries paths
      IClasspathEntry[] entries = javaProject.getResolvedClasspath();
      for (int j = 0, eLength = entries.length; j < eLength; j++) {
        IClasspathEntry entry = entries[j];
        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
          IPath path = entry.getPath();
          Object target = JavaModel.getTarget(path, false/*don't check existence*/);
 
View Full Code Here

    // projectOrJarPath is a jar
    // it can see the focus only if it is on the classpath of a project that can see the focus
    IJavaProject[] allProjects = model.getJavaProjects();
    for (int i = 0, length = allProjects.length; i < length; i++) {
      JavaProject otherProject = (JavaProject) allProjects[i];
      IClasspathEntry entry = otherProject.getClasspathEntryFor(projectOrJarPath);
      if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        if (canSeeFocus(focuses, otherProject, null)) {
          return true;
        }
      }
View Full Code Here

        focusQualifiedNames = getQualifiedNames(superTypes);
      }
      IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
      for (int i = 0; i < length; i++) {
        IPath path = projectsAndJars[i];
        JavaProject project = (JavaProject) getJavaProject(path, model);
        if (project != null) {
          visitedProjects.add(project);
          if (canSeeFocus(focuses, project, focusQualifiedNames)) {
            locations.add(manager.computeIndexLocation(path));
            projectsCanSeeFocus[projectIndex++] = project;
          }
        } else {
          externalLibsToCheck.add(path);
        }
      }
      for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
        IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
        for (int j = entries.length; --j >= 0;) {
          IClasspathEntry entry = entries[j];
          if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath path = entry.getPath();
            if (externalLibsToCheck.remove(path) != null) {
              Object target = JavaModel.getTarget(path, false/*don't check existence*/);
              if (target instanceof IFolder) // case of an external folder
                path = ((IFolder) target).getFullPath();
              locations.add(manager.computeIndexLocation(path));
            }
          }
        }
      }
      // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
      if (externalLibsToCheck.elementSize > 0) {
        IJavaProject[] allProjects = model.getJavaProjects();
        for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
          JavaProject project = (JavaProject) allProjects[i];
          if (!visitedProjects.includes(project)) {
            IClasspathEntry[] entries = project.getResolvedClasspath();
            for (int j = entries.length; --j >= 0;) {
              IClasspathEntry entry = entries[j];
              if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath path = entry.getPath();
                if (externalLibsToCheck.remove(path) != null) {
View Full Code Here

    if (!this.project.isAccessible()) return true; // nothing to do

    ReadWriteMonitor monitor = null;
    try {
      // Get source folder entries. Libraries are done as a separate job
      JavaProject javaProject = (JavaProject)JavaCore.create(this.project);
      // Do not create marker while getting raw classpath (see bug 41859)
      IClasspathEntry[] entries = javaProject.getRawClasspath();
      int length = entries.length;
      IClasspathEntry[] sourceEntries = new IClasspathEntry[length];
      int sourceEntriesNumber = 0;
      for (int i = 0; i < length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
          sourceEntries[sourceEntriesNumber++] = entry;
      }
      if (sourceEntriesNumber == 0) {
        IPath projectPath = javaProject.getPath();
        for (int i = 0; i < length; i++) {
          IClasspathEntry entry = entries[i];
          if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(projectPath)) {
            // the project is also a library folder (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89815)
            // ensure a job exists to index it as a binary folder
            this.manager.indexLibrary(projectPath, this.project);
            return true;
          }
        }

        // nothing to index but want to save an empty index file so its not 'rebuilt' when part of a search request
        Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
        if (index != null)
          this.manager.saveIndex(index);
        return true;
      }
      if (sourceEntriesNumber != length)
        System.arraycopy(sourceEntries, 0, sourceEntries = new IClasspathEntry[sourceEntriesNumber], 0, sourceEntriesNumber);

      Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/);
      if (index == null) return true;
      monitor = index.monitor;
      if (monitor == null) return true; // index got deleted since acquired

      monitor.enterRead(); // ask permission to read

      String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$
      int max = paths == null ? 0 : paths.length;
      final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11);
      final String OK = "OK"; //$NON-NLS-1$
      final String DELETED = "DELETED"; //$NON-NLS-1$
      if (paths != null) {
        for (int i = 0; i < max; i++)
          indexedFileNames.put(paths[i], DELETED);
      }
      final long indexLastModified = max == 0 ? 0L : index.getIndexFile().lastModified();

      IWorkspaceRoot root = this.project.getWorkspace().getRoot();
      for (int i = 0; i < sourceEntriesNumber; i++) {
        if (this.isCancelled) return false;

        IClasspathEntry entry = sourceEntries[i];
        IResource sourceFolder = root.findMember(entry.getPath());
        if (sourceFolder != null) {

          // collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041)
          final HashSet outputs = new HashSet();
          if (sourceFolder.getType() == IResource.PROJECT) {
            // Do not create marker while getting output location (see bug 41859)
            outputs.add(javaProject.getOutputLocation());
            for (int j = 0; j < sourceEntriesNumber; j++) {
              IPath output = sourceEntries[j].getOutputLocation();
              if (output != null) {
                outputs.add(output);
              }
View Full Code Here

    }
    IProject[] referencedProjects = proj.getReferencedProjects();
    result.addAll(Arrays.asList(referencedProjects));
    IProjectNature nature = proj.getNature(JAVANATURE);
    if (nature != null) {
      JavaProject javaProject = (JavaProject) JavaCore.create(proj);
      IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath();
      for (IClasspathEntry eachCPE : resolvedClasspath) {
        if (eachCPE.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
          IProject project = getProject(eachCPE.getPath());
          result.add(project);
        }
View Full Code Here

        result.add(resourceFolder.getLocation().toPortableString());
      }
    }
    IProjectNature javaNature = project.getNature(RutaProjectUtils.JAVANATURE);
    if (javaNature != null) {
      JavaProject javaProject = (JavaProject) JavaCore.create(project);

      // add output, e.g., target/classes
      IPath readOutputLocation = javaProject.readOutputLocation();
      IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(readOutputLocation);
      result.add(folder.getLocation().toPortableString());

      IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
      for (IClasspathEntry each : rawClasspath) {
        int entryKind = each.getEntryKind();
        IPath path = each.getPath();
        if (entryKind == IClasspathEntry.CPE_PROJECT) {
          IProject p = RutaProjectUtils.getProject(path);
          if (!visited.contains(p)) {
            visited.add(p);
            extendClasspathWithProject(result, p, visited);
          }
        } else if (entryKind != IClasspathEntry.CPE_SOURCE) {
          String segment = path.segment(0);
          if (!segment.equals("org.eclipse.jdt.launching.JRE_CONTAINER")) {
            IClasspathEntry[] resolveClasspath = javaProject
                    .resolveClasspath(new IClasspathEntry[] { each });
            for (IClasspathEntry eachResolved : resolveClasspath) {
              if (eachResolved.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = RutaProjectUtils.getProject(eachResolved.getPath());
                if (!visited.contains(p)) {
View Full Code Here

        log(e.getMessage(), e);
        return Status.CANCEL_STATUS;
      }
     
      for (int i = 0; i < projects.length; i++) {
        final JavaProject project = (JavaProject) projects[i];
       
        log(
            "------------------ Project " +
            cutto(project.getProject().getName(), 20) +
            "------------------ ");
       
//        if(!project.isOpen()) {
//          System.out.println("Skipping " + project);
//          continue;
//        }
       
        Collection/*<SourceDescription>*/ sources = XMLConfig.readSources("sources.xml");
       
        if(sources == null || sources.size() == 0) {
          logError("No interesting methods in " + project.getResource().getName());
          continue;
        }
       
        int matches = 0, old_matches = 0;
       
        log("\tProcessing " + sources.size() + " methods");
       
        for (Iterator descIter = sources.iterator(); descIter.hasNext(); ){
          XMLConfig.SourceDescription desc = (SourceDescription) descIter.next();       
         
          log(
              "Project " + project.getProject().getName() +
              ": processing method " + desc.getID() + "...\t");
          monitor.subTask("Project " + project.getProject().getName() +
              ": processing method " + desc.getID() + "...\t");
         
          int index=desc.getMethodName().lastIndexOf('.');
                    char aux=(desc.getMethodName().charAt(index+1));
                    boolean isConstructor = aux<='Z';
                   
                    if(isConstructor)
                      System.out.println(desc.getMethodName()+" is constrcutor");
                   
                   // boolean isContructor = desc.getTypeName().endsWith(desc.getMethodName());
                   
          Collection callers/*<MethodUnitPair>*/ = CallerFinder.findCallers(monitor, desc.getID(), project, isConstructor);
         
          for (Iterator iter = callers.iterator(); iter.hasNext();) {
            Utils.ExprUnitResourceMember element = (Utils.ExprUnitResourceMember) iter.next();
            Expression expr = element.getExpression();
            if(expr == null) {
              log("Unexpected NULL in one of the callers");
              continue;
            }
            // do a case on the expression:
           
            if(!(expr instanceof MethodInvocation)) {
              logError("Can't match " + expr + " of type " + expr.getClass());
              continue;
            }
            MethodInvocation mi = (MethodInvocation) expr;
 
            ViewMatch match = new ViewMatch(
                expr.toString(),
                expr,
                element.getCompilationUnit(),
                element.getResource(),                               
                desc.getID(),
                desc.getCategoryName(),
                element.getMember(),
                false,
                false);
            contentProvider.addMatch(match);
            matches++;
          }
         
          if(matches > old_matches){
            Display.getDefault().syncExec(new Runnable() {
              public void run() {
                viewer.refresh();
              }
            });
          }
          old_matches = matches;         
        }
       
//        System.out.println("Found " + matches + " matche(s).");
        // find all main methods
        log("Looking for 'main' arguments");
        monitor.subTask("Looking for 'main' arguments");
        matches += addMethodsByName("main", "'main' declaration", "main argument", project, monitor, true);
       
        // find Ant entry points
        log("Looking for Ant task entry points");
        monitor.subTask("Looking for Ant task entry points");
        matches += addMethodsByName(ANT_TASK_TYPE + "." + ANT_TASK_METHODS, "Ant task entry point", "ANT", project, monitor, true);
       
        logError(project.getProject().getName() + "\t:\t" + matches + " matche(s)");
      }
      Display.getDefault().syncExec(new Runnable() {
        public void run() {
          viewer.refresh();
        }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.core.JavaProject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.