use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class JavaSearchScopeFactory method addJavaElements.
private void addJavaElements(Set<IJavaElement> javaElements, IWorkingSet workingSet) {
if (workingSet == null)
return;
if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
try {
IJavaProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
javaElements.addAll(Arrays.asList(projects));
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
return;
}
IAdaptable[] elements = workingSet.getElements();
for (int i = 0; i < elements.length; i++) {
IJavaElement javaElement = (IJavaElement) elements[i].getAdapter(IJavaElement.class);
if (javaElement != null) {
addJavaElements(javaElements, javaElement);
continue;
}
IResource resource = (IResource) elements[i].getAdapter(IResource.class);
if (resource != null) {
addJavaElements(javaElements, resource);
}
// else we don't know what to do with it, ignore.
}
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class JavaSearchScopeFactory method addJavaElements.
private void addJavaElements(Set<IJavaElement> javaElements, IResource resource) {
IJavaElement javaElement = (IJavaElement) resource.getAdapter(IJavaElement.class);
if (javaElement == null)
// not a Java resource
return;
if (javaElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
// add other possible package fragments
try {
addJavaElements(javaElements, ((IFolder) resource).members());
} catch (CoreException ex) {
// don't add elements
}
}
javaElements.add(javaElement);
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class Rename18Test method renameLocalVariable.
private void renameLocalVariable(String newFieldName, boolean updateReferences) throws Exception {
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
ISourceRange selection = getSelection(cu);
IJavaElement[] elements = cu.codeSelect(selection.getOffset(), selection.getLength());
assertEquals(1, elements.length);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
descriptor.setJavaElement(elements[0]);
descriptor.setNewName(newFieldName);
descriptor.setUpdateReferences(updateReferences);
descriptor.setUpdateTextualOccurrences(false);
RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
List list = new ArrayList();
list.add(elements[0]);
List args = new ArrayList();
args.add(new RenameArguments(newFieldName, updateReferences));
String[] renameHandles = ParticipantTesting.createHandles(list.toArray());
RefactoringStatus result = performRefactoring(refactoring);
assertEquals("was supposed to pass", null, result);
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
ParticipantTesting.testRename(renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class RenameTypeTest method helperWithTextual.
private String[] helperWithTextual(String oldCuName, String oldName, String newName, String newCUName, boolean updateReferences, boolean updateTextualMatches) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldCuName);
IType classA = getType(cu, oldName);
IJavaElement[] classAMembers = classA.getChildren();
IPackageFragment pack = (IPackageFragment) cu.getParent();
String[] renameHandles = null;
if (classA.getDeclaringType() == null && cu.getElementName().startsWith(classA.getElementName())) {
renameHandles = ParticipantTesting.createHandles(classA, cu, cu.getResource());
} else {
renameHandles = ParticipantTesting.createHandles(classA);
}
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, newName);
descriptor.setUpdateReferences(updateReferences);
descriptor.setUpdateTextualOccurrences(updateTextualMatches);
Refactoring refactoring = createRefactoring(descriptor);
assertEquals("was supposed to pass", null, performRefactoring(refactoring));
ICompilationUnit newcu = pack.getCompilationUnit(newCUName + ".java");
TestCase.assertTrue("cu " + newcu.getElementName() + " does not exist", newcu.exists());
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName(newCUName)), newcu.getSource());
INameUpdating nameUpdating = ((INameUpdating) refactoring.getAdapter(INameUpdating.class));
IType newElement = (IType) nameUpdating.getNewElement();
TestCase.assertTrue("new element does not exist:\n" + newElement.toString(), newElement.exists());
checkMappers(refactoring, classA, newCUName + ".java", classAMembers);
return renameHandles;
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class RenameTypeTest method checkMappedSimilarElementsExist.
private void checkMappedSimilarElementsExist(Refactoring ref) {
RenameTypeProcessor rtp = (RenameTypeProcessor) ((RenameRefactoring) ref).getProcessor();
IJavaElementMapper mapper = (IJavaElementMapper) rtp.getAdapter(IJavaElementMapper.class);
IJavaElement[] similarElements = rtp.getSimilarElements();
if (similarElements == null)
return;
for (int i = 0; i < similarElements.length; i++) {
IJavaElement element = similarElements[i];
if (!(element instanceof ILocalVariable)) {
IJavaElement newElement = mapper.getRefactoredJavaElement(element);
TestCase.assertTrue(newElement.exists());
Assert.assertFalse(element.exists());
}
}
}
Aggregations