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;
}
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;
}
}
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()]);
}
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();
}
}
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;
}
Aggregations