Java 类org.eclipse.jdt.core.WorkingCopyOwner 实例源码

项目:eclipse.jdt.ls    文件:RippleMethodFinder.java   
private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException {
    IType rep = fUnionFind.find(type);
    if (rep != null) {
        Collection<IType> collection = fRootReps.get(rep);
        for (Iterator<IType> iter = collection.iterator(); iter.hasNext();) {
            IType root = iter.next();
            ITypeHierarchy hierarchy = fRootHierarchies.get(root);
            if (hierarchy == null) {
                hierarchy = root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1));
                fRootHierarchies.put(root, hierarchy);
            }
            if (hierarchy.contains(type)) {
                return hierarchy;
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:RippleMethodFinder.java   
private void findAllDeclarations(IProgressMonitor monitor, WorkingCopyOwner owner) throws CoreException {
    fDeclarations = new ArrayList<>();

    class MethodRequestor extends SearchRequestor {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            IMethod method = (IMethod) match.getElement();
            boolean isBinary = method.isBinary();
            if (!isBinary) {
                fDeclarations.add(method);
            }
        }
    }

    int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
    int matchRule = SearchPattern.R_ERASURE_MATCH | SearchPattern.R_CASE_SENSITIVE;
    SearchPattern pattern = SearchPattern.createPattern(fMethod, limitTo, matchRule);
    MethodRequestor requestor = new MethodRequestor();
    SearchEngine searchEngine = owner != null ? new SearchEngine(owner) : new SearchEngine();

    searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), requestor, monitor);
}
项目:eclipse.jdt.ls    文件:AbstractProjectsManagerBasedTest.java   
@Before
public void initProjectManager() throws CoreException {
    clientRequests.clear();

    logListener = new SimpleLogListener();
    Platform.addLogListener(logListener);
    preferences = new Preferences();
    if (preferenceManager != null) {
        when(preferenceManager.getPreferences()).thenReturn(preferences);
    }
    projectsManager = new ProjectsManager(preferenceManager);

    WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {
        @Override
        public IBuffer createBuffer(ICompilationUnit workingCopy) {
            ICompilationUnit original= workingCopy.getPrimary();
            IResource resource= original.getResource();
            if (resource instanceof IFile) {
                return new DocumentAdapter(workingCopy, (IFile)resource);
            }
            return DocumentAdapter.Null;
        }
    });
}
项目:che    文件:RippleMethodFinder2.java   
private IMethod[] getAllRippleMethods(IProgressMonitor pm, WorkingCopyOwner owner)
    throws CoreException {
  IMethod[] rippleMethods = findAllRippleMethods(pm, owner);
  if (fDeclarationToMatch == null) return rippleMethods;

  List<IMethod> rippleMethodsList = new ArrayList<IMethod>(Arrays.asList(rippleMethods));
  for (Iterator<IMethod> iter = rippleMethodsList.iterator(); iter.hasNext(); ) {
    Object match = fDeclarationToMatch.get(iter.next());
    if (match != null) {
      iter.remove();
      fBinaryRefs.add((SearchMatch) match);
    }
  }
  fDeclarationToMatch = null;
  return rippleMethodsList.toArray(new IMethod[rippleMethodsList.size()]);
}
项目:che    文件:RippleMethodFinder2.java   
private ITypeHierarchy getCachedHierarchy(
    IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException {
  IType rep = fUnionFind.find(type);
  if (rep != null) {
    Collection<IType> collection = fRootReps.get(rep);
    for (Iterator<IType> iter = collection.iterator(); iter.hasNext(); ) {
      IType root = iter.next();
      ITypeHierarchy hierarchy = fRootHierarchies.get(root);
      if (hierarchy == null) {
        hierarchy = root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1));
        fRootHierarchies.put(root, hierarchy);
      }
      if (hierarchy.contains(type)) return hierarchy;
    }
  }
  return null;
}
项目:che    文件:RefactoringASTParser.java   
public CompilationUnit parse(
    ITypeRoot typeRoot,
    WorkingCopyOwner owner,
    boolean resolveBindings,
    boolean statementsRecovery,
    boolean bindingsRecovery,
    IProgressMonitor pm) {
  fParser.setResolveBindings(resolveBindings);
  fParser.setStatementsRecovery(statementsRecovery);
  fParser.setBindingsRecovery(bindingsRecovery);
  fParser.setSource(typeRoot);
  if (owner != null) fParser.setWorkingCopyOwner(owner);
  fParser.setCompilerOptions(getCompilerOptions(typeRoot));
  CompilationUnit result = (CompilationUnit) fParser.createAST(pm);
  return result;
}
项目:che    文件:RefactoringSearchEngine.java   
public static SearchResultGroup[] search(
    SearchPattern pattern,
    WorkingCopyOwner owner,
    IJavaSearchScope scope,
    CollectingSearchRequestor requestor,
    IProgressMonitor monitor,
    RefactoringStatus status)
    throws JavaModelException {
  return internalSearch(
      owner != null ? new SearchEngine(owner) : new SearchEngine(),
      pattern,
      scope,
      requestor,
      monitor,
      status);
}
项目:che    文件:JavaModelManager.java   
public PerWorkingCopyInfo getPerWorkingCopyInfo(
    CompilationUnit workingCopy,
    boolean create,
    boolean recordUsage,
    IProblemRequestor problemRequestor) {
  synchronized (
      this.perWorkingCopyInfos) { // use the perWorkingCopyInfo collection as its own lock
    WorkingCopyOwner owner = workingCopy.owner;
    Map workingCopyToInfos = (Map) this.perWorkingCopyInfos.get(owner);
    if (workingCopyToInfos == null && create) {
      workingCopyToInfos = new HashMap();
      this.perWorkingCopyInfos.put(owner, workingCopyToInfos);
    }

    PerWorkingCopyInfo info =
        workingCopyToInfos == null
            ? null
            : (PerWorkingCopyInfo) workingCopyToInfos.get(workingCopy);
    if (info == null && create) {
      info = new PerWorkingCopyInfo(workingCopy, problemRequestor);
      workingCopyToInfos.put(workingCopy, info);
    }
    if (info != null && recordUsage) info.useCount++;
    return info;
  }
}
项目:che    文件:Util.java   
private static ICompilationUnit getCompilationUnit(
    char[] fileName, WorkingCopyOwner workingCopyOwner) {
  char[] slashSeparatedFileName = CharOperation.replaceOnCopy(fileName, File.separatorChar, '/');
  int pkgEnd = CharOperation.lastIndexOf('/', slashSeparatedFileName); // pkgEnd is exclusive
  if (pkgEnd == -1) return null;
  IPackageFragment pkg =
      getPackageFragment(slashSeparatedFileName, pkgEnd, -1 /*no jar separator for .java files*/);
  if (pkg == null) return null;
  int start;
  ICompilationUnit cu =
      pkg.getCompilationUnit(
          new String(
              slashSeparatedFileName, start = pkgEnd + 1, slashSeparatedFileName.length - start));
  if (workingCopyOwner != null) {
    ICompilationUnit workingCopy = cu.findWorkingCopy(workingCopyOwner);
    if (workingCopy != null) return workingCopy;
  }
  return cu;
}
项目:che    文件:JavaProject.java   
public IJavaElement findPackageFragment(String packageName) throws JavaModelException {
  NameLookup lookup =
      newNameLookup((WorkingCopyOwner) null /*no need to look at working copies for pkgs*/);
  IPackageFragment[] pkgFragments = lookup.findPackageFragments(packageName, false);
  if (pkgFragments == null) {
    return null;

  } else {
    // try to return one that is a child of this project
    for (int i = 0, length = pkgFragments.length; i < length; i++) {

      IPackageFragment pkgFragment = pkgFragments[i];
      if (equals(pkgFragment.getParent().getParent())) {
        return pkgFragment;
      }
    }
    // default to the first one
    return pkgFragments[0];
  }
}
项目:che    文件:JavaProject.java   
@Override
public IJavaElement getHandleFromMemento(
    String token, MementoTokenizer memento, WorkingCopyOwner owner) {
  switch (token.charAt(0)) {
    case JavaElement.JEM_PACKAGEFRAGMENTROOT:
      String rootPath = IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH;
      token = null;
      while (memento.hasMoreTokens()) {
        token = memento.nextToken();
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=331821
        if (token == MementoTokenizer.PACKAGEFRAGMENT || token == MementoTokenizer.COUNT) {
          break;
        }
        rootPath += token;
      }
      JavaElement root = (JavaElement) getPackageFragmentRoot(new Path(rootPath));
      if (token != null && token.charAt(0) == JavaElement.JEM_PACKAGEFRAGMENT) {
        return root.getHandleFromMemento(token, memento, owner);
      } else {
        return root.getHandleFromMemento(memento, owner);
      }
  }
  return null;
}
项目:eclipsemembersort    文件:SortHandler.java   
private void _processUnit(ICompilationUnit cu)
    throws JavaModelException, MalformedTreeException, BadLocationException {

    // Parse the javacode to be able to modify it
    ASTParser parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(cu);

    // Create a copy of the CompilationUnit to work on
    CompilationUnit copyOfUnit = (CompilationUnit)parser.createAST(null);

    MemberComparator comparator = new MemberComparator();

    // This helper method will sort our java code with the given comparator
    TextEdit edits = CompilationUnitSorter.sort(copyOfUnit, comparator, 0, null, null);

    // The sort method gives us null if there weren't any changes
    if (edits != null) {
        ICompilationUnit workingCopy = cu.getWorkingCopy(new WorkingCopyOwner() {}, null);

        workingCopy.applyTextEdit(edits, null);

        // Commit changes
        workingCopy.commitWorkingCopy(true, null);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:ConstructorReferenceFinder.java   
private List<SearchMatch> getImplicitConstructorReferencesInClassCreations(WorkingCopyOwner owner, IProgressMonitor pm, RefactoringStatus status) throws JavaModelException {
    //XXX workaround for jdt core bug 23112
    SearchPattern pattern= SearchPattern.createPattern(fType, IJavaSearchConstants.REFERENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    IJavaSearchScope scope= RefactoringScopeFactory.create(fType);
    SearchResultGroup[] refs= RefactoringSearchEngine.search(pattern, owner, scope, pm, status);
    List<SearchMatch> result= new ArrayList<SearchMatch>();
    for (int i= 0; i < refs.length; i++) {
        SearchResultGroup group= refs[i];
        ICompilationUnit cu= group.getCompilationUnit();
        if (cu == null)
            continue;
        CompilationUnit cuNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(cu, false);
        SearchMatch[] results= group.getSearchResults();
        for (int j= 0; j < results.length; j++) {
            SearchMatch searchResult= results[j];
            ASTNode node= ASTNodeSearchUtil.getAstNode(searchResult, cuNode);
            if (isImplicitConstructorReferenceNodeInClassCreations(node))
                result.add(searchResult);
        }
    }
    return result;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CompilationUnitResolver.java   
private void reportBinding(Object key, ASTRequestor astRequestor, WorkingCopyOwner owner, CompilationUnitDeclaration unit) {
    BindingKeyResolver keyResolver = (BindingKeyResolver) key;
    Binding compilerBinding = keyResolver.getCompilerBinding();
    if (compilerBinding != null) {
        DefaultBindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, false, this.fromJavaProject);
        AnnotationBinding annotationBinding = keyResolver.getAnnotationBinding();
        IBinding binding;
        if (annotationBinding != null) {
            binding = resolver.getAnnotationInstance(annotationBinding);
        } else {
            binding = resolver.getBinding(compilerBinding);
        }
        if (binding != null)
            astRequestor.acceptBinding(keyResolver.getKey(), binding);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:InternalCompletionContext.java   
protected void setExtendedData(
        ITypeRoot typeRoot,
        CompilationUnitDeclaration compilationUnitDeclaration,
        LookupEnvironment lookupEnvironment,
        Scope scope,
        ASTNode astNode,
        ASTNode astNodeParent,
        WorkingCopyOwner owner,
        CompletionParser parser) {
    this.isExtended = true;
    this.extendedContext =
        new InternalExtendedCompletionContext(
                this,
                typeRoot,
                compilationUnitDeclaration,
                lookupEnvironment,
                scope,
                astNode,
                astNodeParent,
                owner,
                parser);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RippleMethodFinder2.java   
private IMethod[] getAllRippleMethods(IProgressMonitor pm, WorkingCopyOwner owner) throws CoreException {
    IMethod[] rippleMethods= findAllRippleMethods(pm, owner);
    if (fDeclarationToMatch == null)
        return rippleMethods;

    List<IMethod> rippleMethodsList= new ArrayList<IMethod>(Arrays.asList(rippleMethods));
    for (Iterator<IMethod> iter= rippleMethodsList.iterator(); iter.hasNext(); ) {
        Object match= fDeclarationToMatch.get(iter.next());
        if (match != null) {
            iter.remove();
            fBinaryRefs.add((SearchMatch) match);
        }
    }
    fDeclarationToMatch= null;
    return rippleMethodsList.toArray(new IMethod[rippleMethodsList.size()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:PackageFragment.java   
/**
 * @see IPackageFragment#getCompilationUnits(WorkingCopyOwner)
 */
public ICompilationUnit[] getCompilationUnits(WorkingCopyOwner owner) {
    ICompilationUnit[] workingCopies = JavaModelManager.getJavaModelManager().getWorkingCopies(owner, false/*don't add primary*/);
    if (workingCopies == null) return JavaModelManager.NO_WORKING_COPY;
    int length = workingCopies.length;
    ICompilationUnit[] result = new ICompilationUnit[length];
    int index = 0;
    for (int i = 0; i < length; i++) {
        ICompilationUnit wc = workingCopies[i];
        if (equals(wc.getParent()) && !Util.isExcluded(wc)) { // 59933 - excluded wc shouldn't be answered back
            result[index++] = wc;
        }
    }
    if (index != length) {
        System.arraycopy(result, 0, result = new ICompilationUnit[index], 0, index);
    }
    return result;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaProject.java   
public IJavaElement findPackageFragment(String packageName)
        throws JavaModelException {
    NameLookup lookup = newNameLookup((WorkingCopyOwner)null/*no need to look at working copies for pkgs*/);
    IPackageFragment[] pkgFragments = lookup.findPackageFragments(packageName, false);
    if (pkgFragments == null) {
        return null;

    } else {
        // try to return one that is a child of this project
        for (int i = 0, length = pkgFragments.length; i < length; i++) {

            IPackageFragment pkgFragment = pkgFragments[i];
            if (equals(pkgFragment.getParent().getParent())) {
                return pkgFragment;
            }
        }
        // default to the first one
        return pkgFragments[0];
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaProject.java   
/**
 * @see IJavaProject
 */
public ITypeHierarchy newTypeHierarchy(
    IRegion region,
    WorkingCopyOwner owner,
    IProgressMonitor monitor)
    throws JavaModelException {

    if (region == null) {
        throw new IllegalArgumentException(Messages.hierarchy_nullRegion);
    }
    ICompilationUnit[] workingCopies = JavaModelManager.getJavaModelManager().getWorkingCopies(owner, true/*add primary working copies*/);
    CreateTypeHierarchyOperation op =
        new CreateTypeHierarchyOperation(region, workingCopies, null, true);
    op.runOperation(monitor);
    return op.getResult();
}
项目:Eclipse-Postfix-Code-Completion    文件:CompilationUnitResolver.java   
private void reportBinding(Object key, ASTRequestor astRequestor, WorkingCopyOwner owner, CompilationUnitDeclaration unit) {
    BindingKeyResolver keyResolver = (BindingKeyResolver) key;
    Binding compilerBinding = keyResolver.getCompilerBinding();
    if (compilerBinding != null) {
        DefaultBindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, false, this.fromJavaProject);
        AnnotationBinding annotationBinding = keyResolver.getAnnotationBinding();
        IBinding binding;
        if (annotationBinding != null) {
            binding = resolver.getAnnotationInstance(annotationBinding);
        } else {
            binding = resolver.getBinding(compilerBinding);
        }
        if (binding != null)
            astRequestor.acceptBinding(keyResolver.getKey(), binding);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RippleMethodFinder2.java   
private ITypeHierarchy getCachedHierarchy(IType type, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException {
    IType rep= fUnionFind.find(type);
    if (rep != null) {
        Collection<IType> collection= fRootReps.get(rep);
        for (Iterator<IType> iter= collection.iterator(); iter.hasNext();) {
            IType root= iter.next();
            ITypeHierarchy hierarchy= fRootHierarchies.get(root);
            if (hierarchy == null) {
                hierarchy= root.newTypeHierarchy(owner, new SubProgressMonitor(monitor, 1));
                fRootHierarchies.put(root, hierarchy);
            }
            if (hierarchy.contains(type))
                return hierarchy;
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InternalCompletionContext.java   
protected void setExtendedData(
        ITypeRoot typeRoot,
        CompilationUnitDeclaration compilationUnitDeclaration,
        LookupEnvironment lookupEnvironment,
        Scope scope,
        ASTNode astNode,
        ASTNode astNodeParent,
        WorkingCopyOwner owner,
        CompletionParser parser) {
    this.isExtended = true;
    this.extendedContext =
        new InternalExtendedCompletionContext(
                this,
                typeRoot,
                compilationUnitDeclaration,
                lookupEnvironment,
                scope,
                astNode,
                astNodeParent,
                owner,
                parser);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaProject.java   
public IJavaElement findPackageFragment(String packageName)
        throws JavaModelException {
    NameLookup lookup = newNameLookup((WorkingCopyOwner)null/*no need to look at working copies for pkgs*/);
    IPackageFragment[] pkgFragments = lookup.findPackageFragments(packageName, false);
    if (pkgFragments == null) {
        return null;

    } else {
        // try to return one that is a child of this project
        for (int i = 0, length = pkgFragments.length; i < length; i++) {

            IPackageFragment pkgFragment = pkgFragments[i];
            if (equals(pkgFragment.getParent().getParent())) {
                return pkgFragment;
            }
        }
        // default to the first one
        return pkgFragments[0];
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InternalExtendedCompletionContext.java   
public InternalExtendedCompletionContext(
        InternalCompletionContext completionContext,
        ITypeRoot typeRoot,
        CompilationUnitDeclaration compilationUnitDeclaration,
        LookupEnvironment lookupEnvironment,
        Scope assistScope,
        ASTNode assistNode,
        ASTNode assistNodeParent,
        WorkingCopyOwner owner,
        CompletionParser parser) {
    this.completionContext = completionContext;
    this.typeRoot = typeRoot;
    this.compilationUnitDeclaration = compilationUnitDeclaration;
    this.lookupEnvironment = lookupEnvironment;
    this.assistScope = assistScope;
    this.assistNode = assistNode;
    this.assistNodeParent = assistNodeParent;
    this.owner = owner;
    this.parser = parser;
}
项目:eclipse.jdt.ls    文件:RippleMethodFinder.java   
public static IMethod[] getRelatedMethods(IMethod method, IProgressMonitor pm, WorkingCopyOwner owner) throws CoreException {
    try {
        if (!isVirtual(method)) {
            return new IMethod[]{ method };
        }

        return new RippleMethodFinder(method).getAllRippleMethods(pm, owner);
    } finally {
        pm.done();
    }
}
项目:eclipse.jdt.ls    文件:RippleMethodFinder.java   
private void createHierarchyOfDeclarations(IProgressMonitor pm, WorkingCopyOwner owner) throws JavaModelException {
    IRegion region = JavaCore.newRegion();
    for (Iterator<IMethod> iter = fDeclarations.iterator(); iter.hasNext();) {
        IType declaringType = iter.next().getDeclaringType();
        region.add(declaringType);
    }
    fHierarchy = JavaCore.newTypeHierarchy(region, owner, pm);
}
项目:eclipse.jdt.ls    文件:JavaRefactoringDescriptorUtil.java   
/**
 * Converts an input handle back to the corresponding java element.
 *
 * @param owner
 *            the working copy owner
 * @param project
 *            the project, or <code>null</code> for the workspace
 * @param handle
 *            the input handle
 * @param check
 *            <code>true</code> to check for existence of the element,
 *            <code>false</code> otherwise
 * @return the corresponding java element, or <code>null</code> if no such
 *         element exists
 */
public static IJavaElement handleToElement(final WorkingCopyOwner owner, final String project, final String handle, final boolean check) {
    IJavaElement element = null;
    if (owner != null) {
        element = JavaCore.create(handle, owner);
    } else {
        element = JavaCore.create(handle);
    }
    if (element == null && project != null) {
        final IJavaProject javaProject = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProject(project);
        final String identifier = javaProject.getHandleIdentifier();
        if (owner != null) {
            element = JavaCore.create(identifier + handle, owner);
        } else {
            element = JavaCore.create(identifier + handle);
        }
    }
    if (check && element instanceof IMethod) {
        /*
         * Resolve the method based on simple names of parameter types
         * (to accommodate for different qualifications when refactoring is e.g.
         * recorded in source but applied on binary method):
         */
        final IMethod method = (IMethod) element;
        final IMethod[] methods = method.getDeclaringType().findMethods(method);
        if (methods != null && methods.length > 0) {
            element = methods[0];
        }
    }
    if (element != null && (!check || element.exists())) {
        return element;
    }
    return null;
}
项目:eclipse.jdt.ls    文件:RefactoringASTParser.java   
public CompilationUnit parse(ITypeRoot typeRoot, WorkingCopyOwner owner, boolean resolveBindings, boolean statementsRecovery, boolean bindingsRecovery, IProgressMonitor pm) {
    fParser.setResolveBindings(resolveBindings);
    fParser.setStatementsRecovery(statementsRecovery);
    fParser.setBindingsRecovery(bindingsRecovery);
    fParser.setSource(typeRoot);
    if (owner != null) {
        fParser.setWorkingCopyOwner(owner);
    }
    fParser.setCompilerOptions(getCompilerOptions(typeRoot));
    CompilationUnit result = (CompilationUnit) fParser.createAST(pm);
    return result;
}
项目:eclipse.jdt.ls    文件:JDTLanguageServer.java   
public void connectClient(JavaLanguageClient client) {
    this.client = new JavaClientConnection(client);
    this.workingCopyOwner = new LanguageServerWorkingCopyOwner(this.client);
    pm.setConnection(client);
    WorkingCopyOwner.setPrimaryBufferProvider(this.workingCopyOwner);
    this.documentLifeCycleHandler = new DocumentLifeCycleHandler(this.client, preferenceManager, pm, true);
}
项目:che    文件:QuickFixTest.java   
protected static final ArrayList collectCorrections2(ICompilationUnit cu, int nProblems)
    throws CoreException {

  final ArrayList problemsList = new ArrayList();
  final IProblemRequestor requestor =
      new IProblemRequestor() {
        public void acceptProblem(IProblem problem) {
          problemsList.add(problem);
        }

        public void beginReporting() {
          problemsList.clear();
        }

        public void endReporting() {}

        public boolean isActive() {
          return true;
        }
      };

  WorkingCopyOwner workingCopyOwner =
      new WorkingCopyOwner() {
        public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {
          return requestor;
        }
      };
  ICompilationUnit wc = cu.getWorkingCopy(workingCopyOwner, null);
  try {
    wc.reconcile(ICompilationUnit.NO_AST, true, true, wc.getOwner(), null);
  } finally {
    wc.discardWorkingCopy();
  }

  IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
  assertNumberOfProblems(nProblems, problems);

  return collectCorrections(cu, problems[0], null);
}
项目:che    文件:ReferenceFinderUtil.java   
public static IType[] getTypesReferencedIn(
    IJavaElement[] elements, WorkingCopyOwner owner, IProgressMonitor pm)
    throws JavaModelException {
  SearchMatch[] results = getTypeReferencesIn(elements, owner, pm);
  Set<IJavaElement> referencedTypes = extractElements(results, IJavaElement.TYPE);
  return referencedTypes.toArray(new IType[referencedTypes.size()]);
}
项目:che    文件:ReferenceFinderUtil.java   
private static SearchMatch[] getTypeReferencesIn(
    IJavaElement[] elements, WorkingCopyOwner owner, IProgressMonitor pm)
    throws JavaModelException {

  List<SearchMatch> referencedTypes = new ArrayList<SearchMatch>();
  pm.beginTask("", elements.length); // $NON-NLS-1$
  for (int i = 0; i < elements.length; i++) {
    referencedTypes.addAll(
        getTypeReferencesIn(elements[i], owner, new SubProgressMonitor(pm, 1)));
  }
  pm.done();
  return referencedTypes.toArray(new SearchMatch[referencedTypes.size()]);
}
项目:che    文件:ReferenceFinderUtil.java   
private static List<SearchMatch> getTypeReferencesIn(
    IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException {
  CollectingSearchRequestor requestor = new CollectingSearchRequestor();
  SearchEngine engine = owner != null ? new SearchEngine(owner) : new SearchEngine();
  engine.searchDeclarationsOfReferencedTypes(element, requestor, pm);
  return requestor.getResults();
}
项目:che    文件:ReferenceFinderUtil.java   
public static IField[] getFieldsReferencedIn(
    IJavaElement[] elements, WorkingCopyOwner owner, IProgressMonitor pm)
    throws JavaModelException {
  SearchMatch[] results = getFieldReferencesIn(elements, owner, pm);
  Set<IJavaElement> referencedFields = extractElements(results, IJavaElement.FIELD);
  return referencedFields.toArray(new IField[referencedFields.size()]);
}
项目:che    文件:ReferenceFinderUtil.java   
private static SearchMatch[] getFieldReferencesIn(
    IJavaElement[] elements, WorkingCopyOwner owner, IProgressMonitor pm)
    throws JavaModelException {
  List<SearchMatch> referencedFields = new ArrayList<SearchMatch>();
  pm.beginTask("", elements.length); // $NON-NLS-1$
  for (int i = 0; i < elements.length; i++) {
    referencedFields.addAll(
        getFieldReferencesIn(elements[i], owner, new SubProgressMonitor(pm, 1)));
  }
  pm.done();
  return referencedFields.toArray(new SearchMatch[referencedFields.size()]);
}
项目:che    文件:ReferenceFinderUtil.java   
private static List<SearchMatch> getFieldReferencesIn(
    IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException {
  CollectingSearchRequestor requestor = new CollectingSearchRequestor();
  SearchEngine engine = owner != null ? new SearchEngine(owner) : new SearchEngine();
  engine.searchDeclarationsOfAccessedFields(element, requestor, pm);
  return requestor.getResults();
}
项目:che    文件:ReferenceFinderUtil.java   
public static IMethod[] getMethodsReferencedIn(
    IJavaElement[] elements, WorkingCopyOwner owner, IProgressMonitor pm)
    throws JavaModelException {
  SearchMatch[] results = getMethodReferencesIn(elements, owner, pm);
  Set<IJavaElement> referencedMethods = extractElements(results, IJavaElement.METHOD);
  return referencedMethods.toArray(new IMethod[referencedMethods.size()]);
}
项目:che    文件:ReferenceFinderUtil.java   
private static SearchMatch[] getMethodReferencesIn(
    IJavaElement[] elements, WorkingCopyOwner owner, IProgressMonitor pm)
    throws JavaModelException {
  List<SearchMatch> referencedMethods = new ArrayList<SearchMatch>();
  pm.beginTask("", elements.length); // $NON-NLS-1$
  for (int i = 0; i < elements.length; i++) {
    referencedMethods.addAll(
        getMethodReferencesIn(elements[i], owner, new SubProgressMonitor(pm, 1)));
  }
  pm.done();
  return referencedMethods.toArray(new SearchMatch[referencedMethods.size()]);
}
项目:che    文件:ReferenceFinderUtil.java   
private static List<SearchMatch> getMethodReferencesIn(
    IJavaElement element, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException {
  CollectingSearchRequestor requestor = new CollectingSearchRequestor();
  SearchEngine engine = owner != null ? new SearchEngine(owner) : new SearchEngine();
  engine.searchDeclarationsOfSentMessages(element, requestor, pm);
  return requestor.getResults();
}
项目:che    文件:RenameAnalyzeUtil.java   
static ICompilationUnit[] createNewWorkingCopies(
    ICompilationUnit[] compilationUnitsToModify,
    TextChangeManager manager,
    WorkingCopyOwner owner,
    SubProgressMonitor pm)
    throws CoreException {
  pm.beginTask("", compilationUnitsToModify.length); // $NON-NLS-1$
  ICompilationUnit[] newWorkingCopies = new ICompilationUnit[compilationUnitsToModify.length];
  for (int i = 0; i < compilationUnitsToModify.length; i++) {
    ICompilationUnit cu = compilationUnitsToModify[i];
    newWorkingCopies[i] = createNewWorkingCopy(cu, manager, owner, new SubProgressMonitor(pm, 1));
  }
  pm.done();
  return newWorkingCopies;
}