Search in sources :

Example 41 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.

the class ExtractConstantRefactoring method guessConstantNames.

/**
	 * @return proposed variable names (may be empty, but not null).
	 * The first proposal should be used as "best guess" (if it exists).
	 */
public String[] guessConstantNames() {
    if (fGuessedConstNames == null) {
        try {
            Expression expression = getSelectedExpression().getAssociatedExpression();
            if (expression != null) {
                ITypeBinding binding = guessBindingForReference(expression);
                fGuessedConstNames = StubUtility.getVariableNameSuggestions(NamingConventions.VK_STATIC_FINAL_FIELD, fCu.getJavaProject(), binding, expression, Arrays.asList(getExcludedVariableNames()));
            }
        } catch (JavaModelException e) {
        }
        if (fGuessedConstNames == null)
            fGuessedConstNames = new String[0];
    }
    return fGuessedConstNames;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) Expression(org.eclipse.jdt.core.dom.Expression) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding)

Example 42 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException 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 43 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.

the class RefactoringSearchEngine method findAffectedCompilationUnits.

//TODO: throw CoreException
public static ICompilationUnit[] findAffectedCompilationUnits(SearchPattern pattern, IJavaSearchScope scope, final IProgressMonitor pm, RefactoringStatus status, final boolean tolerateInAccurateMatches) throws JavaModelException {
    boolean hasNonCuMatches = false;
    class ResourceSearchRequestor extends SearchRequestor {

        boolean hasPotentialMatches = false;

        Set<IResource> resources = new HashSet<IResource>(5);

        private IResource fLastResource;

        @Override
        public void acceptSearchMatch(SearchMatch match) {
            if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
                hasPotentialMatches = true;
            }
            if (fLastResource != match.getResource()) {
                fLastResource = match.getResource();
                resources.add(fLastResource);
            }
        }
    }
    ResourceSearchRequestor requestor = new ResourceSearchRequestor();
    try {
        new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
    List<IJavaElement> result = new ArrayList<IJavaElement>(requestor.resources.size());
    for (Iterator<IResource> iter = requestor.resources.iterator(); iter.hasNext(); ) {
        IResource resource = iter.next();
        IJavaElement element = JavaCore.create(resource);
        if (element instanceof ICompilationUnit) {
            result.add(element);
        } else {
            hasNonCuMatches = true;
        }
    }
    addStatusErrors(status, requestor.hasPotentialMatches, hasNonCuMatches);
    return result.toArray(new ICompilationUnit[result.size()]);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource)

Example 44 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException 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 45 with JavaModelException

use of org.eclipse.jdt.core.JavaModelException in project che by eclipse.

the class TypeEnvironment method createStandardType.

private StandardType createStandardType(String fullyQualifiedName, IJavaProject focus) {
    try {
        IType javaElementType = focus.findType(fullyQualifiedName);
        StandardType result = fStandardTypes.get(javaElementType);
        if (result != null)
            return result;
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setProject(focus);
        IBinding[] bindings = parser.createBindings(new IJavaElement[] { javaElementType }, null);
        return createStandardType((ITypeBinding) bindings[0]);
    } catch (JavaModelException e) {
    // fall through
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IBinding(org.eclipse.jdt.core.dom.IBinding) ASTParser(org.eclipse.jdt.core.dom.ASTParser) IType(org.eclipse.jdt.core.IType)

Aggregations

JavaModelException (org.eclipse.jdt.core.JavaModelException)172 IJavaProject (org.eclipse.jdt.core.IJavaProject)44 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)41 IType (org.eclipse.jdt.core.IType)40 IJavaElement (org.eclipse.jdt.core.IJavaElement)35 CoreException (org.eclipse.core.runtime.CoreException)30 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)25 IPath (org.eclipse.core.runtime.IPath)24 ArrayList (java.util.ArrayList)21 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)17 IFile (org.eclipse.core.resources.IFile)15 IResource (org.eclipse.core.resources.IResource)15 HashMap (java.util.HashMap)14 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IMethod (org.eclipse.jdt.core.IMethod)12 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)12 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)11 SimpleName (org.eclipse.jdt.core.dom.SimpleName)9 Iterator (java.util.Iterator)8 ISourceRange (org.eclipse.jdt.core.ISourceRange)8