Search in sources :

Example 21 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class TypeContextChecker method resolveSuperClass.

public static ITypeBinding resolveSuperClass(String superclass, IType typeHandle, StubTypeContext superClassContext) {
    StringBuffer cuString = new StringBuffer();
    cuString.append(superClassContext.getBeforeString());
    cuString.append(superclass);
    cuString.append(superClassContext.getAfterString());
    try {
        ICompilationUnit wc = typeHandle.getCompilationUnit().getWorkingCopy(new WorkingCopyOwner() {
        }, new NullProgressMonitor());
        try {
            wc.getBuffer().setContents(cuString.toString());
            CompilationUnit compilationUnit = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(wc, true);
            ASTNode type = NodeFinder.perform(compilationUnit, superClassContext.getBeforeString().length(), superclass.length());
            if (type instanceof Type) {
                return handleBug84585(((Type) type).resolveBinding());
            } else if (type instanceof Name) {
                ASTNode parent = type.getParent();
                if (parent instanceof Type)
                    return handleBug84585(((Type) parent).resolveBinding());
            }
            throw new IllegalStateException();
        } finally {
            wc.discardWorkingCopy();
        }
    } catch (JavaModelException e) {
        return null;
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RefactoringASTParser(org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser) NameQualifiedType(org.eclipse.jdt.core.dom.NameQualifiedType) IType(org.eclipse.jdt.core.IType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) Type(org.eclipse.jdt.core.dom.Type) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) JavaModelException(org.eclipse.jdt.core.JavaModelException) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) ASTNode(org.eclipse.jdt.core.dom.ASTNode) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Name(org.eclipse.jdt.core.dom.Name)

Example 22 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class RefactoringSearchEngine2 method searchReferencedMethods.

/**
	 * Performs the search of referenced methods.
	 *
	 * @param element the java element whose referenced methods have to be found
	 * @param monitor the progress monitor, or <code>null</code>
	 * @throws JavaModelException if an error occurs during search
	 */
public final void searchReferencedMethods(final IJavaElement element, IProgressMonitor monitor) throws JavaModelException {
    Assert.isNotNull(element);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 1);
        monitor.setTaskName(RefactoringCoreMessages.RefactoringSearchEngine_searching_referenced_methods);
        try {
            SearchEngine engine = null;
            if (fOwner != null)
                engine = new SearchEngine(fOwner);
            else
                engine = new SearchEngine(fWorkingCopies);
            engine.searchDeclarationsOfSentMessages(element, getCollector(), new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        } catch (CoreException exception) {
            throw new JavaModelException(exception);
        }
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 23 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class QualifiedNameFinder method process.

public static void process(QualifiedNameSearchResult result, String pattern, String newValue, String filePatterns, IProject root, IProgressMonitor monitor) {
    Assert.isNotNull(pattern);
    Assert.isNotNull(newValue);
    Assert.isNotNull(root);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    if (filePatterns == null || filePatterns.length() == 0) {
        // Eat progress.
        //$NON-NLS-1$
        monitor.beginTask("", 1);
        monitor.worked(1);
        return;
    }
    ResultCollector collector = new ResultCollector(result, newValue);
    TextSearchEngine engine = TextSearchEngine.create();
    Pattern searchPattern = PatternConstructor.createPattern(pattern, true, false);
    engine.search(createScope(filePatterns, root), collector, searchPattern, monitor);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Pattern(java.util.regex.Pattern) TextSearchEngine(org.eclipse.search.core.text.TextSearchEngine)

Example 24 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class RefactoringFileBuffers method release.

/**
	 * Releases the text file buffer associated with the compilation unit.
	 *
	 * @param unit the compilation unit whose text file buffer has to be released
	 * @throws CoreException if the buffer could not be successfully released
	 */
public static void release(final ICompilationUnit unit) throws CoreException {
    Assert.isNotNull(unit);
    final IResource resource = unit.getResource();
    if (resource != null && resource.getType() == IResource.FILE)
        FileBuffers.getTextFileBufferManager().disconnect(resource.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Example 25 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project che by eclipse.

the class RefactoringFileBuffers method acquire.

/**
	 * Connects to and acquires a text file buffer for the specified compilation unit.
	 * <p>
	 * All text file buffers acquired by a call to {@link RefactoringFileBuffers#acquire(ICompilationUnit)}
	 * must be released using {@link RefactoringFileBuffers#release(ICompilationUnit)}.
	 * </p>
	 *
	 * @param unit the compilation unit to acquire a text file buffer for
	 * @return the text file buffer, or <code>null</code> if no buffer could be acquired
	 * @throws CoreException if no buffer could be acquired
	 */
public static ITextFileBuffer acquire(final ICompilationUnit unit) throws CoreException {
    Assert.isNotNull(unit);
    final IResource resource = unit.getResource();
    if (resource != null && resource.getType() == IResource.FILE) {
        final IPath path = resource.getFullPath();
        FileBuffers.getTextFileBufferManager().connect(path, LocationKind.IFILE, new NullProgressMonitor());
        return FileBuffers.getTextFileBufferManager().getTextFileBuffer(path, LocationKind.IFILE);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1626 CoreException (org.eclipse.core.runtime.CoreException)430 Test (org.junit.Test)353 IFile (org.eclipse.core.resources.IFile)316 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)276 IProject (org.eclipse.core.resources.IProject)261 File (java.io.File)213 IPath (org.eclipse.core.runtime.IPath)184 IOException (java.io.IOException)162 Path (org.eclipse.core.runtime.Path)141 ArrayList (java.util.ArrayList)125 IStatus (org.eclipse.core.runtime.IStatus)116 IFolder (org.eclipse.core.resources.IFolder)90 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)70 List (java.util.List)63 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)63 InvocationTargetException (java.lang.reflect.InvocationTargetException)61 IProjectDescription (org.eclipse.core.resources.IProjectDescription)58 Status (org.eclipse.core.runtime.Status)57 IResource (org.eclipse.core.resources.IResource)56