Search in sources :

Example 81 with IJavaElement

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) RenameTypeArguments(org.eclipse.jdt.core.refactoring.RenameTypeArguments) IJavaElementMapper(org.eclipse.jdt.core.refactoring.IJavaElementMapper)

Example 82 with IJavaElement

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);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test) BaseTest(org.eclipse.che.plugin.java.server.che.BaseTest)

Example 83 with IJavaElement

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();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IEditorInput(org.eclipse.ui.IEditorInput)

Example 84 with IJavaElement

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);
            }
        }
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 85 with IJavaElement

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspace(org.eclipse.core.resources.IWorkspace) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Aggregations

IJavaElement (org.eclipse.jdt.core.IJavaElement)226 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)49 IType (org.eclipse.jdt.core.IType)44 ArrayList (java.util.ArrayList)35 IJavaProject (org.eclipse.jdt.core.IJavaProject)35 IMethod (org.eclipse.jdt.core.IMethod)34 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)32 JavaModelException (org.eclipse.jdt.core.JavaModelException)32 IResource (org.eclipse.core.resources.IResource)30 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)28 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)23 IField (org.eclipse.jdt.core.IField)16 IMember (org.eclipse.jdt.core.IMember)14 Test (org.junit.Test)14 CoreException (org.eclipse.core.runtime.CoreException)13 StringTokenizer (java.util.StringTokenizer)11 ISourceRange (org.eclipse.jdt.core.ISourceRange)11 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)11 IPath (org.eclipse.core.runtime.IPath)10 HashMap (java.util.HashMap)9