use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class TestRenameParticipantShared method initialize.
public boolean initialize(Object element) {
fgInstance = this;
fElements.add(element);
fArguments.add(getArguments());
if (element instanceof IJavaElement)
fHandles.add(((IJavaElement) element).getHandleIdentifier());
else
fHandles.add(((IResource) element).getFullPath().toString());
IJavaElementMapper updating = (IJavaElementMapper) getProcessor().getAdapter(IJavaElementMapper.class);
if ((updating != null) && getArguments() instanceof RenameTypeArguments) {
RenameTypeArguments arguments = (RenameTypeArguments) getArguments();
if (arguments.getUpdateSimilarDeclarations()) {
IJavaElement[] elements = arguments.getSimilarDeclarations();
for (int i = 0; i < elements.length; i++) {
IJavaElement updated = updating.getRefactoredJavaElement(elements[i]);
if (updated != null) {
fSimilarToHandle.put(elements[i].getHandleIdentifier(), getKey(updated));
fSimilarToNewName.put(elements[i].getHandleIdentifier(), updated.getElementName());
}
}
}
}
return true;
}
use of org.eclipse.jdt.core.IJavaElement in project che by eclipse.
the class RenameTypeTest method testSimilarElements24.
@Test
public void testSimilarElements24() throws Exception {
// Test transplanter for ICompilationUnit and IFile
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
IType someClass = getType(cu, "SomeClass");
IJavaElement[] someClassMembers = someClass.getChildren();
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(someClass, "SomeNewClass");
setTheOptions(descriptor, true, false, true, null, RenamingNameSuggestor.STRATEGY_EMBEDDED);
Refactoring ref = createRefactoring(descriptor);
RefactoringStatus status = performRefactoring(ref);
Assert.assertNull("was supposed to pass", status);
checkResultInClass("SomeNewClass");
checkMappers(ref, someClass, "SomeNewClass.java", someClassMembers);
}
use of org.eclipse.jdt.core.IJavaElement in project AutoRefactor by JnRouvignac.
the class AutoRefactorHandler method getSelectedJavaElements.
private static List<IJavaElement> getSelectedJavaElements(Shell shell, IEditorPart activeEditor) {
final IEditorInput editorInput = activeEditor.getEditorInput();
final IJavaElement javaElement = JavaUI.getEditorInputJavaElement(editorInput);
if (javaElement instanceof ICompilationUnit) {
return Collections.singletonList(javaElement);
}
showMessage(shell, "This action only works on Java source files");
return Collections.emptyList();
}
use of org.eclipse.jdt.core.IJavaElement in project AutoRefactor by JnRouvignac.
the class PrepareApplyRefactoringsJob method addAll.
private void addAll(Queue<RefactoringUnit> results, List<IJavaElement> javaElements) throws JavaModelException {
for (IJavaElement javaElement : javaElements) {
final JavaProjectOptions options = getJavaProjectOptions(javaElement);
if (javaElement instanceof ICompilationUnit) {
add(results, (ICompilationUnit) javaElement, options);
} else if (javaElement instanceof IPackageFragment) {
final IPackageFragment pf = (IPackageFragment) javaElement;
addAll(results, pf.getCompilationUnits(), options);
} else if (javaElement instanceof IPackageFragmentRoot) {
final IPackageFragmentRoot pfr = (IPackageFragmentRoot) javaElement;
addAll(results, Arrays.asList(pfr.getChildren()));
} else if (javaElement instanceof IJavaProject) {
IJavaProject javaProject = (IJavaProject) javaElement;
for (IPackageFragment pf : javaProject.getPackageFragments()) {
addAll(results, pf.getCompilationUnits(), options);
}
}
}
}
use of org.eclipse.jdt.core.IJavaElement in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method getCurrentSelectedProject.
public static IProject getCurrentSelectedProject() {
IProject project = null;
ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof IResource) {
project = ((IResource) element).getProject();
} else if (element instanceof PackageFragmentRoot) {
IJavaProject jProject = ((PackageFragmentRoot) element).getJavaProject();
project = jProject.getProject();
} else if (element instanceof IJavaElement) {
IJavaProject jProject = ((IJavaElement) element).getJavaProject();
project = jProject.getProject();
}
}
if (project == null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if (workspace.getRoot() != null && workspace.getRoot().getProjects().length > 0) {
IProject[] projects = workspace.getRoot().getProjects();
project = projects[projects.length - 1];
} else {
PluginUtil.displayErrorDialog(Display.getDefault().getActiveShell(), "No Active Project", "Must have a project first");
}
}
return project;
}
Aggregations