Lambda conversions.
Two classes handled IWorkspaceRunnable and Comparator. The rest is done
by safe actions.
Change-Id: I7cc3e28c585d91b607b16c5ef5a2c2fd265be61d
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsoleCompletionProcessor.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsoleCompletionProcessor.java
index 707d966..2a46043 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsoleCompletionProcessor.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsoleCompletionProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2016 IBM Corporation and others.
+ * Copyright (c) 2005, 2017 IBM Corporation and others.
* 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
@@ -10,7 +10,6 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@@ -23,8 +22,7 @@
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
-public abstract class ScriptConsoleCompletionProcessor
- implements IContentAssistProcessor {
+public abstract class ScriptConsoleCompletionProcessor implements IContentAssistProcessor {
protected static interface IProposalDecorator {
String formatProposal(ScriptConsoleCompletionProposal c);
@@ -37,8 +35,7 @@
if (defaultDecorator == null) {
defaultDecorator = new IProposalDecorator() {
@Override
- public String formatProposal(
- ScriptConsoleCompletionProposal c) {
+ public String formatProposal(ScriptConsoleCompletionProposal c) {
return c.getDisplay();
}
@@ -54,8 +51,7 @@
private IScriptConsoleShell interpreterShell;
- public ScriptConsoleCompletionProcessor(
- IScriptConsoleShell interpreterShell) {
+ public ScriptConsoleCompletionProcessor(IScriptConsoleShell interpreterShell) {
this.interpreterShell = interpreterShell;
}
@@ -63,15 +59,14 @@
return this.interpreterShell;
}
- protected List<CompletionProposal> createProposalsFromString(
- List<ScriptConsoleCompletionProposal> list, int offset,
+ protected List<CompletionProposal> createProposalsFromString(List<ScriptConsoleCompletionProposal> list, int offset,
IProposalDecorator decorator) {
if (decorator == null) {
decorator = getDefaultDecorator();
}
- List<CompletionProposal> result = new ArrayList<CompletionProposal>();
+ List<CompletionProposal> result = new ArrayList<>();
Iterator<ScriptConsoleCompletionProposal> it = list.iterator();
while (it.hasNext()) {
@@ -89,27 +84,18 @@
result.add(proposal);
}
- Collections.sort(result, new Comparator<CompletionProposal>() {
- @Override
- public int compare(CompletionProposal p1, CompletionProposal p2) {
- return p1.getDisplayString().compareTo(p2.getDisplayString());
- }
- });
+ Collections.sort(result, (p1, p2) -> p1.getDisplayString().compareTo(p2.getDisplayString()));
return result;
}
- protected abstract ICompletionProposal[] computeCompletionProposalsImpl(
- IScriptConsoleViewer viewer, int offset);
+ protected abstract ICompletionProposal[] computeCompletionProposalsImpl(IScriptConsoleViewer viewer, int offset);
- protected abstract IContextInformation[] computeContextInformationImpl(
- ITextViewer viewer, int offset);
+ protected abstract IContextInformation[] computeContextInformationImpl(ITextViewer viewer, int offset);
@Override
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
- int offset) {
- return computeCompletionProposalsImpl((IScriptConsoleViewer) viewer,
- offset);
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
+ return computeCompletionProposalsImpl((IScriptConsoleViewer) viewer, offset);
}
@Override
@@ -118,8 +104,7 @@
}
@Override
- public IContextInformation[] computeContextInformation(ITextViewer viewer,
- int offset) {
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return computeContextInformationImpl(viewer, offset);
}
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsolePartitioner.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsolePartitioner.java
index a3dcc67..1c43c81 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsolePartitioner.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/ScriptConsolePartitioner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2016 IBM Corporation and others.
+ * Copyright (c) 2005, 2017 IBM Corporation and others.
* 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
@@ -10,7 +10,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
@@ -27,20 +26,15 @@
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.ui.console.IConsoleDocumentPartitioner;
-public class ScriptConsolePartitioner extends FastPartitioner
- implements IConsoleDocumentPartitioner {
+public class ScriptConsolePartitioner extends FastPartitioner implements IConsoleDocumentPartitioner {
- private SortedSet<StyleRange> ranges = new TreeSet<StyleRange>(
- new Comparator<StyleRange>() {
- @Override
- public int compare(StyleRange sr1, StyleRange sr2) {
- int start = sr1.start - sr2.start;
- if (start == 0) {
- return sr1.length - sr2.length;
- }
- return start;
- }
- });
+ private SortedSet<StyleRange> ranges = new TreeSet<>((sr1, sr2) -> {
+ int start = sr1.start - sr2.start;
+ if (start == 0) {
+ return sr1.length - sr2.length;
+ }
+ return start;
+ });
private static class Constants {
public static final String MY_DOUBLE_QUOTED = "__my_double"; //$NON-NLS-1$
@@ -53,7 +47,7 @@
IToken myDouble = new Token(Constants.MY_DOUBLE_QUOTED);
IToken mySingle = new Token(Constants.MY_SINGLE_QUOTED);
- List<IRule> rules = new ArrayList<IRule>();
+ List<IRule> rules = new ArrayList<>();
rules.add(new MultiLineRule("\'", "\'", mySingle, '\\')); //$NON-NLS-1$ //$NON-NLS-2$
rules.add(new MultiLineRule("\"", "\"", myDouble, '\\')); //$NON-NLS-1$ //$NON-NLS-2$
@@ -67,8 +61,7 @@
public ScriptConsolePartitioner() {
- super(new MyPartitionScanner(), new String[] {
- Constants.MY_DOUBLE_QUOTED, Constants.MY_SINGLE_QUOTED });
+ super(new MyPartitionScanner(), new String[] { Constants.MY_DOUBLE_QUOTED, Constants.MY_SINGLE_QUOTED });
}
public void addRange(StyleRange r) {
@@ -85,12 +78,11 @@
@Override
public StyleRange[] getStyleRanges(int offset, int length) {
- List<StyleRange> result = new ArrayList<StyleRange>();
+ List<StyleRange> result = new ArrayList<>();
// get the sublist with length = 0 so that it will return all with that
// offset.
StyleRange sr = new StyleRange(offset, 0, null, null, SWT.NO);
- for (Iterator<StyleRange> iterator = ranges.tailSet(sr)
- .iterator(); iterator.hasNext();) {
+ for (Iterator<StyleRange> iterator = ranges.tailSet(sr).iterator(); iterator.hasNext();) {
StyleRange r = iterator.next();
if (r.start >= offset && r.start + r.length <= offset + length)
result.add((StyleRange) r.clone());
diff --git a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ConsoleViewManager.java b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ConsoleViewManager.java
index afe9ed4..995d9f8 100644
--- a/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ConsoleViewManager.java
+++ b/core/plugins/org.eclipse.dltk.console.ui/src/org/eclipse/dltk/console/ui/internal/ConsoleViewManager.java
@@ -1,10 +1,10 @@
/*******************************************************************************
- * Copyright (c) 2009, 2016 xored software, Inc. and others.
+ * Copyright (c) 2009, 2017 xored software, Inc. and others.
*
* 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
+ * http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* xored software, Inc. - initial API and Implementation (Alex Panchenko)
@@ -13,7 +13,6 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
@@ -58,22 +57,16 @@
* @param elementType
*/
public ConsoleViewManager(String extensionPoint) {
- extensions = new ArrayList<Descriptor>(5);
+ extensions = new ArrayList<>(5);
extensions.add(new Descriptor(IConsoleConstants.ID_CONSOLE_VIEW, 0));
- for (final IConfigurationElement element : Platform
- .getExtensionRegistry()
+ for (final IConfigurationElement element : Platform.getExtensionRegistry()
.getConfigurationElementsFor(extensionPoint)) {
final Descriptor descriptor = new Descriptor(element);
if (isValidDescriptor(descriptor)) {
extensions.add(descriptor);
}
}
- Collections.sort(extensions, new Comparator<Descriptor>() {
- @Override
- public int compare(Descriptor arg0, Descriptor arg1) {
- return arg1.priority - arg0.priority;
- }
- });
+ Collections.sort(extensions, (arg0, arg1) -> arg1.priority - arg0.priority);
}
// Contains list of descriptors.
@@ -82,7 +75,7 @@
/**
* Return array of descriptors. If there are no contributed instances the
* empty array is returned.
- *
+ *
* @param natureId
* @return
* @throws CoreException
diff --git a/core/plugins/org.eclipse.dltk.core.manipulation/.settings/org.eclipse.jdt.ui.prefs b/core/plugins/org.eclipse.dltk.core.manipulation/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..fbac55c
--- /dev/null
+++ b/core/plugins/org.eclipse.dltk.core.manipulation/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,59 @@
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=true
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_functional_interfaces=true
+sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.correct_indentation=false
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.insert_inferred_type_arguments=false
+sp_cleanup.make_local_variable_final=true
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_type_arguments=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=false
+sp_cleanup.remove_unused_imports=true
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_anonymous_class_creation=false
+sp_cleanup.use_blocks=false
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_lambda=true
+sp_cleanup.use_parentheses_in_expressions=false
+sp_cleanup.use_this_for_non_static_field_access=false
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=false
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
diff --git a/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/RefactoringSearchEngine.java b/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/RefactoringSearchEngine.java
index 9202d58..9a0a035 100644
--- a/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/RefactoringSearchEngine.java
+++ b/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/RefactoringSearchEngine.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
@@ -33,94 +33,109 @@
import org.eclipse.dltk.core.search.SearchPattern;
import org.eclipse.dltk.core.search.SearchRequestor;
import org.eclipse.dltk.internal.corext.util.SearchUtils;
-import org.eclipse.ltk.core.refactoring.IRefactoringStatusEntryComparator;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
/**
- * Convenience wrapper for {@link SearchEngine} - performs searching and sorts the results by {@link IResource}.
- * TODO: throw CoreExceptions from search(..) methods instead of wrapped JavaModelExceptions.
+ * Convenience wrapper for {@link SearchEngine} - performs searching and sorts
+ * the results by {@link IResource}. TODO: throw CoreExceptions from search(..)
+ * methods instead of wrapped JavaModelExceptions.
*/
public class RefactoringSearchEngine {
- private RefactoringSearchEngine(){
- //no instances
+ private RefactoringSearchEngine() {
+ // no instances
}
- public static ISourceModule[] findAffectedCompilationUnits(SearchPattern pattern,
- IDLTKSearchScope scope, final IProgressMonitor pm, RefactoringStatus status, final boolean tolerateInAccurateMatches) throws CoreException {
+ public static ISourceModule[] findAffectedCompilationUnits(SearchPattern pattern, IDLTKSearchScope scope,
+ final IProgressMonitor pm, RefactoringStatus status, final boolean tolerateInAccurateMatches)
+ throws CoreException {
- boolean hasNonCuMatches= false;
+ boolean hasNonCuMatches = false;
- class ResourceSearchRequestor extends SearchRequestor{
- boolean hasPotentialMatches= false ;
- Set<IResource> resources= new HashSet<IResource>(5);
+ class ResourceSearchRequestor extends SearchRequestor {
+ boolean hasPotentialMatches = false;
+ Set<IResource> resources = new HashSet<>(5);
private IResource fLastResource;
+ @Override
public void acceptSearchMatch(SearchMatch match) {
if (!tolerateInAccurateMatches && match.getAccuracy() == SearchMatch.A_INACCURATE) {
- hasPotentialMatches= true;
+ hasPotentialMatches = true;
}
if (fLastResource != match.getResource()) {
- fLastResource= match.getResource();
+ fLastResource = match.getResource();
resources.add(fLastResource);
}
}
}
ResourceSearchRequestor requestor = new ResourceSearchRequestor();
new SearchEngine().search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, pm);
- List<ISourceModule> result= new ArrayList<ISourceModule>(requestor.resources.size());
+ List<ISourceModule> result = new ArrayList<>(requestor.resources.size());
for (IResource resource : requestor.resources) {
- IModelElement element= DLTKCore.create(resource);
+ IModelElement element = DLTKCore.create(resource);
if (element instanceof ISourceModule) {
- result.add((ISourceModule)element);
+ result.add((ISourceModule) element);
} else {
- hasNonCuMatches= true;
+ hasNonCuMatches = true;
}
}
addStatusErrors(status, requestor.hasPotentialMatches, hasNonCuMatches);
return result.toArray(new ISourceModule[result.size()]);
}
- public static ISourceModule[] findAffectedCompilationUnits(SearchPattern pattern,
- IDLTKSearchScope scope, final IProgressMonitor pm, RefactoringStatus status) throws CoreException {
+ public static ISourceModule[] findAffectedCompilationUnits(SearchPattern pattern, IDLTKSearchScope scope,
+ final IProgressMonitor pm, RefactoringStatus status) throws CoreException {
return findAffectedCompilationUnits(pattern, scope, pm, status, false);
}
/**
* Performs a search and groups the resulting {@link SearchMatch}es by
* {@link SearchResultGroup#getCompilationUnit()}.
- * @param pattern the search pattern
- * @param scope the search scope
- * @param monitor the progress monitor
- * @param status an error is added here if inaccurate or non-cu matches have been found
- * @return a {@link SearchResultGroup}[], where each {@link SearchResultGroup}
- * has a different {@link SearchMatch#getResource() getResource()}s.
+ *
+ * @param pattern
+ * the search pattern
+ * @param scope
+ * the search scope
+ * @param monitor
+ * the progress monitor
+ * @param status
+ * an error is added here if inaccurate or non-cu matches have
+ * been found
+ * @return a {@link SearchResultGroup}[], where each
+ * {@link SearchResultGroup} has a different
+ * {@link SearchMatch#getResource() getResource()}s.
* @see SearchMatch
- * @throws JavaModelException when the search failed
+ * @throws JavaModelException
+ * when the search failed
*/
- public static SearchResultGroup[] search(SearchPattern pattern, IDLTKSearchScope scope, IProgressMonitor monitor, RefactoringStatus status)
- throws CoreException {
+ public static SearchResultGroup[] search(SearchPattern pattern, IDLTKSearchScope scope, IProgressMonitor monitor,
+ RefactoringStatus status) throws CoreException {
return internalSearch(new SearchEngine(), pattern, scope, new CollectingSearchRequestor(), monitor, status);
}
- public static SearchResultGroup[] search(SearchPattern pattern, WorkingCopyOwner owner, IDLTKSearchScope scope, IProgressMonitor monitor, RefactoringStatus status)
- throws CoreException {
- return internalSearch(owner != null ? new SearchEngine(owner) : new SearchEngine(), pattern, scope, new CollectingSearchRequestor(), monitor, status);
+ public static SearchResultGroup[] search(SearchPattern pattern, WorkingCopyOwner owner, IDLTKSearchScope scope,
+ IProgressMonitor monitor, RefactoringStatus status) throws CoreException {
+ return internalSearch(owner != null ? new SearchEngine(owner) : new SearchEngine(), pattern, scope,
+ new CollectingSearchRequestor(), monitor, status);
}
- public static SearchResultGroup[] search(SearchPattern pattern, IDLTKSearchScope scope, CollectingSearchRequestor requestor,
- IProgressMonitor monitor, RefactoringStatus status) throws CoreException {
+ public static SearchResultGroup[] search(SearchPattern pattern, IDLTKSearchScope scope,
+ CollectingSearchRequestor requestor, IProgressMonitor monitor, RefactoringStatus status)
+ throws CoreException {
return internalSearch(new SearchEngine(), pattern, scope, requestor, monitor, status);
}
public static SearchResultGroup[] search(SearchPattern pattern, WorkingCopyOwner owner, IDLTKSearchScope scope,
- CollectingSearchRequestor requestor, IProgressMonitor monitor, RefactoringStatus status) throws CoreException {
- return internalSearch(owner != null ? new SearchEngine(owner) : new SearchEngine(), pattern, scope, requestor, monitor, status);
+ CollectingSearchRequestor requestor, IProgressMonitor monitor, RefactoringStatus status)
+ throws CoreException {
+ return internalSearch(owner != null ? new SearchEngine(owner) : new SearchEngine(), pattern, scope, requestor,
+ monitor, status);
}
- private static SearchResultGroup[] internalSearch(SearchEngine searchEngine, SearchPattern pattern, IDLTKSearchScope scope,
- CollectingSearchRequestor requestor, IProgressMonitor monitor, RefactoringStatus status) throws CoreException {
+ private static SearchResultGroup[] internalSearch(SearchEngine searchEngine, SearchPattern pattern,
+ IDLTKSearchScope scope, CollectingSearchRequestor requestor, IProgressMonitor monitor,
+ RefactoringStatus status) throws CoreException {
searchEngine.search(pattern, SearchUtils.getDefaultSearchParticipants(), scope, requestor, monitor);
return groupByCu(requestor.getResults(), status);
}
@@ -130,38 +145,40 @@
}
/**
- * @param matchList a List of SearchMatch
- * @param status the status to report errors.
+ * @param matchList
+ * a List of SearchMatch
+ * @param status
+ * the status to report errors.
* @return a SearchResultGroup[], grouped by SearchMatch#getResource()
*/
public static SearchResultGroup[] groupByCu(List<SearchMatch> matchList, RefactoringStatus status) {
- Map<IResource, List<SearchMatch>> grouped= new HashMap<IResource, List<SearchMatch>>();
- boolean hasPotentialMatches= false;
- boolean hasNonCuMatches= false;
+ Map<IResource, List<SearchMatch>> grouped = new HashMap<>();
+ boolean hasPotentialMatches = false;
+ boolean hasNonCuMatches = false;
for (SearchMatch searchMatch : matchList) {
if (searchMatch.getAccuracy() == SearchMatch.A_INACCURATE)
- hasPotentialMatches= true;
- if (! grouped.containsKey(searchMatch.getResource()))
+ hasPotentialMatches = true;
+ if (!grouped.containsKey(searchMatch.getResource()))
grouped.put(searchMatch.getResource(), new ArrayList<SearchMatch>(1));
grouped.get(searchMatch.getResource()).add(searchMatch);
}
- for (Iterator<IResource> iter= grouped.keySet().iterator(); iter.hasNext();) {
- IResource resource= iter.next();
- IModelElement element= DLTKCore.create(resource);
- if (! (element instanceof ISourceModule)) {
+ for (Iterator<IResource> iter = grouped.keySet().iterator(); iter.hasNext();) {
+ IResource resource = iter.next();
+ IModelElement element = DLTKCore.create(resource);
+ if (!(element instanceof ISourceModule)) {
iter.remove();
- hasNonCuMatches= true;
+ hasNonCuMatches = true;
}
}
- SearchResultGroup[] result= new SearchResultGroup[grouped.keySet().size()];
- int i= 0;
+ SearchResultGroup[] result = new SearchResultGroup[grouped.keySet().size()];
+ int i = 0;
for (IResource resource : grouped.keySet()) {
- List<SearchMatch> searchMatches= grouped.get(resource);
- SearchMatch[] matchArray= searchMatches.toArray(new SearchMatch[searchMatches.size()]);
- result[i]= new SearchResultGroup(resource, matchArray);
+ List<SearchMatch> searchMatches = grouped.get(resource);
+ SearchMatch[] matchArray = searchMatches.toArray(new SearchMatch[searchMatches.size()]);
+ result[i] = new SearchResultGroup(resource, matchArray);
i++;
}
addStatusErrors(status, hasPotentialMatches, hasNonCuMatches);
@@ -171,38 +188,42 @@
public static SearchPattern createOrPattern(IModelElement[] elements, int limitTo, IDLTKLanguageToolkit toolkit) {
if (elements == null || elements.length == 0)
return null;
- Set<IModelElement> set= new HashSet<IModelElement>(Arrays.asList(elements));
- Iterator<IModelElement> iter= set.iterator();
- IModelElement first= iter.next();
- SearchPattern pattern= SearchPattern.createPattern(first, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE, toolkit);
+ Set<IModelElement> set = new HashSet<>(Arrays.asList(elements));
+ Iterator<IModelElement> iter = set.iterator();
+ IModelElement first = iter.next();
+ SearchPattern pattern = SearchPattern.createPattern(first, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE,
+ toolkit);
if (pattern == null) // check for bug 90138
- throw new IllegalArgumentException("Invalid element: " + first.getHandleIdentifier() + "\n" + first.toString()); //$NON-NLS-1$ //$NON-NLS-2$
- while(iter.hasNext()){
- IModelElement each= iter.next();
- SearchPattern nextPattern= SearchPattern.createPattern(each, limitTo, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE, toolkit);
+ throw new IllegalArgumentException(
+ "Invalid element: " + first.getHandleIdentifier() + "\n" + first.toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ while (iter.hasNext()) {
+ IModelElement each = iter.next();
+ SearchPattern nextPattern = SearchPattern.createPattern(each, limitTo,
+ SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE, toolkit);
if (nextPattern == null) // check for bug 90138
- throw new IllegalArgumentException("Invalid element: " + each.getHandleIdentifier() + "\n" + each.toString()); //$NON-NLS-1$ //$NON-NLS-2$
- pattern= SearchPattern.createOrPattern(pattern, nextPattern);
+ throw new IllegalArgumentException(
+ "Invalid element: " + each.getHandleIdentifier() + "\n" + each.toString()); //$NON-NLS-1$ //$NON-NLS-2$
+ pattern = SearchPattern.createOrPattern(pattern, nextPattern);
}
return pattern;
}
private static boolean containsStatusEntry(final RefactoringStatus status, final RefactoringStatusEntry other) {
- return status.getEntries(new IRefactoringStatusEntryComparator() {
- public final int compare(final RefactoringStatusEntry entry1, final RefactoringStatusEntry entry2) {
- return entry1.getMessage().compareTo(entry2.getMessage());
- }
- }, other).length > 0;
+ return status.getEntries((entry1, entry2) -> entry1.getMessage().compareTo(entry2.getMessage()),
+ other).length > 0;
}
- private static void addStatusErrors(RefactoringStatus status, boolean hasPotentialMatches, boolean hasNonCuMatches) {
+ private static void addStatusErrors(RefactoringStatus status, boolean hasPotentialMatches,
+ boolean hasNonCuMatches) {
if (hasPotentialMatches) {
- final RefactoringStatusEntry entry= new RefactoringStatusEntry(RefactoringStatus.ERROR, RefactoringCoreMessages.RefactoringSearchEngine_potential_matches);
+ final RefactoringStatusEntry entry = new RefactoringStatusEntry(RefactoringStatus.ERROR,
+ RefactoringCoreMessages.RefactoringSearchEngine_potential_matches);
if (!containsStatusEntry(status, entry))
status.addEntry(entry);
}
if (hasNonCuMatches) {
- final RefactoringStatusEntry entry= new RefactoringStatusEntry(RefactoringStatus.ERROR, RefactoringCoreMessages.RefactoringSearchEngine_non_cu_matches);
+ final RefactoringStatusEntry entry = new RefactoringStatusEntry(RefactoringStatus.ERROR,
+ RefactoringCoreMessages.RefactoringSearchEngine_non_cu_matches);
if (!containsStatusEntry(status, entry))
status.addEntry(entry);
}
diff --git a/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/changes/DynamicValidationStateChange.java b/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/changes/DynamicValidationStateChange.java
index 64b63f1..bce3c43 100644
--- a/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/changes/DynamicValidationStateChange.java
+++ b/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/changes/DynamicValidationStateChange.java
@@ -1,11 +1,10 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
*
-
*******************************************************************************/
package org.eclipse.dltk.internal.corext.refactoring.changes;
@@ -22,99 +21,93 @@
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
public class DynamicValidationStateChange extends CompositeChange implements WorkspaceTracker.Listener {
-
- private boolean fListenerRegistered= false;
- private RefactoringStatus fValidationState= null;
+
+ private boolean fListenerRegistered = false;
+ private RefactoringStatus fValidationState = null;
private long fTimeStamp;
-
+
// 30 minutes
- private static final long LIFE_TIME= 30 * 60 * 1000;
-
+ private static final long LIFE_TIME = 30 * 60 * 1000;
+
public DynamicValidationStateChange(Change change) {
super(change.getName());
add(change);
markAsSynthetic();
}
-
+
public DynamicValidationStateChange(String name) {
super(name);
markAsSynthetic();
}
-
+
public DynamicValidationStateChange(String name, Change[] changes) {
super(name, changes);
markAsSynthetic();
}
-
- /**
- * {@inheritDoc}
- */
+
+ @Override
public void initializeValidationData(IProgressMonitor pm) {
super.initializeValidationData(pm);
WorkspaceTracker.INSTANCE.addListener(this);
- fListenerRegistered= true;
- fTimeStamp= System.currentTimeMillis();
+ fListenerRegistered = true;
+ fTimeStamp = System.currentTimeMillis();
}
-
+
+ @Override
public void dispose() {
if (fListenerRegistered) {
WorkspaceTracker.INSTANCE.removeListener(this);
- fListenerRegistered= false;
+ fListenerRegistered = false;
}
super.dispose();
}
-
- /**
- * {@inheritDoc}
- */
+
+ @Override
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
if (fValidationState == null) {
return super.isValid(pm);
}
return fValidationState;
}
-
- /**
- * {@inheritDoc}
- */
+
+ @Override
public Change perform(IProgressMonitor pm) throws CoreException {
- final Change[] result= new Change[1];
- IWorkspaceRunnable runnable= new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- result[0]= DynamicValidationStateChange.super.perform(monitor);
- }
- };
+ final Change[] result = new Change[1];
+ IWorkspaceRunnable runnable = monitor -> result[0] = DynamicValidationStateChange.super.perform(monitor);
DLTKCore.run(runnable, pm);
return result[0];
}
- /**
- * {@inheritDoc}
- */
+ @Override
protected Change createUndoChange(Change[] childUndos) {
- DynamicValidationStateChange result= new DynamicValidationStateChange(getName());
- for (int i= 0; i < childUndos.length; i++) {
+ DynamicValidationStateChange result = new DynamicValidationStateChange(getName());
+ for (int i = 0; i < childUndos.length; i++) {
result.add(childUndos[i]);
}
return result;
}
-
+
+ @Override
public void workspaceChanged() {
- long currentTime= System.currentTimeMillis();
+ long currentTime = System.currentTimeMillis();
if (currentTime - fTimeStamp < LIFE_TIME)
return;
- fValidationState= RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.DynamicValidationStateChange_workspace_changed);
+ fValidationState = RefactoringStatus
+ .createFatalErrorStatus(RefactoringCoreMessages.DynamicValidationStateChange_workspace_changed);
// remove listener from workspace tracker
WorkspaceTracker.INSTANCE.removeListener(this);
- fListenerRegistered= false;
+ fListenerRegistered = false;
// clear up the children to not hang onto too much memory
- Change[] children= clear();
- for (int i= 0; i < children.length; i++) {
- final Change change= children[i];
+ Change[] children = clear();
+ for (int i = 0; i < children.length; i++) {
+ final Change change = children[i];
SafeRunner.run(new ISafeRunnable() {
+ @Override
public void run() throws Exception {
change.dispose();
}
+
+ @Override
public void handleException(Throwable exception) {
ScriptManipulationPlugin.log(exception);
}
diff --git a/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/util/TextChangeManager.java b/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/util/TextChangeManager.java
index a094fa5..4d6a7ad 100644
--- a/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/util/TextChangeManager.java
+++ b/core/plugins/org.eclipse.dltk.core.manipulation/src/org/eclipse/dltk/internal/corext/refactoring/util/TextChangeManager.java
@@ -1,16 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
*
-
*******************************************************************************/
package org.eclipse.dltk.internal.corext.refactoring.util;
import java.util.Arrays;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -19,97 +17,101 @@
import org.eclipse.dltk.core.manipulation.SourceModuleChange;
import org.eclipse.ltk.core.refactoring.TextChange;
-
/**
- * A <code>TextChangeManager</code> manages associations between <code>ISourceModule</code>
- * or <code>IFile</code> and <code>TextChange</code> objects.
+ * A <code>TextChangeManager</code> manages associations between
+ * <code>ISourceModule</code> or <code>IFile</code> and <code>TextChange</code>
+ * objects.
*/
public class TextChangeManager {
-
- private Map<ISourceModule, TextChange> fMap= new HashMap<ISourceModule, TextChange>(10);
-
- private final boolean fKeepExecutedTextEdits;
-
- public TextChangeManager() {
- this(false);
- }
- public TextChangeManager(boolean keepExecutedTextEdits) {
- fKeepExecutedTextEdits = keepExecutedTextEdits;
- }
-
+ private Map<ISourceModule, TextChange> fMap = new HashMap<>(10);
+
+ private final boolean fKeepExecutedTextEdits;
+
+ public TextChangeManager() {
+ this(false);
+ }
+
+ public TextChangeManager(boolean keepExecutedTextEdits) {
+ fKeepExecutedTextEdits = keepExecutedTextEdits;
+ }
+
/**
* Adds an association between the given compilation unit and the passed
* change to this manager.
- *
- * @param cu the compilation unit (key)
- * @param change the change associated with the compilation unit
+ *
+ * @param cu
+ * the compilation unit (key)
+ * @param change
+ * the change associated with the compilation unit
*/
public void manage(ISourceModule cu, TextChange change) {
fMap.put(cu, change);
}
-
+
/**
- * Returns the <code>TextChange</code> associated with the given compilation unit.
- * If the manager does not already manage an association it creates a one.
- *
- * @param cu the compilation unit for which the text buffer change is requested
- * @return the text change associated with the given compilation unit.
+ * Returns the <code>TextChange</code> associated with the given compilation
+ * unit. If the manager does not already manage an association it creates a
+ * one.
+ *
+ * @param cu
+ * the compilation unit for which the text buffer change is
+ * requested
+ * @return the text change associated with the given compilation unit.
*/
public TextChange get(ISourceModule cu) {
- TextChange result= fMap.get(cu);
+ TextChange result = fMap.get(cu);
if (result == null) {
- result= new SourceModuleChange(cu.getElementName(), cu);
+ result = new SourceModuleChange(cu.getElementName(), cu);
result.setKeepPreviewEdits(fKeepExecutedTextEdits);
fMap.put(cu, result);
}
return result;
}
-
+
/**
* Removes the <tt>TextChange</tt> managed under the given key
* <code>unit<code>.
- *
+ *
* @param unit the key determining the <tt>TextChange</tt> to be removed.
+ *
* @return the removed <tt>TextChange</tt>.
*/
public TextChange remove(ISourceModule unit) {
return fMap.remove(unit);
}
-
+
/**
* Returns all text changes managed by this instance.
- *
+ *
* @return all text changes managed by this instance
*/
- public TextChange[] getAllChanges(){
- Set<ISourceModule> cuSet= fMap.keySet();
- ISourceModule[] cus= cuSet.toArray(new ISourceModule[cuSet.size()]);
+ public TextChange[] getAllChanges() {
+ Set<ISourceModule> cuSet = fMap.keySet();
+ ISourceModule[] cus = cuSet.toArray(new ISourceModule[cuSet.size()]);
// sort by cu name:
- Arrays.sort(cus, new Comparator<ISourceModule>() {
- public int compare(ISourceModule o1, ISourceModule o2) {
- String name1= o1.getElementName();
- String name2= o2.getElementName();
- return name1.compareTo(name2);
- }
+ Arrays.sort(cus, (o1, o2) -> {
+ String name1 = o1.getElementName();
+ String name2 = o2.getElementName();
+ return name1.compareTo(name2);
});
-
- TextChange[] textChanges= new TextChange[cus.length];
- for (int i= 0; i < cus.length; i++) {
- textChanges[i]= fMap.get(cus[i]);
+
+ TextChange[] textChanges = new TextChange[cus.length];
+ for (int i = 0; i < cus.length; i++) {
+ textChanges[i] = fMap.get(cus[i]);
}
return textChanges;
}
/**
* Returns all compilation units managed by this instance.
- *
+ *
* @return all compilation units managed by this instance
- */
- public ISourceModule[] getAllSourceModules(){
+ */
+ public ISourceModule[] getAllSourceModules() {
return fMap.keySet().toArray(new ISourceModule[fMap.keySet().size()]);
}
-
+
/**
* Clears all associations between resources and text changes.
*/
@@ -118,13 +120,15 @@
}
/**
- * Returns if any text changes are managed for the specified compilation unit.
- *
- * @param cu the compilation unit
- * @return <code>true</code> if any text changes are managed for the specified compilation unit and <code>false</code> otherwise
- */
- public boolean containsChangesIn(ISourceModule cu){
+ * Returns if any text changes are managed for the specified compilation
+ * unit.
+ *
+ * @param cu
+ * the compilation unit
+ * @return <code>true</code> if any text changes are managed for the
+ * specified compilation unit and <code>false</code> otherwise
+ */
+ public boolean containsChangesIn(ISourceModule cu) {
return fMap.containsKey(cu);
}
}
-
diff --git a/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentManager.java b/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentManager.java
index 7fd6b08..edecb2d 100644
--- a/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentManager.java
+++ b/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentManager.java
@@ -14,7 +14,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -89,15 +88,10 @@
protected void initializeDescriptors(
List<Descriptor<IEnvironmentProvider>> descriptors) {
Collections.sort(descriptors,
- new Comparator<Descriptor<IEnvironmentProvider>>() {
- @Override
- public int compare(
- Descriptor<IEnvironmentProvider> arg0,
- Descriptor<IEnvironmentProvider> arg1) {
- EnvironmentProviderDesc d1 = (EnvironmentProviderDesc) arg0;
- EnvironmentProviderDesc d2 = (EnvironmentProviderDesc) arg1;
- return d1.priority - d2.priority;
- }
+ (arg0, arg1) -> {
+ EnvironmentProviderDesc d1 = (EnvironmentProviderDesc) arg0;
+ EnvironmentProviderDesc d2 = (EnvironmentProviderDesc) arg1;
+ return d1.priority - d2.priority;
});
}
@@ -526,15 +520,10 @@
protected void initializeDescriptors(
List<Descriptor<IEnvironmentLocationResolver>> descriptors) {
Collections.sort(descriptors,
- new Comparator<Descriptor<IEnvironmentLocationResolver>>() {
- @Override
- public int compare(
- Descriptor<IEnvironmentLocationResolver> arg0,
- Descriptor<IEnvironmentLocationResolver> arg1) {
- Desc d1 = (Desc) arg0;
- Desc d2 = (Desc) arg1;
- return d1.priority - d2.priority;
- }
+ (arg0, arg1) -> {
+ Desc d1 = (Desc) arg0;
+ Desc d2 = (Desc) arg1;
+ return d1.priority - d2.priority;
});
}
}
diff --git a/core/plugins/org.eclipse.dltk.core/index/org/eclipse/dltk/internal/core/index2/SourceModulesRequest.java b/core/plugins/org.eclipse.dltk.core/index/org/eclipse/dltk/internal/core/index2/SourceModulesRequest.java
index 0840824..9d8b58e 100644
--- a/core/plugins/org.eclipse.dltk.core/index/org/eclipse/dltk/internal/core/index2/SourceModulesRequest.java
+++ b/core/plugins/org.eclipse.dltk.core/index/org/eclipse/dltk/internal/core/index2/SourceModulesRequest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2016 IBM Corporation and others.
+ * Copyright (c) 2009, 2017 IBM Corporation and others.
* 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
@@ -14,7 +14,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -70,13 +69,8 @@
indexer.removeDocument(containerPath, path);
}
- Collections.sort(toReindex, new Comparator<ISourceModule>() {
- @Override
- public int compare(ISourceModule m1, ISourceModule m2) {
- return m1.getPath().toString().compareTo(
- m2.getPath().toString());
- }
- });
+ Collections.sort(toReindex, (m1, m2) -> m1.getPath().toString()
+ .compareTo(m2.getPath().toString()));
for (final ISourceModule sourceModule : toReindex) {
if (isCancelled)
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/builder/ScriptBuilderUtil.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/builder/ScriptBuilderUtil.java
index 35ea199..eea447a 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/builder/ScriptBuilderUtil.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/builder/ScriptBuilderUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2016 NumberFour AG and others.
+ * Copyright (c) 2011, 2017 NumberFour AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -244,23 +244,20 @@
public static void rebuildAfterUpgrade(IProgressMonitor _monitor)
throws CoreException {
final UpgradeCheck check = new UpgradeCheck();
- final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- if (ScriptBuilder.DEBUG) {
- System.out.println("Upgrade check BEGIN");
- }
- final IScriptProject[] projects = DLTKCore.create(
- ResourcesPlugin.getWorkspace().getRoot())
- .getScriptProjects();
- SubMonitor subMonitor = SubMonitor.convert(monitor,
- projects.length);
- for (IScriptProject project : projects) {
- check.checkProject(project, subMonitor.newChild(1));
- }
- if (ScriptBuilder.DEBUG) {
- System.out.println("Upgrade check END");
- }
+ final IWorkspaceRunnable runnable = monitor -> {
+ if (ScriptBuilder.DEBUG) {
+ System.out.println("Upgrade check BEGIN");
+ }
+ final IScriptProject[] projects = DLTKCore
+ .create(ResourcesPlugin.getWorkspace().getRoot())
+ .getScriptProjects();
+ SubMonitor subMonitor = SubMonitor.convert(monitor,
+ projects.length);
+ for (IScriptProject project : projects) {
+ check.checkProject(project, subMonitor.newChild(1));
+ }
+ if (ScriptBuilder.DEBUG) {
+ System.out.println("Upgrade check END");
}
};
ResourcesPlugin.getWorkspace().run(runnable, _monitor);
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ProjectReferenceChange.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ProjectReferenceChange.java
index 01e648c..7a19ead 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ProjectReferenceChange.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ProjectReferenceChange.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
@@ -17,7 +17,6 @@
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.dltk.compiler.CharOperation;
import org.eclipse.dltk.core.IBuildpathEntry;
@@ -110,15 +109,12 @@
ISchedulingRule rule = workspace.getRuleFactory().modifyRule(
projectResource); // scheduling rule for modifying the
// project
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- IProjectDescription description = projectResource
- .getDescription();
- description.setDynamicReferences(requiredProjectArray);
- projectResource.setDescription(description,
- IResource.AVOID_NATURE_CONFIG, null);
- }
+ IWorkspaceRunnable runnable = monitor -> {
+ IProjectDescription description1 = projectResource
+ .getDescription();
+ description1.setDynamicReferences(requiredProjectArray);
+ projectResource.setDescription(description1,
+ IResource.AVOID_NATURE_CONFIG, null);
};
workspace.run(runnable, rule, IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e) {
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/builder/ScriptBuilderManager.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/builder/ScriptBuilderManager.java
index a8b2b15..1794919 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/builder/ScriptBuilderManager.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/builder/ScriptBuilderManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2016 IBM Corporation and others.
+ * Copyright (c) 2005, 2017 IBM Corporation and others.
* 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
@@ -87,14 +87,10 @@
@Override
protected void initializeDescriptors(List<Object> descriptors) {
- Collections.sort(descriptors, new Comparator<Object>() {
-
- @Override
- public int compare(Object o1, Object o2) {
- final IConfigurationElement e1 = (IConfigurationElement) o1;
- final IConfigurationElement e2 = (IConfigurationElement) o2;
- return priorityOf(e2) - priorityOf(e1);
- }
+ Collections.sort(descriptors, (o1, o2) -> {
+ final IConfigurationElement e1 = (IConfigurationElement) o1;
+ final IConfigurationElement e2 = (IConfigurationElement) o2;
+ return priorityOf(e2) - priorityOf(e1);
});
}
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/hierarchy/IndexBasedHierarchyBuilder.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/hierarchy/IndexBasedHierarchyBuilder.java
index 0e64939..a0d504f 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/hierarchy/IndexBasedHierarchyBuilder.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/hierarchy/IndexBasedHierarchyBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
@@ -10,7 +10,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -204,17 +203,14 @@
}
indexes.put(openables[i], index);
}
- Arrays.sort(openables, new Comparator() {
- @Override
- public int compare(Object a, Object b) {
- int aIndex = indexes.get(a);
- int bIndex = indexes.get(b);
- if (aIndex != bIndex) {
- return aIndex - bIndex;
- }
- return ((Openable) b).getElementName().compareTo(
- ((Openable) a).getElementName());
+ Arrays.sort(openables, (a, b) -> {
+ int aIndex = indexes.get(a);
+ int bIndex = indexes.get(b);
+ if (aIndex != bIndex) {
+ return aIndex - bIndex;
}
+ return b.getElementName()
+ .compareTo(a.getElementName());
});
IType focusType = this.getType();
diff --git a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/DLTKSearchParticipant.java b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/DLTKSearchParticipant.java
index e2c772e..20f1251 100644
--- a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/DLTKSearchParticipant.java
+++ b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/DLTKSearchParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
@@ -136,13 +136,8 @@
if (progressMonitor != null) {
progressMonitor.beginTask("", searchDocuments.length); //$NON-NLS-1$
}
- Util.sort(searchDocuments, new Util.Comparer() {
- @Override
- public int compare(Object a, Object b) {
- return ((SearchDocument) a).getPath().compareTo(
- ((SearchDocument) b).getPath());
- }
- });
+ Util.sort(searchDocuments, (a, b) -> ((SearchDocument) a).getPath()
+ .compareTo(((SearchDocument) b).getPath()));
final Set<String> previousPaths = new HashSet<String>();
for (int i = 0; i < docsLength; i++) {
if (progressMonitor != null && progressMonitor.isCanceled()) {
diff --git a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/matching/MatchLocator.java b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/matching/MatchLocator.java
index 0ebf826..3d53908 100644
--- a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/matching/MatchLocator.java
+++ b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/core/search/matching/MatchLocator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
@@ -620,13 +620,8 @@
this.patternLocator.initializePolymorphicSearch(this);
IScriptProject previousScriptProject = null;
PossibleMatchSet matchSet = new PossibleMatchSet();
- Util.sort(searchDocuments, new Util.Comparer() {
- @Override
- public int compare(Object a, Object b) {
- return ((SearchDocument) a).getPath().compareTo(
- ((SearchDocument) b).getPath());
- }
- });
+ Util.sort(searchDocuments, (a, b) -> ((SearchDocument) a).getPath()
+ .compareTo(((SearchDocument) b).getPath()));
int displayed = 0; // progress worked displayed
final Set<String> previousPaths = new HashSet<String>();
for (int i = 0; i < docsLength; i++) {
diff --git a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/internal/core/search/matching/MatchingNodeSet.java b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/internal/core/search/matching/MatchingNodeSet.java
index 17e741c..0bb4628 100644
--- a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/internal/core/search/matching/MatchingNodeSet.java
+++ b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/internal/core/search/matching/MatchingNodeSet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
@@ -134,13 +134,8 @@
ASTNode[] result = new ASTNode[nodes.size()];
nodes.toArray(result);
// sort nodes by source starts
- Util.Comparer comparer = new Util.Comparer() {
- @Override
- public int compare(Object o1, Object o2) {
- return ((ASTNode) o1).sourceStart()
- - ((ASTNode) o2).sourceStart();
- }
- };
+ Util.Comparer comparer = (o1, o2) -> ((ASTNode) o1).sourceStart()
+ - ((ASTNode) o2).sourceStart();
Util.sort(result, comparer);
return result;
}
diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/internal/ExcludeRegionList.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/internal/ExcludeRegionList.java
index 7968b67..aeed7fc 100644
--- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/internal/ExcludeRegionList.java
+++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/internal/ExcludeRegionList.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 xored software, Inc. and others.
+ * Copyright (c) 2008, 2017 xored software, Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -95,13 +95,6 @@
Collections.sort(excludes, REGION_COMPARATOR);
}
- private static final Comparator<IRegion> REGION_COMPARATOR = new Comparator<IRegion>() {
-
- @Override
- public int compare(IRegion o1, IRegion o2) {
- return o1.getOffset() - o2.getOffset();
- }
-
- };
+ private static final Comparator<IRegion> REGION_COMPARATOR = (o1, o2) -> o1.getOffset() - o2.getOffset();
}
diff --git a/core/plugins/org.eclipse.dltk.launching/src/org/eclipse/dltk/internal/launching/DLTKLaunchingPlugin.java b/core/plugins/org.eclipse.dltk.launching/src/org/eclipse/dltk/internal/launching/DLTKLaunchingPlugin.java
index d1c885b..722b12b 100644
--- a/core/plugins/org.eclipse.dltk.launching/src/org/eclipse/dltk/internal/launching/DLTKLaunchingPlugin.java
+++ b/core/plugins/org.eclipse.dltk.launching/src/org/eclipse/dltk/internal/launching/DLTKLaunchingPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2016 IBM Corporation and others.
+ * Copyright (c) 2005, 2017 IBM Corporation and others.
* 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
@@ -263,8 +263,7 @@
ID_EXTENSION_POINT_RUNTIME_BUILDPATH_ENTRIES);
IConfigurationElement[] configs = extensionPoint
.getConfigurationElements();
- fBuildpathEntryExtensions = new HashMap<>(
- configs.length);
+ fBuildpathEntryExtensions = new HashMap<>(configs.length);
for (int i = 0; i < configs.length; i++) {
fBuildpathEntryExtensions.put(configs[i].getAttribute("id"), //$NON-NLS-1$
configs[i]);
@@ -664,18 +663,14 @@
}
protected void doit(IProgressMonitor monitor) throws CoreException {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor1)
- throws CoreException {
- IScriptProject[] projects = DLTKCore
- .create(ResourcesPlugin.getWorkspace().getRoot())
- .getScriptProjects();
- monitor1.beginTask(LaunchingMessages.LaunchingPlugin_0,
- projects.length + 1);
- rebind(monitor1, projects, fRenamedContainerIds);
- monitor1.done();
- }
+ IWorkspaceRunnable runnable = monitor1 -> {
+ IScriptProject[] projects = DLTKCore
+ .create(ResourcesPlugin.getWorkspace().getRoot())
+ .getScriptProjects();
+ monitor1.beginTask(LaunchingMessages.LaunchingPlugin_0,
+ projects.length + 1);
+ rebind(monitor1, projects, fRenamedContainerIds);
+ monitor1.done();
};
DLTKCore.run(runnable, null, monitor);
}
diff --git a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/TestCategoryEngineManager.java b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/TestCategoryEngineManager.java
index 5f74b11..0e0bee9 100644
--- a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/TestCategoryEngineManager.java
+++ b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/TestCategoryEngineManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2016 xored software, Inc. and others.
+ * Copyright (c) 2008, 2017 xored software, Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -25,8 +25,8 @@
import org.eclipse.dltk.testing.ITestRunnerUI;
import org.eclipse.dltk.utils.NatureExtensionManager;
-public class TestCategoryEngineManager extends
- NatureExtensionManager<TestCategoryEngineManager.Descriptor> {
+public class TestCategoryEngineManager
+ extends NatureExtensionManager<TestCategoryEngineManager.Descriptor> {
private static final String EXTENSION_POINT = DLTKTestingPlugin.PLUGIN_ID
+ ".categoryEngine"; //$NON-NLS-1$
@@ -65,15 +65,10 @@
return new Descriptor(confElement, priority);
}
- private final Comparator<Object> descriptorComparator = new Comparator<Object>() {
-
- @Override
- public int compare(Object o1, Object o2) {
- Descriptor descriptor1 = (Descriptor) o1;
- Descriptor descriptor2 = (Descriptor) o2;
- return descriptor1.priority - descriptor2.priority;
- }
-
+ private final Comparator<Object> descriptorComparator = (o1, o2) -> {
+ Descriptor descriptor1 = (Descriptor) o1;
+ Descriptor descriptor2 = (Descriptor) o2;
+ return descriptor1.priority - descriptor2.priority;
};
@Override
@@ -104,7 +99,7 @@
/**
* Returns the category engines registered for the specified testing engine
* or <code>null</code>.
- *
+ *
* @param runnerUI
* @return
*/
@@ -113,12 +108,12 @@
if (runnerUI instanceof NullTestRunnerUI) {
return null;
}
- final Descriptor[] descriptors = getInstance().getInstances(
- runnerUI.getTestingEngine().getId());
+ final Descriptor[] descriptors = getInstance()
+ .getInstances(runnerUI.getTestingEngine().getId());
if (descriptors == null) {
return null;
}
- final List<ITestCategoryEngine> result = new ArrayList<ITestCategoryEngine>(
+ final List<ITestCategoryEngine> result = new ArrayList<>(
descriptors.length);
for (int i = 0; i < descriptors.length; ++i) {
final Descriptor descriptor = descriptors[i];
diff --git a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/TestingEngineManager.java b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/TestingEngineManager.java
index 39edc1d..d6149fd 100644
--- a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/TestingEngineManager.java
+++ b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/TestingEngineManager.java
@@ -11,8 +11,8 @@
import org.eclipse.dltk.internal.testing.util.NumberUtils;
import org.eclipse.dltk.utils.NatureExtensionManager;
-public final class TestingEngineManager extends
- NatureExtensionManager<ITestingEngine> {
+public final class TestingEngineManager
+ extends NatureExtensionManager<ITestingEngine> {
private static final String EXTENSION_POINT = DLTKTestingPlugin.PLUGIN_ID
+ ".engine"; //$NON-NLS-1$
@@ -46,15 +46,10 @@
return new Descriptor(confElement, priority);
}
- private final Comparator<Object> descriptorComparator = new Comparator<Object>() {
-
- @Override
- public int compare(Object o1, Object o2) {
- Descriptor descriptor1 = (Descriptor) o1;
- Descriptor descriptor2 = (Descriptor) o2;
- return descriptor1.priority - descriptor2.priority;
- }
-
+ private final Comparator<Object> descriptorComparator = (o1, o2) -> {
+ Descriptor descriptor1 = (Descriptor) o1;
+ Descriptor descriptor2 = (Descriptor) o2;
+ return descriptor1.priority - descriptor2.priority;
};
@Override
@@ -90,7 +85,7 @@
/**
* Returns the {@link ITestingEngine} with the specified engineId or
* <code>null</code>.
- *
+ *
* @param engineId
* @return
*/
diff --git a/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/refactoring/reorg/ScriptDeleteProcessor.java b/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/refactoring/reorg/ScriptDeleteProcessor.java
index 092ca75..3762d77 100644
--- a/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/refactoring/reorg/ScriptDeleteProcessor.java
+++ b/core/plugins/org.eclipse.dltk.ui/core refactoring/org/eclipse/dltk/internal/corext/refactoring/reorg/ScriptDeleteProcessor.java
@@ -11,7 +11,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -61,8 +60,8 @@
import org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker;
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
-
-public final class ScriptDeleteProcessor extends DeleteProcessor implements ICommentProvider {
+public final class ScriptDeleteProcessor extends DeleteProcessor
+ implements ICommentProvider {
private boolean fWasCanceled;
private Object[] fElements;
@@ -75,17 +74,19 @@
private Change fDeleteChange;
private boolean fDeleteSubPackages;
- public static final String IDENTIFIER= "org.eclipse.dltk.ui.DeleteProcessor"; //$NON-NLS-1$
+ public static final String IDENTIFIER = "org.eclipse.dltk.ui.DeleteProcessor"; //$NON-NLS-1$
public ScriptDeleteProcessor(Object[] elements) {
- fElements= elements;
- fResources= RefactoringAvailabilityTester.getResources(elements);
- fScriptElements= RefactoringAvailabilityTester.getScriptElements(elements);
- fDeleteSubPackages= false;
- fWasCanceled= false;
+ fElements = elements;
+ fResources = RefactoringAvailabilityTester.getResources(elements);
+ fScriptElements = RefactoringAvailabilityTester
+ .getScriptElements(elements);
+ fDeleteSubPackages = false;
+ fWasCanceled = false;
}
- //---- IRefactoringProcessor ---------------------------------------------------
+ // ---- IRefactoringProcessor
+ // ---------------------------------------------------
@Override
public String getIdentifier() {
@@ -98,12 +99,13 @@
return false;
if (fElements.length != fResources.length + fScriptElements.length)
return false;
- for (int i= 0; i < fResources.length; i++) {
+ for (int i = 0; i < fResources.length; i++) {
if (!RefactoringAvailabilityTester.isDeleteAvailable(fResources[i]))
return false;
}
- for (int i= 0; i < fScriptElements.length; i++) {
- if (!RefactoringAvailabilityTester.isDeleteAvailable(fScriptElements[i]))
+ for (int i = 0; i < fScriptElements.length; i++) {
+ if (!RefactoringAvailabilityTester
+ .isDeleteAvailable(fScriptElements[i]))
return false;
}
return true;
@@ -113,8 +115,8 @@
if (fResources != null && fResources.length > 0)
return true;
if (fScriptElements != null) {
- for (int i= 0; i < fScriptElements.length; i++) {
- int type= fScriptElements[i].getElementType();
+ for (int i = 0; i < fScriptElements.length; i++) {
+ int type = fScriptElements[i].getElementType();
if (type <= IModelElement.SOURCE_MODULE)
return true;
}
@@ -134,13 +136,17 @@
}
@Override
- public RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants shared) throws CoreException {
- return fDeleteModifications.loadParticipants(status, this, getAffectedProjectNatures(), shared);
+ public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
+ SharableParticipants shared) throws CoreException {
+ return fDeleteModifications.loadParticipants(status, this,
+ getAffectedProjectNatures(), shared);
}
private String[] getAffectedProjectNatures() throws CoreException {
- String[] jNatures= ScriptProcessors.computeAffectedNaturs(fScriptElements);
- String[] rNatures= ResourceProcessors.computeAffectedNatures(fResources);
+ String[] jNatures = ScriptProcessors
+ .computeAffectedNaturs(fScriptElements);
+ String[] rNatures = ResourceProcessors
+ .computeAffectedNatures(fResources);
Set<String> result = new HashSet<String>();
result.addAll(Arrays.asList(jNatures));
result.addAll(Arrays.asList(rNatures));
@@ -148,7 +154,7 @@
}
public void setDeleteSubPackages(boolean selection) {
- fDeleteSubPackages= selection;
+ fDeleteSubPackages = selection;
}
public boolean getDeleteSubPackages() {
@@ -157,11 +163,12 @@
public boolean hasSubPackagesToDelete() {
try {
- for (int i= 0; i < fScriptElements.length; i++) {
+ for (int i = 0; i < fScriptElements.length; i++) {
if (fScriptElements[i] instanceof IScriptFolder) {
- IScriptFolder scriptFolder= (IScriptFolder) fScriptElements[i];
+ IScriptFolder scriptFolder = (IScriptFolder) fScriptElements[i];
if (scriptFolder.isRootFolder())
- continue; // see bug 132576 (can remove this if(..) continue; statement when bug is fixed)
+ continue; // see bug 132576 (can remove this if(..)
+ // continue; statement when bug is fixed)
if (scriptFolder.hasSubfolders())
return true;
}
@@ -172,12 +179,12 @@
return false;
}
- public void setQueries(IReorgQueries queries){
+ public void setQueries(IReorgQueries queries) {
Assert.isNotNull(queries);
- fDeleteQueries= queries;
+ fDeleteQueries = queries;
}
- public IModelElement[] getScriptElementsToDelete(){
+ public IModelElement[] getScriptElementsToDelete() {
return fScriptElements;
}
@@ -185,85 +192,103 @@
return fWasCanceled;
}
- public IResource[] getResourcesToDelete(){
+ public IResource[] getResourcesToDelete() {
return fResources;
}
- /* (non-Javadoc)
- * @see org.eclipse.dltk.internal.corext.refactoring.base.Refactoring#checkActivation(org.eclipse.core.runtime.IProgressMonitor)
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.dltk.internal.corext.refactoring.base.Refactoring#
+ * checkActivation(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
- public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
- Assert.isNotNull(fDeleteQueries);//must be set before checking activation
- RefactoringStatus result= new RefactoringStatus();
- result.merge(RefactoringStatus.create(Resources.checkInSync(ReorgUtils.getNotLinked(fResources))));
- IResource[] javaResources= ReorgUtils.getResources(fScriptElements);
- result.merge(RefactoringStatus.create(Resources.checkInSync(ReorgUtils
- .getNotLinked(javaResources))));
- for (int i= 0; i < fScriptElements.length; i++) {
-// IModelElement element= fScriptElements[i];
-// if (element instanceof IType && ((IType)element).isAnonymous()) {
-// // work around for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=44450
-// // result.addFatalError("Currently, there isn't any support to delete an anonymous type.");
-// }
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
+ throws CoreException {
+ Assert.isNotNull(fDeleteQueries);// must be set before checking
+ // activation
+ RefactoringStatus result = new RefactoringStatus();
+ result.merge(RefactoringStatus.create(
+ Resources.checkInSync(ReorgUtils.getNotLinked(fResources))));
+ IResource[] javaResources = ReorgUtils.getResources(fScriptElements);
+ result.merge(RefactoringStatus.create(
+ Resources.checkInSync(ReorgUtils.getNotLinked(javaResources))));
+ for (int i = 0; i < fScriptElements.length; i++) {
+ // IModelElement element= fScriptElements[i];
+ // if (element instanceof IType && ((IType)element).isAnonymous()) {
+ // // work around for bug
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=44450
+ // // result.addFatalError("Currently, there isn't any support to
+ // delete an anonymous type.");
+ // }
}
return result;
}
- /* (non-Javadoc)
- * @see org.eclipse.dltk.internal.corext.refactoring.base.Refactoring#checkInput(org.eclipse.core.runtime.IProgressMonitor)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.dltk.internal.corext.refactoring.base.Refactoring#checkInput(
+ * org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
- public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException {
+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
+ CheckConditionsContext context) throws CoreException {
pm.beginTask(RefactoringCoreMessages.DeleteRefactoring_1, 1);
- try{
- fWasCanceled= false;
- RefactoringStatus result= new RefactoringStatus();
+ try {
+ fWasCanceled = false;
+ RefactoringStatus result = new RefactoringStatus();
recalculateElementsToDelete();
- TextChangeManager manager= new TextChangeManager();
- fDeleteChange= DeleteChangeCreator.createDeleteChange(manager, fResources, fScriptElements, getProcessorName());
+ TextChangeManager manager = new TextChangeManager();
+ fDeleteChange = DeleteChangeCreator.createDeleteChange(manager,
+ fResources, fScriptElements, getProcessorName());
checkDirtySourceModules(result);
checkDirtyResources(result);
- fDeleteModifications= new DeleteModifications();
+ fDeleteModifications = new DeleteModifications();
fDeleteModifications.delete(fResources);
fDeleteModifications.delete(fScriptElements);
fDeleteModifications.postProcess();
- ResourceChangeChecker checker= (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
- IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory();
+ ResourceChangeChecker checker = (ResourceChangeChecker) context
+ .getChecker(ResourceChangeChecker.class);
+ IResourceChangeDescriptionFactory deltaFactory = checker
+ .getDeltaFactory();
fDeleteModifications.buildDelta(deltaFactory);
- IFile[] files= getBuildpathFiles();
- for (int i= 0; i < files.length; i++) {
+ IFile[] files = getBuildpathFiles();
+ for (int i = 0; i < files.length; i++) {
deltaFactory.change(files[i]);
}
- files= ResourceUtil.getFiles(manager.getAllSourceModules());
- for (int i= 0; i < files.length; i++) {
+ files = ResourceUtil.getFiles(manager.getAllSourceModules());
+ for (int i = 0; i < files.length; i++) {
deltaFactory.change(files[i]);
}
return result;
} catch (OperationCanceledException e) {
- fWasCanceled= true;
+ fWasCanceled = true;
throw e;
- } catch (ModelException e){
+ } catch (ModelException e) {
throw e;
} catch (CoreException e) {
throw new ModelException(e);
- } finally{
+ } finally {
pm.done();
}
}
- private void checkDirtySourceModules(RefactoringStatus result) throws CoreException {
+ private void checkDirtySourceModules(RefactoringStatus result)
+ throws CoreException {
if (fScriptElements == null || fScriptElements.length == 0)
return;
- for (int je= 0; je < fScriptElements.length; je++) {
- IModelElement element= fScriptElements[je];
+ for (int je = 0; je < fScriptElements.length; je++) {
+ IModelElement element = fScriptElements[je];
if (element instanceof ISourceModule) {
- checkDirtySourceModule(result, (ISourceModule)element);
+ checkDirtySourceModule(result, (ISourceModule) element);
} else if (element instanceof IScriptFolder) {
- ISourceModule[] units= ((IScriptFolder)element).getSourceModules();
+ ISourceModule[] units = ((IScriptFolder) element)
+ .getSourceModules();
for (int u = 0; u < units.length; u++) {
checkDirtySourceModule(result, units[u]);
}
@@ -271,24 +296,23 @@
}
}
- private void checkDirtySourceModule(RefactoringStatus result, ISourceModule cunit) {
- IResource resource= cunit.getResource();
+ private void checkDirtySourceModule(RefactoringStatus result,
+ ISourceModule cunit) {
+ IResource resource = cunit.getResource();
if (resource == null || resource.getType() != IResource.FILE)
return;
- checkDirtyFile(result, (IFile)resource);
+ checkDirtyFile(result, (IFile) resource);
}
- private void checkDirtyResources(final RefactoringStatus result) throws CoreException {
- for (int i= 0; i < fResources.length; i++) {
- IResource resource= fResources[i];
- resource.accept(new IResourceVisitor() {
- @Override
- public boolean visit(IResource visitedResource) throws CoreException {
- if (visitedResource instanceof IFile) {
- checkDirtyFile(result, (IFile)visitedResource);
- }
- return true;
+ private void checkDirtyResources(final RefactoringStatus result)
+ throws CoreException {
+ for (int i = 0; i < fResources.length; i++) {
+ IResource resource = fResources[i];
+ resource.accept((IResourceVisitor) visitedResource -> {
+ if (visitedResource instanceof IFile) {
+ checkDirtyFile(result, (IFile) visitedResource);
}
+ return true;
}, IResource.DEPTH_INFINITE, false);
}
}
@@ -296,45 +320,73 @@
private void checkDirtyFile(RefactoringStatus result, IFile file) {
if (file == null || !file.exists())
return;
- ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.NORMALIZE);
+ ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager()
+ .getTextFileBuffer(file.getFullPath(), LocationKind.NORMALIZE);
if (buffer != null && buffer.isDirty()) {
if (buffer.isStateValidated() && buffer.isSynchronized()) {
result.addWarning(Messages.format(
- RefactoringCoreMessages.ScriptDeleteProcessor_unsaved_changes,
- file.getFullPath().toString()));
+ RefactoringCoreMessages.ScriptDeleteProcessor_unsaved_changes,
+ file.getFullPath().toString()));
} else {
result.addFatalError(Messages.format(
- RefactoringCoreMessages.ScriptDeleteProcessor_unsaved_changes,
- file.getFullPath().toString()));
+ RefactoringCoreMessages.ScriptDeleteProcessor_unsaved_changes,
+ file.getFullPath().toString()));
}
}
}
/*
- * The set of elements that will eventually be deleted may be very different from the set
- * originally selected - there may be fewer, more or different elements.
- * This method is used to calculate the set of elements that will be deleted - if necessary,
- * it asks the user.
+ * The set of elements that will eventually be deleted may be very different
+ * from the set originally selected - there may be fewer, more or different
+ * elements. This method is used to calculate the set of elements that will
+ * be deleted - if necessary, it asks the user.
*/
private void recalculateElementsToDelete() throws CoreException {
- //the sequence is critical here
+ // the sequence is critical here
- if (fDeleteSubPackages) /* add subpackages first, to allow removing elements with parents in selection etc. */
+ if (fDeleteSubPackages) /*
+ * add subpackages first, to allow removing
+ * elements with parents in selection etc.
+ */
addSubPackages();
- removeElementsWithParentsInSelection(); /*ask before adding empty cus - you don't want to ask if you, for example delete
- *the package, in which the cus live*/
- removeUnconfirmedFoldersThatContainSourceFolders(); /* a selected folder may be a parent of a source folder
- * we must inform the user about it and ask if ok to delete the folder*/
+ removeElementsWithParentsInSelection(); /*
+ * ask before adding empty cus -
+ * you don't want to ask if you,
+ * for example delete the
+ * package, in which the cus
+ * live
+ */
+ removeUnconfirmedFoldersThatContainSourceFolders(); /*
+ * a selected folder
+ * may be a parent
+ * of a source
+ * folder we must
+ * inform the user
+ * about it and ask
+ * if ok to delete
+ * the folder
+ */
removeUnconfirmedReferencedArchives();
addEmptySourceModulesToDelete();
- removeScriptElementsChildrenOfScriptElements();/*because adding cus may create elements (types in cus)
- *whose parents are in selection*/
- confirmDeletingReadOnly(); /*after empty cus - you want to ask for all cus that are to be deleted*/
+ removeScriptElementsChildrenOfScriptElements();/*
+ * because adding cus
+ * may create elements
+ * (types in cus) whose
+ * parents are in
+ * selection
+ */
+ confirmDeletingReadOnly(); /*
+ * after empty cus - you want to ask for all
+ * cus that are to be deleted
+ */
-
-
- addDeletableParentPackagesOnPackageDeletion(); /* do not change the sequence in fScriptElements after this method */
+ addDeletableParentPackagesOnPackageDeletion(); /*
+ * do not change the
+ * sequence in
+ * fScriptElements after
+ * this method
+ */
}
/**
@@ -346,9 +398,11 @@
private void addSubPackages() throws ModelException {
final Set<IModelElement> modelElements = new HashSet<IModelElement>();
- for (int i= 0; i < fScriptElements.length; i++) {
+ for (int i = 0; i < fScriptElements.length; i++) {
if (fScriptElements[i] instanceof IScriptFolder) {
- modelElements.addAll(Arrays.asList(ModelElementUtil.getPackageAndSubpackages((IScriptFolder) fScriptElements[i])));
+ modelElements.addAll(
+ Arrays.asList(ModelElementUtil.getPackageAndSubpackages(
+ (IScriptFolder) fScriptElements[i])));
} else {
modelElements.add(fScriptElements[i]);
}
@@ -363,27 +417,27 @@
*
* @throws CoreException
*/
- private void addDeletableParentPackagesOnPackageDeletion() throws CoreException {
+ private void addDeletableParentPackagesOnPackageDeletion()
+ throws CoreException {
- final List/* <IScriptFolder */initialPackagesToDelete= ReorgUtils.getElementsOfType(fScriptElements, IModelElement.SCRIPT_FOLDER);
+ final List/* <IScriptFolder */ initialPackagesToDelete = ReorgUtils
+ .getElementsOfType(fScriptElements,
+ IModelElement.SCRIPT_FOLDER);
if (initialPackagesToDelete.size() == 0)
return;
// Move from inner to outer packages
- Collections.sort(initialPackagesToDelete, new Comparator() {
- @Override
- public int compare(Object arg0, Object arg1) {
- IScriptFolder one= (IScriptFolder) arg0;
- IScriptFolder two= (IScriptFolder) arg1;
- return two.getElementName().compareTo(one.getElementName());
- }
+ Collections.sort(initialPackagesToDelete, (arg0, arg1) -> {
+ IScriptFolder one = (IScriptFolder) arg0;
+ IScriptFolder two = (IScriptFolder) arg1;
+ return two.getElementName().compareTo(one.getElementName());
});
// Get resources andscriptelements which will be deleted as well
- final Set/* <IResource> */deletedChildren= new HashSet();
+ final Set/* <IResource> */ deletedChildren = new HashSet();
deletedChildren.addAll(Arrays.asList(fResources));
- for (int i= 0; i < fScriptElements.length; i++) {
+ for (int i = 0; i < fScriptElements.length; i++) {
if (!ReorgUtils.isInsideSourceModule(fScriptElements[i]))
deletedChildren.add(fScriptElements[i].getResource());
}
@@ -391,19 +445,25 @@
// new package list in the right sequence
final List<IScriptFolder> allFragmentsToDelete = new ArrayList<IScriptFolder>();
- for (Iterator outerIter= initialPackagesToDelete.iterator(); outerIter.hasNext();) {
- final IScriptFolder currentScriptFolder= (IScriptFolder) outerIter.next();
+ for (Iterator outerIter = initialPackagesToDelete.iterator(); outerIter
+ .hasNext();) {
+ final IScriptFolder currentScriptFolder = (IScriptFolder) outerIter
+ .next();
// The package will at least be cleared
allFragmentsToDelete.add(currentScriptFolder);
- if (canRemoveCompletely(currentScriptFolder, initialPackagesToDelete)) {
+ if (canRemoveCompletely(currentScriptFolder,
+ initialPackagesToDelete)) {
- final IScriptFolder parent= ModelElementUtil.getParentSubpackage(currentScriptFolder);
- if (parent != null && !initialPackagesToDelete.contains(parent)) {
+ final IScriptFolder parent = ModelElementUtil
+ .getParentSubpackage(currentScriptFolder);
+ if (parent != null
+ && !initialPackagesToDelete.contains(parent)) {
- final List/* <IScriptFolder> */emptyParents= new ArrayList();
- addDeletableParentPackages(parent, initialPackagesToDelete, deletedChildren, emptyParents);
+ final List/* <IScriptFolder> */ emptyParents = new ArrayList();
+ addDeletableParentPackages(parent, initialPackagesToDelete,
+ deletedChildren, emptyParents);
// Add parents in the right sequence (inner to outer)
allFragmentsToDelete.addAll(emptyParents);
@@ -413,10 +473,11 @@
// Remove resources in deleted packages; and the packages as well
final List<IModelElement> modelElements = new ArrayList<IModelElement>();
- for (int i= 0; i < fScriptElements.length; i++) {
+ for (int i = 0; i < fScriptElements.length; i++) {
if (!(fScriptElements[i] instanceof IScriptFolder)) {
// remove children of deleted packages
- final IScriptFolder frag= (IScriptFolder) fScriptElements[i].getAncestor(IModelElement.SCRIPT_FOLDER);
+ final IScriptFolder frag = (IScriptFolder) fScriptElements[i]
+ .getAncestor(IModelElement.SCRIPT_FOLDER);
if (!allFragmentsToDelete.contains(frag))
modelElements.add(fScriptElements[i]);
}
@@ -426,10 +487,10 @@
// Remove resources in deleted folders
final List<IResource> resources = new ArrayList<IResource>();
- for (int i= 0; i < fResources.length; i++) {
- IResource parent= fResources[i];
+ for (int i = 0; i < fResources.length; i++) {
+ IResource parent = fResources[i];
if (parent.getType() == IResource.FILE)
- parent= parent.getParent();
+ parent = parent.getParent();
if (!deletedChildren.contains(parent))
resources.add(fResources[i]);
}
@@ -440,14 +501,17 @@
}
/**
- * Returns true if this initially selected package is really deletable
- * (if it has non-selected subpackages, it may only be cleared).
+ * Returns true if this initially selected package is really deletable (if
+ * it has non-selected subpackages, it may only be cleared).
*
*/
- private boolean canRemoveCompletely(IScriptFolder pack, List packagesToDelete) throws ModelException {
- final IScriptFolder[] subPackages= ModelElementUtil.getPackageAndSubpackages(pack);
- for (int i= 0; i < subPackages.length; i++) {
- if (!(subPackages[i].equals(pack)) && !(packagesToDelete.contains(subPackages[i])))
+ private boolean canRemoveCompletely(IScriptFolder pack,
+ List packagesToDelete) throws ModelException {
+ final IScriptFolder[] subPackages = ModelElementUtil
+ .getPackageAndSubpackages(pack);
+ for (int i = 0; i < subPackages.length; i++) {
+ if (!(subPackages[i].equals(pack))
+ && !(packagesToDelete.contains(subPackages[i])))
return false;
}
return true;
@@ -455,21 +519,27 @@
/**
* Adds deletable parent packages of the fragment "frag" to the list
- * "deletableParentPackages"; also adds the resources of those packages to the
- * set "resourcesToDelete".
+ * "deletableParentPackages"; also adds the resources of those packages to
+ * the set "resourcesToDelete".
*
*/
- private void addDeletableParentPackages(IScriptFolder frag, List initialPackagesToDelete, Set resourcesToDelete, List deletableParentPackages)
- throws CoreException {
+ private void addDeletableParentPackages(IScriptFolder frag,
+ List initialPackagesToDelete, Set resourcesToDelete,
+ List deletableParentPackages) throws CoreException {
if (frag.getResource().isLinked()) {
- final IConfirmQuery query= fDeleteQueries.createYesNoQuery(RefactoringCoreMessages.ScriptDeleteProcessor_confirm_linked_folder_delete, false, IReorgQueries.CONFIRM_DELETE_LINKED_PARENT);
- if (!query.confirm(Messages.format(RefactoringCoreMessages.ScriptDeleteProcessor_delete_linked_folder_question, new String[] { frag.getResource().getName() })))
- return;
+ final IConfirmQuery query = fDeleteQueries.createYesNoQuery(
+ RefactoringCoreMessages.ScriptDeleteProcessor_confirm_linked_folder_delete,
+ false, IReorgQueries.CONFIRM_DELETE_LINKED_PARENT);
+ if (!query.confirm(Messages.format(
+ RefactoringCoreMessages.ScriptDeleteProcessor_delete_linked_folder_question,
+ new String[] { frag.getResource().getName() })))
+ return;
}
- final IResource[] children= (((IContainer) frag.getResource())).members();
- for (int i= 0; i < children.length; i++) {
+ final IResource[] children = (((IContainer) frag.getResource()))
+ .members();
+ for (int i = 0; i < children.length; i++) {
// Child must be a package fragment already in the list,
// or a resource which is deleted as well.
if (!resourcesToDelete.contains(children[i]))
@@ -478,36 +548,42 @@
resourcesToDelete.add(frag.getResource());
deletableParentPackages.add(frag);
- final IScriptFolder parent= ModelElementUtil.getParentSubpackage(frag);
+ final IScriptFolder parent = ModelElementUtil.getParentSubpackage(frag);
if (parent != null && !initialPackagesToDelete.contains(parent))
- addDeletableParentPackages(parent, initialPackagesToDelete, resourcesToDelete, deletableParentPackages);
+ addDeletableParentPackages(parent, initialPackagesToDelete,
+ resourcesToDelete, deletableParentPackages);
}
// ask for confirmation of deletion of all package fragment roots that are
// on buildpaths of other projects
private void removeUnconfirmedReferencedArchives() throws ModelException {
- String queryTitle= RefactoringCoreMessages.DeleteRefactoring_2;
- IConfirmQuery query= fDeleteQueries.createYesYesToAllNoNoToAllQuery(queryTitle, true, IReorgQueries.CONFIRM_DELETE_REFERENCED_ARCHIVES);
+ String queryTitle = RefactoringCoreMessages.DeleteRefactoring_2;
+ IConfirmQuery query = fDeleteQueries.createYesYesToAllNoNoToAllQuery(
+ queryTitle, true,
+ IReorgQueries.CONFIRM_DELETE_REFERENCED_ARCHIVES);
removeUnconfirmedReferencedProjectFragments(query);
removeUnconfirmedReferencedArchiveFiles(query);
}
- private void removeUnconfirmedReferencedArchiveFiles(IConfirmQuery query) throws ModelException, OperationCanceledException {
+ private void removeUnconfirmedReferencedArchiveFiles(IConfirmQuery query)
+ throws ModelException, OperationCanceledException {
List<IFile> filesToSkip = new ArrayList<IFile>(0);
- for (int i= 0; i < fResources.length; i++) {
- IResource resource= fResources[i];
- if (! (resource instanceof IFile))
+ for (int i = 0; i < fResources.length; i++) {
+ IResource resource = fResources[i];
+ if (!(resource instanceof IFile))
continue;
- IScriptProject project= DLTKCore.create(resource.getProject());
- if (project == null || ! project.exists())
+ IScriptProject project = DLTKCore.create(resource.getProject());
+ if (project == null || !project.exists())
continue;
- IProjectFragment root= project.findProjectFragment(resource.getFullPath());
+ IProjectFragment root = project
+ .findProjectFragment(resource.getFullPath());
if (root == null)
continue;
- List referencingProjects= new ArrayList(1);
+ List referencingProjects = new ArrayList(1);
referencingProjects.add(root.getScriptProject());
- referencingProjects.addAll(Arrays.asList(ModelElementUtil.getReferencingProjects(root)));
+ referencingProjects.addAll(Arrays
+ .asList(ModelElementUtil.getReferencingProjects(root)));
if (skipDeletingReferencedRoot(query, root, referencingProjects))
filesToSkip.add((IFile) resource);
}
@@ -515,14 +591,17 @@
filesToSkip.toArray(new IFile[filesToSkip.size()]));
}
- private void removeUnconfirmedReferencedProjectFragments(IConfirmQuery query) throws ModelException, OperationCanceledException {
+ private void removeUnconfirmedReferencedProjectFragments(
+ IConfirmQuery query)
+ throws ModelException, OperationCanceledException {
List<IModelElement> rootsToSkip = new ArrayList<IModelElement>(0);
- for (int i= 0; i < fScriptElements.length; i++) {
- IModelElement element= fScriptElements[i];
- if (! (element instanceof IProjectFragment))
+ for (int i = 0; i < fScriptElements.length; i++) {
+ IModelElement element = fScriptElements[i];
+ if (!(element instanceof IProjectFragment))
continue;
- IProjectFragment root= (IProjectFragment)element;
- List referencingProjects= Arrays.asList(ModelElementUtil.getReferencingProjects(root));
+ IProjectFragment root = (IProjectFragment) element;
+ List referencingProjects = Arrays
+ .asList(ModelElementUtil.getReferencingProjects(root));
if (skipDeletingReferencedRoot(query, root, referencingProjects))
rootsToSkip.add(root);
}
@@ -530,24 +609,34 @@
rootsToSkip.toArray(new IModelElement[rootsToSkip.size()]));
}
- private static boolean skipDeletingReferencedRoot(IConfirmQuery query, IProjectFragment root, List referencingProjects) throws OperationCanceledException {
- if (referencingProjects.isEmpty() || root == null || ! root.exists() ||! root.isArchive())
+ private static boolean skipDeletingReferencedRoot(IConfirmQuery query,
+ IProjectFragment root, List referencingProjects)
+ throws OperationCanceledException {
+ if (referencingProjects.isEmpty() || root == null || !root.exists()
+ || !root.isArchive())
return false;
- String question= Messages.format(RefactoringCoreMessages.DeleteRefactoring_3, root.getElementName());
- return ! query.confirm(question, referencingProjects.toArray());
+ String question = Messages.format(
+ RefactoringCoreMessages.DeleteRefactoring_3,
+ root.getElementName());
+ return !query.confirm(question, referencingProjects.toArray());
}
- private void removeUnconfirmedFoldersThatContainSourceFolders() throws CoreException {
- String queryTitle= RefactoringCoreMessages.DeleteRefactoring_4;
- IConfirmQuery query= fDeleteQueries.createYesYesToAllNoNoToAllQuery(queryTitle, true, IReorgQueries.CONFIRM_DELETE_FOLDERS_CONTAINING_SOURCE_FOLDERS);
+ private void removeUnconfirmedFoldersThatContainSourceFolders()
+ throws CoreException {
+ String queryTitle = RefactoringCoreMessages.DeleteRefactoring_4;
+ IConfirmQuery query = fDeleteQueries.createYesYesToAllNoNoToAllQuery(
+ queryTitle, true,
+ IReorgQueries.CONFIRM_DELETE_FOLDERS_CONTAINING_SOURCE_FOLDERS);
List<IResource> foldersToSkip = new ArrayList<IResource>(0);
- for (int i= 0; i < fResources.length; i++) {
- IResource resource= fResources[i];
- if (resource instanceof IFolder){
- IFolder folder= (IFolder)resource;
- if (containsSourceFolder(folder)){
- String question= Messages.format(RefactoringCoreMessages.DeleteRefactoring_5, folder.getName());
- if (! query.confirm(question))
+ for (int i = 0; i < fResources.length; i++) {
+ IResource resource = fResources[i];
+ if (resource instanceof IFolder) {
+ IFolder folder = (IFolder) resource;
+ if (containsSourceFolder(folder)) {
+ String question = Messages.format(
+ RefactoringCoreMessages.DeleteRefactoring_5,
+ folder.getName());
+ if (!query.confirm(question))
foldersToSkip.add(folder);
}
}
@@ -556,47 +645,50 @@
foldersToSkip.toArray(new IResource[foldersToSkip.size()]));
}
- private static boolean containsSourceFolder(IFolder folder) throws CoreException {
- IResource[] subFolders= folder.members();
+ private static boolean containsSourceFolder(IFolder folder)
+ throws CoreException {
+ IResource[] subFolders = folder.members();
for (int i = 0; i < subFolders.length; i++) {
- if (! (subFolders[i] instanceof IFolder))
+ if (!(subFolders[i] instanceof IFolder))
continue;
- IModelElement element= DLTKCore.create(folder);
+ IModelElement element = DLTKCore.create(folder);
if (element instanceof IProjectFragment)
return true;
if (element instanceof IScriptFolder)
continue;
- if (containsSourceFolder((IFolder)subFolders[i]))
+ if (containsSourceFolder((IFolder) subFolders[i]))
return true;
}
return false;
}
private void removeElementsWithParentsInSelection() {
- ParentChecker parentUtil= new ParentChecker(fResources, fScriptElements);
+ ParentChecker parentUtil = new ParentChecker(fResources,
+ fScriptElements);
parentUtil.removeElementsWithAncestorsOnList(false);
- fScriptElements= parentUtil.getScriptElements();
- fResources= parentUtil.getResources();
+ fScriptElements = parentUtil.getScriptElements();
+ fResources = parentUtil.getResources();
}
- private void removeScriptElementsChildrenOfScriptElements(){
- ParentChecker parentUtil= new ParentChecker(fResources, fScriptElements);
+ private void removeScriptElementsChildrenOfScriptElements() {
+ ParentChecker parentUtil = new ParentChecker(fResources,
+ fScriptElements);
parentUtil.removeElementsWithAncestorsOnList(true);
- fScriptElements= parentUtil.getScriptElements();
+ fScriptElements = parentUtil.getScriptElements();
}
private IFile[] getBuildpathFiles() {
- List result= new ArrayList();
- for (int i= 0; i < fScriptElements.length; i++) {
- IModelElement element= fScriptElements[i];
+ List result = new ArrayList();
+ for (int i = 0; i < fScriptElements.length; i++) {
+ IModelElement element = fScriptElements[i];
if (element instanceof IProjectFragment) {
- IProject project= element.getScriptProject().getProject();
- IFile buildpathFile= project.getFile(".classpath"); //$NON-NLS-1$
+ IProject project = element.getScriptProject().getProject();
+ IFile buildpathFile = project.getFile(".classpath"); //$NON-NLS-1$
if (buildpathFile.exists())
result.add(buildpathFile);
}
}
- return (IFile[])result.toArray(new IFile[result.size()]);
+ return (IFile[]) result.toArray(new IFile[result.size()]);
}
@Override
@@ -606,34 +698,38 @@
return fDeleteChange;
}
- private void addToSetToDelete(IModelElement[] newElements){
- fScriptElements= ReorgUtils.union(fScriptElements, newElements);
+ private void addToSetToDelete(IModelElement[] newElements) {
+ fScriptElements = ReorgUtils.union(fScriptElements, newElements);
}
private void removeFromSetToDelete(IResource[] resourcesToNotDelete) {
- fResources= ReorgUtils.setMinus(fResources, resourcesToNotDelete);
+ fResources = ReorgUtils.setMinus(fResources, resourcesToNotDelete);
}
private void removeFromSetToDelete(IModelElement[] elementsToNotDelete) {
- fScriptElements= ReorgUtils.setMinus(fScriptElements, elementsToNotDelete);
+ fScriptElements = ReorgUtils.setMinus(fScriptElements,
+ elementsToNotDelete);
}
-// private static IField[] getFields(IModelElement[] elements){
-// List fields= new ArrayList(3);
-// for (int i= 0; i < elements.length; i++) {
-// if (elements[i] instanceof IField)
-// fields.add(elements[i]);
-// }
-// return (IField[]) fields.toArray(new IField[fields.size()]);
-// }
+ // private static IField[] getFields(IModelElement[] elements){
+ // List fields= new ArrayList(3);
+ // for (int i= 0; i < elements.length; i++) {
+ // if (elements[i] instanceof IField)
+ // fields.add(elements[i]);
+ // }
+ // return (IField[]) fields.toArray(new IField[fields.size()]);
+ // }
- //----------- read-only confirmation business ------
+ // ----------- read-only confirmation business ------
private void confirmDeletingReadOnly() throws CoreException {
- if (! ReadOnlyResourceFinder.confirmDeleteOfReadOnlyElements(fScriptElements, fResources, fDeleteQueries))
- throw new OperationCanceledException(); //saying 'no' to this one is like cancelling the whole operation
+ if (!ReadOnlyResourceFinder.confirmDeleteOfReadOnlyElements(
+ fScriptElements, fResources, fDeleteQueries))
+ throw new OperationCanceledException(); // saying 'no' to this one
+ // is like cancelling the
+ // whole operation
}
- //----------- empty source modules related method
+ // ----------- empty source modules related method
private void addEmptySourceModulesToDelete() throws ModelException {
Set<ISourceModule> modulesToEmpty = getCusToEmpty();
addToSetToDelete(modulesToEmpty
@@ -648,9 +744,8 @@
if (module != null && !result.contains(module)) {
IDLTKLanguageToolkit toolkit = DLTKLanguageManager
.getLanguageToolkit(module);
- if (toolkit != null
- && toolkit
- .get(DLTKFeatures.DELETE_MODULE_WITHOUT_TOP_LEVEL_TYPES)
+ if (toolkit != null && toolkit
+ .get(DLTKFeatures.DELETE_MODULE_WITHOUT_TOP_LEVEL_TYPES)
&& willHaveAllTopLevelTypesDeleted(module)) {
result.add(module);
}
@@ -659,11 +754,12 @@
return result;
}
- private boolean willHaveAllTopLevelTypesDeleted(ISourceModule cu) throws ModelException {
- Set elementSet= new HashSet(Arrays.asList(fScriptElements));
- IType[] topLevelTypes= cu.getTypes();
- for (int i= 0; i < topLevelTypes.length; i++) {
- if (! elementSet.contains(topLevelTypes[i]))
+ private boolean willHaveAllTopLevelTypesDeleted(ISourceModule cu)
+ throws ModelException {
+ Set elementSet = new HashSet(Arrays.asList(fScriptElements));
+ IType[] topLevelTypes = cu.getTypes();
+ for (int i = 0; i < topLevelTypes.length; i++) {
+ if (!elementSet.contains(topLevelTypes[i]))
return false;
}
return true;
@@ -681,6 +777,6 @@
@Override
public void setComment(String comment) {
- fComment= comment;
+ fComment = comment;
}
}
diff --git a/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/corext/SourceRange.java b/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/corext/SourceRange.java
index 53cf9e1..8c149e1 100644
--- a/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/corext/SourceRange.java
+++ b/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/corext/SourceRange.java
@@ -19,14 +19,14 @@
* Use {@link org.eclipse.dltk.core.SourceRange}.
*/
@Deprecated
-public class SourceRange implements ISourceRange{
+public class SourceRange implements ISourceRange {
private final int fOffset;
private final int fLength;
- public SourceRange(int offset, int length){
- fLength= length;
- fOffset= offset;
+ public SourceRange(int offset, int length) {
+ fLength = length;
+ fOffset = offset;
}
public SourceRange(ASTNode node) {
@@ -34,7 +34,8 @@
}
public SourceRange(IProblem problem) {
- this(problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1);
+ this(problem.getSourceStart(),
+ problem.getSourceEnd() - problem.getSourceStart() + 1);
}
public SourceRange(ISourceRange range) {
@@ -60,57 +61,57 @@
}
@Override
- public String toString(){
- return "<offset: " + fOffset +" length: " + fLength + "/>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ public String toString() {
+ return "<offset: " + fOffset + " length: " + fLength + "/>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
/**
- * Sorts the given ranges by offset (backwards).
- * Note: modifies the parameter.
- * @param ranges the ranges to sort
+ * Sorts the given ranges by offset (backwards). Note: modifies the
+ * parameter.
+ *
+ * @param ranges
+ * the ranges to sort
* @return the sorted ranges, which are identical to the parameter ranges
*/
public static ISourceRange[] reverseSortByOffset(ISourceRange[] ranges) {
- Comparator<ISourceRange> comparator = new Comparator<ISourceRange>() {
- @Override
- public int compare(ISourceRange o1, ISourceRange o2) {
- return o2.getOffset() - o1.getOffset();
- }
- };
+ Comparator<ISourceRange> comparator = (o1, o2) -> o2.getOffset()
+ - o1.getOffset();
Arrays.sort(ranges, comparator);
return ranges;
}
@Override
public boolean equals(Object obj) {
- if (! (obj instanceof ISourceRange))
- return false;
- return ((ISourceRange)obj).getOffset() == fOffset && ((ISourceRange)obj).getLength() == fLength;
- }
+ if (!(obj instanceof ISourceRange))
+ return false;
+ return ((ISourceRange) obj).getOffset() == fOffset
+ && ((ISourceRange) obj).getLength() == fLength;
+ }
@Override
public int hashCode() {
- return fLength ^ fOffset;
- }
+ return fLength ^ fOffset;
+ }
- public boolean covers(ASTNode node) {
- return covers(new SourceRange(node));
- }
+ public boolean covers(ASTNode node) {
+ return covers(new SourceRange(node));
+ }
- public boolean covers(SourceRange range) {
- return getOffset() <= range.getOffset()
- && getEndInclusive() >= range.getEndInclusive();
- }
+ public boolean covers(SourceRange range) {
+ return getOffset() <= range.getOffset()
+ && getEndInclusive() >= range.getEndInclusive();
+ }
- /**
- * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=130161
- * (Script Model returns ISourceRanges [-1, 0] if source not available).
- *
- * @param range a source range, can be <code>null</code>
- * @return <code>true</code> iff range is not null and range.getOffset() is not -1
- */
- public static boolean isAvailable(ISourceRange range) {
- return range != null && range.getOffset() != -1;
- }
+ /**
+ * Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=130161
+ * (Script Model returns ISourceRanges [-1, 0] if source not available).
+ *
+ * @param range
+ * a source range, can be <code>null</code>
+ * @return <code>true</code> iff range is not null and range.getOffset() is
+ * not -1
+ */
+ public static boolean isAvailable(ISourceRange range) {
+ return range != null && range.getOffset() != -1;
+ }
}
-
diff --git a/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/internal/corext/callhierarchy/CalleeMethodWrapper.java b/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/internal/corext/callhierarchy/CalleeMethodWrapper.java
index c98adf1..8aa2b4b 100644
--- a/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/internal/corext/callhierarchy/CalleeMethodWrapper.java
+++ b/core/plugins/org.eclipse.dltk.ui/src corext/org/eclipse/dltk/internal/corext/callhierarchy/CalleeMethodWrapper.java
@@ -26,30 +26,20 @@
import org.eclipse.dltk.core.search.IDLTKSearchScope;
class CalleeMethodWrapper extends MethodWrapper {
- private Comparator fMethodWrapperComparator = new MethodWrapperComparator();
+ private Comparator<MethodWrapper> fMethodWrapperComparator = (m1, m2) -> {
+ CallLocation callLocation1 = m1.getMethodCall().getFirstCallLocation();
+ CallLocation callLocation2 = m2.getMethodCall().getFirstCallLocation();
- private static class MethodWrapperComparator implements Comparator {
- @Override
- public int compare(Object o1, Object o2) {
- MethodWrapper m1 = (MethodWrapper) o1;
- MethodWrapper m2 = (MethodWrapper) o2;
-
- CallLocation callLocation1 = m1.getMethodCall()
- .getFirstCallLocation();
- CallLocation callLocation2 = m2.getMethodCall()
- .getFirstCallLocation();
-
- if ((callLocation1 != null) && (callLocation2 != null)) {
- if (callLocation1.getStart() == callLocation2.getStart()) {
- return callLocation1.getEnd() - callLocation2.getEnd();
- }
-
- return callLocation1.getStart() - callLocation2.getStart();
+ if ((callLocation1 != null) && (callLocation2 != null)) {
+ if (callLocation1.getStart() == callLocation2.getStart()) {
+ return callLocation1.getEnd() - callLocation2.getEnd();
}
- return 0;
+ return callLocation1.getStart() - callLocation2.getStart();
}
- }
+
+ return 0;
+ };
/**
* Constructor for CalleeMethodWrapper.
@@ -106,8 +96,8 @@
SimpleReference e = (SimpleReference) i.next();
IMethod[] calls = (IMethod[]) result.get(e);
for (int j = 0; j < calls.length; ++j) {
- collector.addMember(getMember(), calls[j], e
- .sourceStart(), e.sourceEnd());
+ collector.addMember(getMember(), calls[j],
+ e.sourceStart(), e.sourceEnd());
}
}
return collector.getCallers();
@@ -117,8 +107,8 @@
}
if (DLTKCore.DEBUG) {
- System.err
- .println("TODO:CalleeMethodWrap findChildren not implemented..."); //$NON-NLS-1$
+ System.err.println(
+ "TODO:CalleeMethodWrap findChildren not implemented..."); //$NON-NLS-1$
}
return new HashMap(0);
}
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/CodeAssistUtil.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/CodeAssistUtil.java
index ea6c33d..203801d 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/CodeAssistUtil.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/CodeAssistUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 NumberFour AG
+ * Copyright (c) 2012, 2017 NumberFour AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -14,7 +14,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import org.eclipse.core.resources.IFile;
@@ -214,13 +213,7 @@
}
final CompletionProposal[] sorted = proposals
.toArray(new CompletionProposal[proposals.size()]);
- Arrays.sort(sorted, new Comparator<CompletionProposal>() {
- @Override
- public int compare(CompletionProposal pr, CompletionProposal pr1) {
- return pr.getName().compareTo(pr1.getName());
- }
-
- });
+ Arrays.sort(sorted, (pr, pr1) -> pr.getName().compareTo(pr1.getName()));
final String[] sortedNames = new String[names.length];
System.arraycopy(names, 0, sortedNames, 0, names.length);
Arrays.sort(sortedNames);
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/ProblemTestUtil.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/ProblemTestUtil.java
index 5b634e3..c0137a2 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/ProblemTestUtil.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/ProblemTestUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 NumberFour AG
+ * Copyright (c) 2012, 2017 NumberFour AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -13,7 +13,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Comparator;
import java.util.List;
import org.eclipse.core.resources.IFile;
@@ -46,13 +45,8 @@
final IMarker[] problems = resource.findMarkers(
DefaultProblem.MARKER_TYPE_PROBLEM, true,
IResource.DEPTH_INFINITE);
- Arrays.sort(problems, new Comparator<IMarker>() {
- @Override
- public int compare(IMarker o1, IMarker o2) {
- return o1.getAttribute(IMarker.CHAR_START, 0)
- - o2.getAttribute(IMarker.CHAR_START, 0);
- }
- });
+ Arrays.sort(problems, (o1, o2) -> o1.getAttribute(IMarker.CHAR_START, 0)
+ - o2.getAttribute(IMarker.CHAR_START, 0));
return problems;
}
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/ProjectSetup.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/ProjectSetup.java
index de1e576..5dbaec1 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/ProjectSetup.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/ProjectSetup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 NumberFour AG
+ * Copyright (c) 2012, 2017 NumberFour AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -25,11 +25,9 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.dltk.core.tests.model.AbstractModelTests;
import org.eclipse.dltk.internal.core.ModelManager;
import org.eclipse.dltk.utils.ResourceUtil;
@@ -220,13 +218,10 @@
FileUtil.copyDirectory(source, target, excludes);
final IProject project = getWorkspaceRoot().getProject(
workspaceProjectName);
- ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- project.create(null);
- if (!hasOption(Option.CLOSED)) {
- project.open(null);
- }
+ ResourcesPlugin.getWorkspace().run(monitor -> {
+ project.create(null);
+ if (!hasOption(Option.CLOSED)) {
+ project.open(null);
}
}, null);
return project;
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/cache/SourceModuleInfoCacheTest.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/cache/SourceModuleInfoCacheTest.java
index 81606c4..5e4aa36 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/cache/SourceModuleInfoCacheTest.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/cache/SourceModuleInfoCacheTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 NumberFour AG
+ * Copyright (c) 2012, 2017 NumberFour AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -20,9 +20,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.dltk.core.IModelElement;
import org.eclipse.dltk.core.IScriptFolder;
import org.eclipse.dltk.core.ISourceModule;
@@ -109,14 +107,11 @@
assertThat(module, IS_CACHED);
final IFile file = (IFile) module.getResource();
- project.getWorkspace().run(new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- file.delete(true, monitor);
- file.create(
- new ByteArrayInputStream(("//new content\n").getBytes()),
- IResource.NONE, monitor);
- }
+ project.getWorkspace().run(monitor -> {
+ file.delete(true, monitor);
+ file.create(
+ new ByteArrayInputStream(("//new content\n").getBytes()),
+ IResource.NONE, monitor);
}, null);
assertEquals(0, getCache().size());
assertThat(module, not(IS_CACHED));
@@ -182,13 +177,10 @@
assertNotNull(folder);
final int capacity = getCache().capacity();
final List<ISourceModule> modules = new ArrayList<ISourceModule>();
- project.getWorkspace().run(new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- for (int i = 0; i < capacity; ++i) {
- modules.add(folder.createSourceModule("m" + i + ".txt", "",
- false, null));
- }
+ project.getWorkspace().run(monitor -> {
+ for (int i = 0; i < capacity; ++i) {
+ modules.add(folder.createSourceModule("m" + i + ".txt", "",
+ false, null));
}
}, null);
for (ISourceModule module : modules) {
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/AbstractModelTests.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/AbstractModelTests.java
index d96dadc..be85bfc 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/AbstractModelTests.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/AbstractModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2016 IBM Corporation and others.
+ * Copyright (c) 2005, 2017 IBM Corporation and others.
* 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
@@ -32,7 +32,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.dltk.compiler.problem.IProblem;
@@ -130,14 +129,11 @@
}
protected void sortDeltas(IModelElementDelta[] elementDeltas) {
- Comparer comparer = new Comparer() {
- @Override
- public int compare(Object a, Object b) {
- IModelElementDelta deltaA = (IModelElementDelta) a;
- IModelElementDelta deltaB = (IModelElementDelta) b;
- return deltaA.getElement().getElementName()
- .compareTo(deltaB.getElement().getElementName());
- }
+ Comparer comparer = (a, b) -> {
+ IModelElementDelta deltaA = (IModelElementDelta) a;
+ IModelElementDelta deltaB = (IModelElementDelta) b;
+ return deltaA.getElement().getElementName()
+ .compareTo(deltaB.getElement().getElementName());
};
org.eclipse.dltk.internal.core.util.Util.sort(elementDeltas,
comparer);
@@ -403,12 +399,9 @@
protected IProject createProject(final String projectName)
throws CoreException {
final IProject project = getProject(projectName);
- IWorkspaceRunnable create = new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- project.create(null);
- project.open(null);
- }
+ IWorkspaceRunnable create = monitor -> {
+ project.create(null);
+ project.open(null);
};
getWorkspace().run(create, null);
return project;
@@ -439,75 +432,72 @@
final String[] projects, final String[] containers)
throws CoreException {
final IScriptProject[] result = new IScriptProject[1];
- IWorkspaceRunnable create = new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- // create project
- createProject(projectName);
+ IWorkspaceRunnable create = monitor -> {
+ // create project
+ createProject(projectName);
- IProject project = getWorkspaceRoot().getProject(projectName);
+ IProject project = getWorkspaceRoot().getProject(projectName);
- // add natures
- IProjectDescription description = project.getDescription();
- description.setNatureIds(natures);
- project.setDescription(description, null);
+ // add natures
+ IProjectDescription description = project.getDescription();
+ description.setNatureIds(natures);
+ project.setDescription(description, null);
- // create buildpath entries
- IPath projectPath = project.getFullPath();
- int sourceLength = sourceFolders == null ? 0
- : sourceFolders.length;
- int containersLength = containers == null ? 0
- : containers.length;
- int projectLength = projects == null ? 0 : projects.length;
- IBuildpathEntry[] entries = new IBuildpathEntry[sourceLength
- + projectLength + containersLength];
- for (int i = 0; i < sourceLength; i++) {
- IPath sourcePath = new Path(sourceFolders[i]);
- int segmentCount = sourcePath.segmentCount();
- if (segmentCount > 0) {
- // create folder and its parents
- IContainer container = project;
- for (int j = 0; j < segmentCount; j++) {
- IFolder folder = container.getFolder(new Path(
- sourcePath.segment(j)));
- if (!folder.exists()) {
- folder.create(true, true, null);
- }
- container = folder;
+ // create buildpath entries
+ IPath projectPath = project.getFullPath();
+ int sourceLength = sourceFolders == null ? 0
+ : sourceFolders.length;
+ int containersLength = containers == null ? 0
+ : containers.length;
+ int projectLength = projects == null ? 0 : projects.length;
+ IBuildpathEntry[] entries = new IBuildpathEntry[sourceLength
+ + projectLength + containersLength];
+ for (int i1 = 0; i1 < sourceLength; i1++) {
+ IPath sourcePath = new Path(sourceFolders[i1]);
+ int segmentCount = sourcePath.segmentCount();
+ if (segmentCount > 0) {
+ // create folder and its parents
+ IContainer container = project;
+ for (int j = 0; j < segmentCount; j++) {
+ IFolder folder = container.getFolder(new Path(
+ sourcePath.segment(j)));
+ if (!folder.exists()) {
+ folder.create(true, true, null);
}
+ container = folder;
}
- // create source entry
- entries[i] = DLTKCore.newSourceEntry(projectPath
- .append(sourcePath));
}
-
- for (int i = 0; i < projectLength; i++) {
-
- // accessible files
- IPath[] accessibleFiles;
- accessibleFiles = new IPath[0];
-
- // non accessible files
- IPath[] nonAccessibleFiles;
- nonAccessibleFiles = new IPath[0];
-
- entries[sourceLength + i] = DLTKCore.newProjectEntry(
- new Path(projects[i]), BuildpathEntry
- .getAccessRules(accessibleFiles,
- nonAccessibleFiles), true,
- new IBuildpathAttribute[0], false);
- }
-
- for (int i = 0; i < containersLength; i++) {
- entries[sourceLength + projectLength + i] = DLTKCore
- .newContainerEntry(new Path(containers[i]));
- }
- // set buildpath and output location
- IScriptProject scriptProject = DLTKCore.create(project);
- scriptProject.setRawBuildpath(entries, null);
-
- result[0] = scriptProject;
+ // create source entry
+ entries[i1] = DLTKCore.newSourceEntry(projectPath
+ .append(sourcePath));
}
+
+ for (int i2 = 0; i2 < projectLength; i2++) {
+
+ // accessible files
+ IPath[] accessibleFiles;
+ accessibleFiles = new IPath[0];
+
+ // non accessible files
+ IPath[] nonAccessibleFiles;
+ nonAccessibleFiles = new IPath[0];
+
+ entries[sourceLength + i2] = DLTKCore.newProjectEntry(
+ new Path(projects[i2]), BuildpathEntry
+ .getAccessRules(accessibleFiles,
+ nonAccessibleFiles), true,
+ new IBuildpathAttribute[0], false);
+ }
+
+ for (int i3 = 0; i3 < containersLength; i3++) {
+ entries[sourceLength + projectLength + i3] = DLTKCore
+ .newContainerEntry(new Path(containers[i3]));
+ }
+ // set buildpath and output location
+ IScriptProject scriptProject = DLTKCore.create(project);
+ scriptProject.setRawBuildpath(entries, null);
+
+ result[0] = scriptProject;
};
getWorkspace().run(create, null);
return result[0];
@@ -579,15 +569,12 @@
protected IFolder createFolder(IPath path) throws CoreException {
final IFolder folder = getWorkspaceRoot().getFolder(path);
- getWorkspace().run(new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- IContainer parent = folder.getParent();
- if (parent instanceof IFolder && !parent.exists()) {
- createFolder(parent.getFullPath());
- }
- folder.create(true, true, null);
+ getWorkspace().run(monitor -> {
+ IContainer parent = folder.getParent();
+ if (parent instanceof IFolder && !parent.exists()) {
+ createFolder(parent.getFullPath());
}
+ folder.create(true, true, null);
}, null);
return folder;
@@ -610,14 +597,11 @@
*/
protected void deleteProjects(final String... projectNames)
throws CoreException {
- ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- if (projectNames != null) {
- for (int i = 0, max = projectNames.length; i < max; i++) {
- if (projectNames[i] != null)
- deleteProject(projectNames[i]);
- }
+ ResourcesPlugin.getWorkspace().run(monitor -> {
+ if (projectNames != null) {
+ for (int i = 0, max = projectNames.length; i < max; i++) {
+ if (projectNames[i] != null)
+ deleteProject(projectNames[i]);
}
}
}, null);
@@ -647,24 +631,21 @@
}
protected void sortElements(IModelElement[] elements) {
- Comparer comparer = new Comparer() {
- @Override
- public int compare(Object a, Object b) {
- ModelElement elementA = (ModelElement) a;
- ModelElement elementB = (ModelElement) b;
- // char[] tempJCLPath = "<externalJCLPath>".toCharArray();
- // String idA = new String(CharOperation.replace(
- // elementA.toStringWithAncestors().toCharArray(),
- // getExternalJCLPathString().toCharArray(),
- // tempJCLPath));
- // String idB = new String(CharOperation.replace(
- // elementB.toStringWithAncestors().toCharArray(),
- // getExternalJCLPathString().toCharArray(),
- // tempJCLPath));
- return elementA.toStringWithAncestors().compareTo(
- elementB.toStringWithAncestors().toString());
- // return idA.compareTo(idB);
- }
+ Comparer comparer = (a, b) -> {
+ ModelElement elementA = (ModelElement) a;
+ ModelElement elementB = (ModelElement) b;
+ // char[] tempJCLPath = "<externalJCLPath>".toCharArray();
+ // String idA = new String(CharOperation.replace(
+ // elementA.toStringWithAncestors().toCharArray(),
+ // getExternalJCLPathString().toCharArray(),
+ // tempJCLPath));
+ // String idB = new String(CharOperation.replace(
+ // elementB.toStringWithAncestors().toCharArray(),
+ // getExternalJCLPathString().toCharArray(),
+ // tempJCLPath));
+ return elementA.toStringWithAncestors().compareTo(
+ elementB.toStringWithAncestors().toString());
+ // return idA.compareTo(idB);
};
org.eclipse.dltk.internal.core.util.Util.sort(elements, comparer);
}
@@ -711,14 +692,11 @@
}
protected void sortResources(Object[] resources) {
- Util.Comparer comparer = new Util.Comparer() {
- @Override
- public int compare(Object a, Object b) {
- IResource resourceA = (IResource) a;
- IResource resourceB = (IResource) b;
- return resourceA.getFullPath().toString()
- .compareTo(resourceB.getFullPath().toString());
- }
+ Util.Comparer comparer = (a, b) -> {
+ IResource resourceA = (IResource) a;
+ IResource resourceB = (IResource) b;
+ return resourceA.getFullPath().toString()
+ .compareTo(resourceB.getFullPath().toString());
};
Util.sort(resources, comparer);
}
@@ -788,14 +766,11 @@
}
protected void sortMarkers(IMarker[] markers) {
- org.eclipse.dltk.internal.core.util.Util.Comparer comparer = new org.eclipse.dltk.internal.core.util.Util.Comparer() {
- @Override
- public int compare(Object a, Object b) {
- IMarker markerA = (IMarker) a;
- IMarker markerB = (IMarker) b;
- return markerA
- .getAttribute(IMarker.MESSAGE, "").compareTo(markerB.getAttribute(IMarker.MESSAGE, "")); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ org.eclipse.dltk.internal.core.util.Util.Comparer comparer = (a, b) -> {
+ IMarker markerA = (IMarker) a;
+ IMarker markerB = (IMarker) b;
+ return markerA
+ .getAttribute(IMarker.MESSAGE, "").compareTo(markerB.getAttribute(IMarker.MESSAGE, "")); //$NON-NLS-1$ //$NON-NLS-2$
};
org.eclipse.dltk.internal.core.util.Util.sort(markers, comparer);
}
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/CompletionTestsRequestor2.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/CompletionTestsRequestor2.java
index 963ae51..a0d520f 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/CompletionTestsRequestor2.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/CompletionTestsRequestor2.java
@@ -1,16 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
+ * Copyright (c) 2004, 2017 IBM Corporation and others.
* 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
*
-
*******************************************************************************/
package org.eclipse.dltk.core.tests.model;
import java.util.Arrays;
-import java.util.Comparator;
import org.eclipse.dltk.compiler.problem.IProblem;
import org.eclipse.dltk.core.CompletionContext;
@@ -159,15 +157,12 @@
*/
public String getReversedResults() {
if(this.proposalsPtr < 0) return "";
- Arrays.sort(this.proposals, new Comparator<CompletionProposal>() {
- @Override
- public int compare(CompletionProposal p1, CompletionProposal p2) {
- int relDif = p2.getRelevance() - p1.getRelevance();
- if(relDif != 0) return relDif;
- String name1 = getElementName(p1);
- String name2 = getElementName(p2);
- return name1.compareTo(name2);
- }
+ Arrays.sort(this.proposals, (p1, p2) -> {
+ int relDif = p2.getRelevance() - p1.getRelevance();
+ if(relDif != 0) return relDif;
+ String name1 = getElementName(p1);
+ String name2 = getElementName(p2);
+ return name1.compareTo(name2);
});
return getResultsWithoutSorting();
}
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/ModifyingResourceTests.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/ModifyingResourceTests.java
index d689398..d8b824e 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/ModifyingResourceTests.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/ModifyingResourceTests.java
@@ -1,11 +1,10 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
*
-
*******************************************************************************/
package org.eclipse.dltk.core.tests.model;
@@ -21,7 +20,6 @@
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.dltk.core.DLTKCore;
import org.eclipse.dltk.core.IBuildpathEntry;
@@ -162,14 +160,11 @@
protected void swapFiles(String firstPath, String secondPath) throws CoreException {
final IFile first = this.getFile(firstPath);
final IFile second = this.getFile(secondPath);
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) throws CoreException {
- IPath tempPath = first.getParent().getFullPath().append("swappingFile.temp");
- first.move(tempPath, false, monitor);
- second.move(first.getFullPath(), false, monitor);
- getWorkspaceRoot().getFile(tempPath).move(second.getFullPath(), false, monitor);
- }
+ IWorkspaceRunnable runnable = monitor -> {
+ IPath tempPath = first.getParent().getFullPath().append("swappingFile.temp");
+ first.move(tempPath, false, monitor);
+ second.move(first.getFullPath(), false, monitor);
+ getWorkspaceRoot().getFile(tempPath).move(second.getFullPath(), false, monitor);
};
getWorkspace().run(runnable, null);
}
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TestPessimisticProvider.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TestPessimisticProvider.java
index 651cd56..02acf10 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TestPessimisticProvider.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TestPessimisticProvider.java
@@ -1,22 +1,19 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
*
-
*******************************************************************************/
package org.eclipse.dltk.core.tests.model;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFileModificationValidator;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.team.core.RepositoryProvider;
@@ -59,15 +56,12 @@
if (markWritableOnEdit) {
try {
ResourcesPlugin.getWorkspace().run(
- new IWorkspaceRunnable() {
- @Override
- public void run(IProgressMonitor monitor) {
- for (int i = 0, length = files.length; i < length; i++) {
- try {
- setReadOnly(files[i], false);
- } catch (CoreException e) {
- e.printStackTrace();
- }
+ monitor -> {
+ for (int i = 0, length = files.length; i < length; i++) {
+ try {
+ setReadOnly(files[i], false);
+ } catch (CoreException e) {
+ e.printStackTrace();
}
}
},
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TestSearchResults.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TestSearchResults.java
index 2d0b8b7..96ddfea 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TestSearchResults.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TestSearchResults.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 xored software, Inc.
+ * Copyright (c) 2008, 2017 xored software, Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -13,7 +13,6 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
@@ -116,11 +115,6 @@
}
public void sortByOffset() {
- Collections.sort(matches, new Comparator<SearchMatch>() {
- @Override
- public int compare(SearchMatch o1, SearchMatch o2) {
- return o1.getOffset() - o2.getOffset();
- }
- });
+ Collections.sort(matches, (o1, o2) -> o1.getOffset() - o2.getOffset());
}
}
diff --git a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TypeHierarchyTests.java b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TypeHierarchyTests.java
index 1872488..0807a52 100644
--- a/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TypeHierarchyTests.java
+++ b/core/tests/org.eclipse.dltk.core.tests/src/org/eclipse/dltk/core/tests/model/TypeHierarchyTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016 IBM Corporation and others.
+ * Copyright (c) 2016, 2017 IBM Corporation and others.
* 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
@@ -8,7 +8,6 @@
*******************************************************************************/
package org.eclipse.dltk.core.tests.model;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -148,14 +147,11 @@
}
private void print(Set<IType> classPaths) {
- Set<IType> sortedClassPaths = new TreeSet<IType>(new Comparator<IType>() {
- @Override
- public int compare(IType arg0, IType arg1) {
- if (arg0 == arg1 || arg0.equals(arg1)) {
- return 0;
- }
- return arg0.getElementName().compareTo(arg1.getElementName());
+ Set<IType> sortedClassPaths = new TreeSet<IType>((arg0, arg1) -> {
+ if (arg0 == arg1 || arg0.equals(arg1)) {
+ return 0;
}
+ return arg0.getElementName().compareTo(arg1.getElementName());
});
sortedClassPaths.addAll(classPaths);
System.out.println(sortedClassPaths);