diff --git a/AnyEditTools-feature/feature.xml b/AnyEditTools-feature/feature.xml index aff244e..7731684 100644 --- a/AnyEditTools-feature/feature.xml +++ b/AnyEditTools-feature/feature.xml @@ -2,7 +2,7 @@ @@ -27,7 +27,7 @@ - + @@ -38,16 +38,15 @@ - - + diff --git a/AnyEditTools/.classpath b/AnyEditTools/.classpath index 90639e3..d67844e 100644 --- a/AnyEditTools/.classpath +++ b/AnyEditTools/.classpath @@ -4,6 +4,6 @@ - + diff --git a/AnyEditTools/.settings/AnyeditPlatform_3.7.1.target b/AnyEditTools/.settings/AnyeditPlatform_3.7.1.target deleted file mode 100755 index 2404cbf..0000000 --- a/AnyEditTools/.settings/AnyeditPlatform_3.7.1.target +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - --Xmx900m - - diff --git a/AnyEditTools/.settings/org.eclipse.jdt.core.prefs b/AnyEditTools/.settings/org.eclipse.jdt.core.prefs index 03ba29a..1fc3d16 100644 --- a/AnyEditTools/.settings/org.eclipse.jdt.core.prefs +++ b/AnyEditTools/.settings/org.eclipse.jdt.core.prefs @@ -17,9 +17,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -108,7 +108,7 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.compiler.source=11 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 diff --git a/AnyEditTools/META-INF/MANIFEST.MF b/AnyEditTools/META-INF/MANIFEST.MF index ef4af9e..aa920e3 100644 --- a/AnyEditTools/META-INF/MANIFEST.MF +++ b/AnyEditTools/META-INF/MANIFEST.MF @@ -2,12 +2,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: de.loskutov.anyedit.AnyEditTools;singleton:=true -Bundle-Version: 2.7.2.qualifier +Bundle-Version: 2.7.3.qualifier Bundle-ClassPath: . Bundle-Activator: de.loskutov.anyedit.AnyEditToolsPlugin Bundle-Vendor: %Bundle-Vendor Bundle-Localization: plugin -Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", +Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.filesystem, org.eclipse.ui, org.eclipse.ui.ide, @@ -19,18 +19,17 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", org.eclipse.jface.text, org.eclipse.core.expressions, org.eclipse.compare, - org.eclipse.core.net, + org.eclipse.ui.workbench, org.eclipse.jdt.launching;resolution:=optional, org.eclipse.jdt.ui;resolution:=optional, org.eclipse.jdt.core;resolution:=optional, org.junit;resolution:=optional, - org.eclipse.jdt.annotation;bundle-version="[1.1.0,1.2.0)";resolution:=optional, - org.eclipse.ui.workbench;bundle-version="3.8.0" + org.eclipse.jdt.annotation;resolution:=optional Bundle-ActivationPolicy: lazy Export-Package: de.loskutov.anyedit, de.loskutov.anyedit.actions, de.loskutov.anyedit.actions.compare, - de.loskutov.anyedit.actions.internal;x-internal:=true, + de.loskutov.anyedit.actions.internal, de.loskutov.anyedit.actions.replace, de.loskutov.anyedit.actions.sort, de.loskutov.anyedit.compare, @@ -41,4 +40,3 @@ Export-Package: de.loskutov.anyedit, de.loskutov.anyedit.ui.util, de.loskutov.anyedit.ui.wizards, de.loskutov.anyedit.util -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/AnyEditTools/build.properties b/AnyEditTools/build.properties index 5b4dccd..0eeaeb0 100644 --- a/AnyEditTools/build.properties +++ b/AnyEditTools/build.properties @@ -5,20 +5,16 @@ bin.includes = META-INF/,\ .,\ icons/,\ plugin.properties,\ - src/,\ build.properties,\ about.ini,\ about.properties,\ about.html,\ schema/,\ epl-v10.html,\ - .settings/,\ .project,\ - .settings/edu.umd.cs.findbugs.core.prefs,\ .classpath,\ loskutov32.png javacProjectSettings = true src.excludes = test/ javacDefaultEncoding.. = UTF-8 jre.compilation.profile = JavaSE-1.7 -additional.bundles = org.eclipse.jdt.annotation diff --git a/AnyEditTools/plugin.xml b/AnyEditTools/plugin.xml index b513cf1..515e626 100644 --- a/AnyEditTools/plugin.xml +++ b/AnyEditTools/plugin.xml @@ -18,7 +18,6 @@ - @@ -602,9 +601,9 @@ class="de.loskutov.anyedit.ui.wizards.WorkingSetExportWizard" icon="icons/workingSets2.gif" id="AnyEditTools.workingSetExportWizard" - name="Working Sets"> + name="Working Sets and Projects"> - Exports all working sets to the file. + Exports all working sets and local projects to a file. @@ -616,9 +615,9 @@ class="de.loskutov.anyedit.ui.wizards.WorkingSetImportWizard" icon="icons/workingSets.gif" id="AnyEditTools.workingSetImportWizard" - name="Working Sets"> + name="Working Sets and Projects"> - Imports all working sets from file. + Imports all working sets and projects from previously exported file. diff --git a/AnyEditTools/src/de/loskutov/anyedit/actions/ConvertAllInFolderAction.java b/AnyEditTools/src/de/loskutov/anyedit/actions/ConvertAllInFolderAction.java index c76c2a4..5c71673 100644 --- a/AnyEditTools/src/de/loskutov/anyedit/actions/ConvertAllInFolderAction.java +++ b/AnyEditTools/src/de/loskutov/anyedit/actions/ConvertAllInFolderAction.java @@ -18,7 +18,6 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; @@ -61,7 +60,6 @@ protected boolean getEnablement() { return !selectedResources.isEmpty(); } - @Nullable protected IResource getResource(Object selection) { if(selection instanceof IContainer || selection instanceof IFile) { return (IResource)selection; diff --git a/AnyEditTools/src/de/loskutov/anyedit/ui/editor/AbstractEditor.java b/AnyEditTools/src/de/loskutov/anyedit/ui/editor/AbstractEditor.java index af53156..ba02e75 100644 --- a/AnyEditTools/src/de/loskutov/anyedit/ui/editor/AbstractEditor.java +++ b/AnyEditTools/src/de/loskutov/anyedit/ui/editor/AbstractEditor.java @@ -19,8 +19,6 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentRewriteSession; import org.eclipse.jface.text.DocumentRewriteSessionType; @@ -63,7 +61,7 @@ public class AbstractEditor implements ITextEditorExtension2 { /** * Proxy for different editor types */ - public AbstractEditor(final @Nullable IWorkbenchPart editorPart) { + public AbstractEditor(final IWorkbenchPart editorPart) { this(); wPart = editorPart; if(editorPart instanceof FormEditor){ @@ -134,7 +132,7 @@ public boolean isMultiPage(){ /** * @return may return null */ - @Nullable + public IDocumentProvider getDocumentProvider() { if (wPart == null) { return null; @@ -150,7 +148,7 @@ public IDocumentProvider getDocumentProvider() { /** * @return may return null */ - @Nullable + public IEditorInput getInput() { if (!(wPart instanceof IEditorPart)) { return null; @@ -161,7 +159,7 @@ public IEditorInput getInput() { /** * @return may return null */ - @Nullable + public IFile getIFile(){ if(wPart == null){ return null; @@ -177,7 +175,7 @@ public IFile getIFile(){ return adapter; } - @Nullable + public File getFile(){ if(wPart == null){ return null; @@ -206,7 +204,7 @@ public File getFile(){ /** * @see ITypedElement#getType() */ - @Nullable + public String getContentType(){ URI uri = getURI(); String path; @@ -226,7 +224,6 @@ public String getContentType(){ return path; } - @NonNull public String getTitle(){ if(wPart == null){ return ""; @@ -238,12 +235,11 @@ public String getTitle(){ /** * @return may return null */ - @Nullable + private URI getURI(){ return EclipseUtils.getURI(getInput()); } - @NonNull public String computeEncoding() { IFile file = getIFile(); if(file != null) { @@ -267,7 +263,7 @@ public String computeEncoding() { return TextUtil.SYSTEM_CHARSET; } - @Nullable + public ISelectionProvider getSelectionProvider() { if (wPart == null) { return null; @@ -291,7 +287,7 @@ public ISelectionProvider getSelectionProvider() { return null; } - @Nullable + public IDocument getDocument() { IEditorInput input = getInput(); if(input != null) { @@ -322,7 +318,7 @@ public IDocument getDocument() { return null; } - @Nullable + public ITextSelection getSelection(){ ISelectionProvider selectionProvider = getSelectionProvider(); if (selectionProvider == null) { @@ -335,7 +331,7 @@ public ITextSelection getSelection(){ return null; } - @Nullable + public String getSelectedText(){ ITextSelection selection = getSelection(); if(selection == null){ @@ -373,7 +369,7 @@ public boolean isDirty(){ return ((ISaveablePart) wPart).isDirty(); } - @Nullable + private T getAdapterFromPart(Class clazz){ if (wPart == null) { return null; @@ -441,7 +437,7 @@ public void stopSequentialRewriteMode(DocumentRewriteSession session) { * @param normalized true if the rewrite is performed * from the start to the end of the document */ - @Nullable + public DocumentRewriteSession startSequentialRewriteMode(boolean normalized) { // de/activate listeners etc, prepare multiple replace IRewriteTarget target = getAdapterFromPart(IRewriteTarget.class); @@ -515,12 +511,12 @@ public boolean equals(Object obj) { return this.hashCode() == other.hashCode(); } - @Nullable + public IWorkbenchPart getPart() { return wPart; } - @Nullable + public String getText() { IDocument doc = getDocument(); return doc != null? doc.get() : null; diff --git a/AnyEditTools/src/de/loskutov/anyedit/ui/wizards/ExportPage.java b/AnyEditTools/src/de/loskutov/anyedit/ui/wizards/ExportPage.java index db56991..786bb40 100644 --- a/AnyEditTools/src/de/loskutov/anyedit/ui/wizards/ExportPage.java +++ b/AnyEditTools/src/de/loskutov/anyedit/ui/wizards/ExportPage.java @@ -1,10 +1,11 @@ /******************************************************************************* - * Copyright (c) 2009 Andrey Loskutov. + * Copyright (c) 2009-2021 Andrey Loskutov. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * Contributor: Andrey Loskutov - initial API and implementation + * Contributor: Fabio Zadrozny - import local projects *******************************************************************************/ package de.loskutov.anyedit.ui.wizards; @@ -12,12 +13,21 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IPath; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IMemento; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.PlatformUI; @@ -46,11 +56,29 @@ private boolean storeSets() { } File file = new File(pathname); XMLMemento memento = XMLMemento.createWriteRoot("workingSets"); + Set projects = new HashSet<>(); + Object[] sets = getSelectedWorkingSets(); for (int i = 0; i < sets.length; i++) { IMemento childMem = memento.createChild("workingSet"); IWorkingSet set = (IWorkingSet) sets[i]; set.saveState(childMem); + IAdaptable[] elements = set.getElements(); + for (IAdaptable iAdaptable : elements) { + IProject project = iAdaptable.getAdapter(IProject.class); + if(project != null) { + projects.add(project); + } + } + } + + for(IProject project: projects) { + IMemento child = memento.createChild("project"); + IPath location = project.getLocation(); + if(location != null) { + child.putString("name", project.getName()); + child.putString("location", location.toPortableString()); + } } FileWriter writer = null; @@ -79,6 +107,14 @@ private boolean storeSets() { return true; } + @Override + public void createControl(Composite parent) { + super.createControl(parent); + Label label = new Label(comp, SWT.NONE); + + label.setText("Note: all "+ResourcesPlugin.getWorkspace().getRoot().getProjects().length+" projects will also be exported"); + } + public boolean finish() { return storeSets(); } diff --git a/AnyEditTools/src/de/loskutov/anyedit/ui/wizards/ImportPage.java b/AnyEditTools/src/de/loskutov/anyedit/ui/wizards/ImportPage.java index 154da5a..506a5f9 100644 --- a/AnyEditTools/src/de/loskutov/anyedit/ui/wizards/ImportPage.java +++ b/AnyEditTools/src/de/loskutov/anyedit/ui/wizards/ImportPage.java @@ -1,10 +1,11 @@ /******************************************************************************* - * Copyright (c) 2012 Andrey. + * Copyright (c) 2012-2021 Andrey. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * Contributor: Andrey Loskutov - initial API and implementation + * Contributor: Fabio Zadrozny - import local projects *******************************************************************************/ package de.loskutov.anyedit.ui.wizards; @@ -16,13 +17,23 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; @@ -51,10 +62,14 @@ public class ImportPage extends WSPage { private static final String TITLE = "Import working sets from the local file system"; - private static final String DESCRIPTION = "Select the file path to import working " + - "sets from and working sets to import"; + private static final String DESCRIPTION = "Select the file path to import working " + + "sets from and working sets to import"; protected boolean isMerge; + protected boolean importProjects; + private IMemento[] projects; + private Button importProjectsBtn; + private String importText = "Import local projects (note: projects will be initially closed)."; protected ImportPage(String pageName) { super(pageName, TITLE, DESCRIPTION, "icons/import_wiz.gif"); @@ -68,6 +83,7 @@ public void createControl(Composite parent) { chooserBtn.setSelection(isMerge); chooserBtn.setText("Merge with existing working sets"); chooserBtn.addSelectionListener(new SelectionListener() { + @Override public void widgetDefaultSelected(SelectionEvent e) { // ignored @@ -78,6 +94,43 @@ public void widgetSelected(SelectionEvent e) { isMerge = chooserBtn.getSelection(); } }); + + importProjectsBtn = new Button(comp, SWT.CHECK); + importProjectsBtn.setSelection(importProjects); + setImportText(null, 0); + importProjectsBtn.addSelectionListener(new SelectionListener() { + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // ignored + } + + @Override + public void widgetSelected(SelectionEvent e) { + importProjects = importProjectsBtn.getSelection(); + } + }); + } + + private void setImportText(Integer nProjectsForImport, int totalInFile) { + if (nProjectsForImport != null) { + // if found == null, just use what was already set. + if (totalInFile == 0) { + importText = "No projects found to import"; + } else if (nProjectsForImport == 0) { + importText = totalInFile + " projects found, but all are already imported"; + } else if (nProjectsForImport == totalInFile) { + importText = "Import " + nProjectsForImport + + " projects (note: projects will be initially closed)"; + } else { + importText = "Import " + nProjectsForImport + " projects of " + + (totalInFile - nProjectsForImport) + + " are already in the workspace or are not valid (note: projects will be initially closed)"; + } + } + if (importProjectsBtn != null) { + importProjectsBtn.setText(importText); + } } private String readSets() { @@ -109,8 +162,43 @@ private String readSets() { } } + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceRoot root = workspace.getRoot(); + IProject[] existingProjects = root.getProjects(); + Set existingNames = new HashSet<>(); + Set existingLocations = new HashSet<>(); + for (IProject iProject : existingProjects) { + existingNames.add(iProject.getName()); + IPath location = iProject.getLocation(); + if (location != null) { + existingLocations.add(location.toPortableString()); + } + } + IMemento[] projectMementos = memento.getChildren("project"); + List lst = new ArrayList<>(projectMementos.length); + for (IMemento iMemento : projectMementos) { + String name = iMemento.getString("name"); + String location = iMemento.getString("location"); + if (existingNames.contains(name)) { + continue; + } + if (existingLocations.contains(location)) { + continue; + } + + IPath locationAsPath = Path.fromPortableString(location); + IPath dotProjectPath = locationAsPath.append(".project"); + if (!dotProjectPath.toFile().exists()) { + continue; + } + + lst.add(iMemento); + } + this.projects = lst.toArray(new IMemento[0]); + this.setImportText(this.projects.length, projectMementos.length); + IMemento[] mementos = memento.getChildren("workingSet"); - List sets = new ArrayList(); + List sets = new ArrayList<>(); for (int i = 0; i < mementos.length; i++) { IWorkingSet set = restoreWorkingSet(mementos[i]); if (set != null) { @@ -143,21 +231,21 @@ protected IWorkingSet restoreWorkingSet(IMemento memento) { IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryID); if (factory == null) { AnyEditToolsPlugin.logError( - "Unable to restore working set - cannot instantiate factory: " - + factoryID, null); + "Unable to restore working set - cannot instantiate factory: " + factoryID, + null); return null; } IAdaptable adaptable = factory.createElement(memento); if (adaptable == null) { AnyEditToolsPlugin.logError( - "Unable to restore working set - cannot instantiate working set: " - + factoryID, null); + "Unable to restore working set - cannot instantiate working set: " + factoryID, + null); return null; } if (!(adaptable instanceof IWorkingSet)) { AnyEditToolsPlugin.logError( - "Unable to restore working set - element is not an IWorkingSet: " - + factoryID, null); + "Unable to restore working set - element is not an IWorkingSet: " + factoryID, + null); return null; } return (IWorkingSet) adaptable; @@ -169,13 +257,61 @@ public boolean finish() { } private void importSelectedSets() { + IProgressMonitor pm = Job.getJobManager().createProgressGroup(); + try { + if (importProjects && projects != null && projects.length > 0) { + pm.beginTask("Import projects", projects.length); + + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + workspace.run((IProgressMonitor monitor) -> { + for (IMemento iMemento : projects) { + try { + String name = iMemento.getString("name"); + String location = iMemento.getString("location"); + + pm.setTaskName("Importing: " + name); + IProjectDescription description; + try { + IPath locationAsPath = Path.fromPortableString(location); + IPath dotProjectPath = locationAsPath.append(".project"); + if (!dotProjectPath.toFile().exists()) { + continue; + } + description = workspace.loadProjectDescription(dotProjectPath); + IProject project = workspace.getRoot() + .getProject(description.getName()); + if (project.exists()) { + continue; + } + description.setLocation(locationAsPath); + project.create(description, null); + // Note: don't open initially as that's slow (let the user + // open it when he wants later on). + } catch (CoreException e) { + AnyEditToolsPlugin.logError(null, e); + continue; + } + } finally { + pm.worked(1); + } + } + }, workspace.getRoot(), IWorkspace.AVOID_UPDATE, pm); + + } + } catch (CoreException e) { + AnyEditToolsPlugin.logError(null, e); + } finally { + pm.done(); + } + + pm.setTaskName("Restoring working sets."); + Object[] selected = getSelectedWorkingSets(); if (selected == null) { return; } - IWorkingSetManager workingSetManager = PlatformUI.getWorkbench() - .getWorkingSetManager(); - List added = new ArrayList(); + IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); + List added = new ArrayList<>(); for (int i = 0; i < selected.length; i++) { IWorkingSet workingSet = (IWorkingSet) selected[i]; IWorkingSet oldWorkingSet = workingSetManager.getWorkingSet(workingSet.getName()); @@ -183,7 +319,7 @@ private void importSelectedSets() { removeNonExistingChildren(workingSet); workingSetManager.addWorkingSet(workingSet); added.add(workingSet); - } else if(isMerge) { + } else if (isMerge) { removeNonExistingChildren(workingSet); mergeWorkingSets(oldWorkingSet, workingSet); } @@ -191,13 +327,11 @@ private void importSelectedSets() { if (added.size() > 0) { try { /* - * Reflection required because some people do not have JDT installed, and - * thus current class would not be loaded at all with the direct reference - * to the action + * Reflection required because some people do not have JDT installed, and thus + * current class would not be loaded at all with the direct reference to the action */ - Class actClass = Class.forName( - "de.loskutov.anyedit.jdt.SelectWorkingSetsAction", true, - getClass().getClassLoader()); + Class actClass = Class.forName("de.loskutov.anyedit.jdt.SelectWorkingSetsAction", + true, getClass().getClassLoader()); IWSAction action = (IWSAction) actClass.newInstance(); action.setWorkingSets(added); action.run(); @@ -206,8 +340,9 @@ private void importSelectedSets() { } catch (ClassNotFoundException e) { AnyEditToolsPlugin.logError("JDT not installed", e); } catch (Throwable e) { - AnyEditToolsPlugin.logError("Failed to activate imported working sets" - + " in Package Explorer view", e); + AnyEditToolsPlugin.logError( + "Failed to activate imported working sets" + " in Package Explorer view", + e); } } } @@ -216,7 +351,7 @@ private static void removeNonExistingChildren(IWorkingSet workingSet) { IAdaptable[] elements = workingSet.getElements(); List existing = new ArrayList<>(); for (int i = 0; i < elements.length; i++) { - IResource resource = EclipseUtils.getResource(elements[i]); + IResource resource = EclipseUtils.getResource(elements[i]); if (resource != null && resource.exists()) { existing.add(resource); } @@ -225,6 +360,7 @@ private static void removeNonExistingChildren(IWorkingSet workingSet) { } public static class WorkingSetContentProvider implements ITreeContentProvider { + private IWorkingSet[] workingSets; @Override @@ -314,39 +450,39 @@ protected boolean validateInput() { } public void setInitialSelection(IStructuredSelection selection) { - if(selection == null) { + if (selection == null) { return; } IResource resource = EclipseUtils.getResource(selection); - if(resource == null) { + if (resource == null) { return; } IPath location = resource.getLocation(); - if(location != null && "wst".equals(location.getFileExtension()) && - location.toFile().isFile()) { + if (location != null && "wst".equals(location.getFileExtension()) + && location.toFile().isFile()) { usedFiles.add(location.toOSString()); } } private void mergeWorkingSets(IWorkingSet oldWorkingSet, IWorkingSet newWorkingSet) { - if(!oldWorkingSet.isEditable()) { + if (!oldWorkingSet.isEditable()) { return; } IAdaptable[] elementsOld = oldWorkingSet.getElements(); IAdaptable[] elementsNew = newWorkingSet.getElements(); - if(elementsNew == null || elementsOld == null || elementsNew.length == 0) { + if (elementsNew == null || elementsOld == null || elementsNew.length == 0) { return; } LinkedHashSet set = new LinkedHashSet(Arrays.asList(elementsOld)); ArrayList newList = new ArrayList(Arrays.asList(elementsNew)); newList.removeAll(set); - if(newList.size() == 0) { + if (newList.size() == 0) { return; } elementsNew = oldWorkingSet.adaptElements(newList.toArray(new IAdaptable[newList.size()])); newList = new ArrayList(Arrays.asList(elementsNew)); newList.removeAll(set); - if(newList.size() == 0) { + if (newList.size() == 0) { return; } set.addAll(newList); diff --git a/AnyEditTools/src/de/loskutov/anyedit/util/EclipseUtils.java b/AnyEditTools/src/de/loskutov/anyedit/util/EclipseUtils.java index b49f24e..14de5dd 100644 --- a/AnyEditTools/src/de/loskutov/anyedit/util/EclipseUtils.java +++ b/AnyEditTools/src/de/loskutov/anyedit/util/EclipseUtils.java @@ -47,7 +47,6 @@ import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.ui.console.IConsole; -import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; @@ -190,7 +189,7 @@ public static IProject getProject(IWorkbenchPart viewPart) { * @param askPlatform * @return adapter from given object to file, may return null */ - @Nullable + public static File getFile(Object o, boolean askPlatform) { File fileOrDir = getFileInternal(o, askPlatform); if(fileOrDir == null || fileOrDir.isDirectory()) { @@ -224,7 +223,7 @@ private static File getFileInternal(Object o, boolean askPlatform) { * @param b * @return adapter from given object to {@link IFile}, may return null */ - @Nullable + public static IFile getIFile(Object o, boolean askPlatform) { IResource r = getAdapter(o, IResource.class, askPlatform); if (r != null) { @@ -243,7 +242,7 @@ public static IFile getIFile(Object o, boolean askPlatform) { * @param type of target * @return adapter from given object to given type, may return null */ - @Nullable + public static V getAdapter(Object object, Class target) { return getAdapter(object, target, true); } @@ -263,7 +262,7 @@ public static IResource getResource(Object o) { * @param askPlatform * @return adapter from given object to resource, may return null */ - @Nullable + public static IResource getResource(Object o, boolean askPlatform) { IResource r = getAdapter(o, IResource.class, askPlatform); if (r != null) { @@ -281,7 +280,7 @@ public static IResource getResource(Object o, boolean askPlatform) { * @param type of target * @return adapter from given object to given type, may return null */ - @Nullable + public static V getAdapter(Object o, Class target, boolean askPlatform) { if(o instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) o; @@ -324,7 +323,7 @@ public static V getAdapter(Object o, Class target, boolean askPlatform) { * does not have an adapter for the given class */ @SuppressWarnings("unchecked") - @Nullable + public static T getAdapter(IAdaptable adaptable, Class adapterClass) { Object adapter = adaptable.getAdapter(adapterClass); return (T) adapter; @@ -452,7 +451,7 @@ private static IFile findAbsoluteFile(String selectedText) * @return may return null or external file, which location in workspace is null. For * files located inside the root of the file system, always returns null. */ - @Nullable + public static IFile getIFile(IPath iPath) throws OperationCanceledException { IFile resource = getWorkspaceFile(iPath.toFile()); if (resource != null) { @@ -533,7 +532,7 @@ private static String getRelativePath(IFileEditorInput currentInput) { return currentPath.toString(); } - @Nullable + public final static IFile getWorkspaceFile() { try { IFile file = queryFile(null, ResourcesPlugin.getWorkspace().getRoot()); @@ -579,8 +578,8 @@ public static ITextFileBuffer getBuffer(IFile file) { return fileBuffer; } - @Nullable - public static URI getURI(@Nullable IEditorInput input){ + + public static URI getURI( IEditorInput input){ if(input == null){ return null; } @@ -591,8 +590,8 @@ public static URI getURI(@Nullable IEditorInput input){ return null; } - @Nullable - public static File getFile(@Nullable IEditorInput input) { + + public static File getFile( IEditorInput input) { URI uri = getURI(input); if(uri == null){ return null; @@ -607,8 +606,8 @@ public static File getFile(@Nullable IEditorInput input) { /** * @return may return null */ - @Nullable - public static File getLocalFile(@Nullable URI uri) { + + public static File getLocalFile( URI uri) { if (uri != null) { try { IFileStore store = EFS.getStore(uri);