diff options
| author | Kalyan Prasad Tatavarthi | 2020-03-03 06:33:44 +0000 |
|---|---|---|
| committer | Kalyan Prasad Tatavarthi | 2020-03-03 06:33:44 +0000 |
| commit | bfb4b6648b1db97a15a5ca785fa8a74278d9c791 (patch) | |
| tree | cfa1c3e53791c20519be6769e2f7278b5bb8fa03 | |
| parent | d17729180beb68a11218aa64027226484e33df7b (diff) | |
| parent | 8ba9929b986a6c02bbe5ab955679d27f2d850a72 (diff) | |
| download | eclipse.jdt.ui-bfb4b6648b1db97a15a5ca785fa8a74278d9c791.tar.gz eclipse.jdt.ui-bfb4b6648b1db97a15a5ca785fa8a74278d9c791.tar.xz eclipse.jdt.ui-bfb4b6648b1db97a15a5ca785fa8a74278d9c791.zip | |
'origin/master' into BETA_JAVA14
Conflicts:
org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java
org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingsCore.java
org.eclipse.jdt.core.manipulation/core
extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java
org.eclipse.jdt.core.manipulation/core
extension/org/eclipse/jdt/internal/corext/dom/GenericVisitor.java
org.eclipse.jdt.core.manipulation/core
extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java
org.eclipse.jdt.core.manipulation/core
extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest13.java
Change-Id: Icffb34f0347bbfc1d3a9f35327dacb012030655f
Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
543 files changed, 9790 insertions, 3991 deletions
diff --git a/org.eclipse.jdt.astview/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.astview/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.astview/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.astview/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ASTView.java b/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ASTView.java index 50fd726169..13f8a79ab2 100644 --- a/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ASTView.java +++ b/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/ASTView.java @@ -1133,7 +1133,7 @@ public class ASTView extends ViewPart implements IShowInSource, IShowInTargetLis }; fFocusAction.setText("&Show AST of active editor"); //$NON-NLS-1$ fFocusAction.setToolTipText("Show AST of active editor"); //$NON-NLS-1$ - fFocusAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH); + fFocusAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH); ASTViewImages.setImageDescriptors(fFocusAction, ASTViewImages.SETFOCUS); fCollapseAction = new Action() { diff --git a/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/Binding.java b/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/Binding.java index 2dc08b23de..878525fb03 100644 --- a/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/Binding.java +++ b/org.eclipse.jdt.astview/src/org/eclipse/jdt/astview/views/Binding.java @@ -104,7 +104,7 @@ public class Binding extends ASTAttribute { res.add(new Binding(this, "VARIABLE DECLARATION", variableBinding.getVariableDeclaration(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS SYNTHETIC", fBinding.isSynthetic(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS DEPRECATED", fBinding.isDeprecated(), true)); //$NON-NLS-1$ - res.add(new BindingProperty(this, "CONSTANT VALUE", variableBinding.getConstantValue(), true)); //$NON-NLS-1$ + res.add(new BindingProperty(this, "CONSTANT VALUE", variableBinding.getConstantValue(), true)); //$NON-NLS-1$ res.add(new BindingProperty(this, "IS EFFECTIVELY FINAL", variableBinding.isEffectivelyFinal(), true)); //$NON-NLS-1$ break; @@ -135,7 +135,7 @@ public class Binding extends ASTAttribute { if (typeBinding.isClass()) kinds.append(" isClass"); //$NON-NLS-1$ if (typeBinding.isInterface()) kinds.append(" isInterface"); //$NON-NLS-1$ if (typeBinding.isEnum()) kinds.append(" isEnum"); //$NON-NLS-1$ - res.add(new BindingProperty(this, kinds, true)); + res.add(new BindingProperty(this, kinds, true)); StringBuffer generics= new StringBuffer("GENERICS:"); //$NON-NLS-1$ if (typeBinding.isRawType()) generics.append(" isRawType"); //$NON-NLS-1$ @@ -144,7 +144,7 @@ public class Binding extends ASTAttribute { if (!isType(typeKind, GENERIC | PARAMETRIZED)) { generics.append(" (non-generic, non-parameterized)"); } - res.add(new BindingProperty(this, generics, isRefType)); + res.add(new BindingProperty(this, generics, isRefType)); res.add(new Binding(this, "ELEMENT TYPE", typeBinding.getElementType(), isType(typeKind, ARRAY_TYPE))); //$NON-NLS-1$ res.add(new Binding(this, "COMPONENT TYPE", typeBinding.getComponentType(), isType(typeKind, ARRAY_TYPE))); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core.manipulation/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.core.manipulation/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.core.manipulation/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.core.manipulation/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/CUCorrectionProposalCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/CUCorrectionProposalCore.java index 2fba70d2e6..e357559af1 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/CUCorrectionProposalCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/CUCorrectionProposalCore.java @@ -47,7 +47,7 @@ import org.eclipse.jdt.internal.ui.text.correction.proposals.EditAnnotator; * <p> * The proposal takes care of the preview of the changes as proposal information. * </p> - * + * * @since 1.11 */ public class CUCorrectionProposalCore extends ChangeCorrectionProposalCore implements ICUCorrectionProposal { @@ -57,7 +57,7 @@ public class CUCorrectionProposalCore extends ChangeCorrectionProposalCore imple /** * Constructs a correction proposal working on a compilation unit with a given text change. - * + * * @param proposal ICUCorrectionProposal to use * @param name the name that is displayed in the proposal selection dialog * @param cu the compilation unit to which the change can be applied @@ -77,7 +77,7 @@ public class CUCorrectionProposalCore extends ChangeCorrectionProposalCore imple /** * Constructs a correction proposal working on a compilation unit with a given text change. - * + * * @param name the name that is displayed in the proposal selection dialog * @param cu the compilation unit to which the change can be applied * @param change the change that is executed when the proposal is applied or <code>null</code> @@ -100,7 +100,7 @@ public class CUCorrectionProposalCore extends ChangeCorrectionProposalCore imple * Users have to override {@link #addEdits(IDocument, TextEdit)} to provide the text edits or * {@link #createTextChange()} to provide a text change. * </p> - * + * * @param name the name that is displayed in the proposal selection dialog * @param cu the compilation unit on that the change works * @param relevance the relevance of this proposal @@ -116,7 +116,7 @@ public class CUCorrectionProposalCore extends ChangeCorrectionProposalCore imple * <p> * The default implementation does not add any edits * </p> - * + * * @param document content of the underlying compilation unit. To be accessed read only. * @param editRoot The root edit to add all edits to * @throws CoreException can be thrown if adding the edits is failing. @@ -141,7 +141,7 @@ public class CUCorrectionProposalCore extends ChangeCorrectionProposalCore imple } return buf.toString(); } - + @Override public void apply() throws CoreException { performChange(); @@ -219,7 +219,7 @@ public class CUCorrectionProposalCore extends ChangeCorrectionProposalCore imple * * @return the preview of the changed compilation unit * @throws CoreException if the creation of the change failed - * + * * @noreference This method is not intended to be referenced by clients. */ public String getPreviewContent() throws CoreException { diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ChangeCorrectionProposalCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ChangeCorrectionProposalCore.java index 47118fdffe..d5c4c5d42a 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ChangeCorrectionProposalCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ChangeCorrectionProposalCore.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (c) 2018 IBM Corporation and others. - * + * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ICUCorrectionProposal.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ICUCorrectionProposal.java index b5511effb8..9a2d392047 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ICUCorrectionProposal.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ICUCorrectionProposal.java @@ -22,7 +22,7 @@ import org.eclipse.ltk.core.refactoring.TextChange; * @since 1.11 */ public interface ICUCorrectionProposal { - + /** * Returns the text change that is invoked when the change is applied. * diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java index 4b70628339..743ad65c72 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/ImportReferencesCollector.java @@ -293,7 +293,7 @@ public class ImportReferencesCollector extends GenericVisitor { doVisitChildren(node.annotations()); return false; } - + @Override public boolean visit(LabeledStatement node) { doVisitNode(node.getBody()); @@ -304,15 +304,15 @@ public class ImportReferencesCollector extends GenericVisitor { public boolean visit(ContinueStatement node) { return false; } - + @Override public boolean visit(YieldStatement node) { if (ASTHelper.isYieldNodeSupportedInAST(node.getAST())) { - evalQualifyingExpression(node.getExpression(), null); + evalQualifyingExpression(node.getExpression(), null); } return false; } - + /* * @see ASTVisitor#visit(ThisExpression) */ @@ -321,7 +321,7 @@ public class ImportReferencesCollector extends GenericVisitor { typeRefFound(node.getQualifier()); return false; } - + @Override public boolean visit(SuperFieldAccess node) { typeRefFound(node.getQualifier()); @@ -374,7 +374,7 @@ public class ImportReferencesCollector extends GenericVisitor { doVisitChildren(node.typeArguments()); return false; } - + @Override public boolean visit(ExpressionMethodReference node) { evalQualifyingExpression(node.getExpression(), node.getName()); @@ -388,7 +388,7 @@ public class ImportReferencesCollector extends GenericVisitor { doVisitChildren(node.typeArguments()); return false; } - + @Override public boolean visit(TypeMethodReference node) { doVisitNode(node.getType()); @@ -410,7 +410,7 @@ public class ImportReferencesCollector extends GenericVisitor { } return false; } - + /* * @see ASTVisitor#visit(SuperConstructorInvocation) */ @@ -493,7 +493,7 @@ public class ImportReferencesCollector extends GenericVisitor { doVisitNode(node.getReturnType2()); } // name not visited - + int apiLevel= node.getAST().apiLevel(); if (apiLevel >= AST.JLS8) { doVisitNode(node.getReceiverType()); @@ -570,7 +570,7 @@ public class ImportReferencesCollector extends GenericVisitor { } return false; } - + @Override public boolean visit(MethodRefParameter node) { doVisitNode(node.getType()); diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/OrganizeImportsOperation.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/OrganizeImportsOperation.java index 9b7cf5de89..f7ee9fe1fe 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/OrganizeImportsOperation.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/OrganizeImportsOperation.java @@ -560,7 +560,7 @@ public class OrganizeImportsOperation implements IWorkspaceRunnable { CompilationUnit astRoot= fASTRoot; if (astRoot == null) { astRoot= CoreASTProvider.getInstance().getAST(fCompilationUnit, CoreASTProvider.WAIT_YES, subMonitor.split(2)); - } + } subMonitor.setWorkRemaining(7); ImportRewrite importsRewrite= CodeStyleConfiguration.createImportRewrite(astRoot, false); diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/SharedASTProviderCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/SharedASTProviderCore.java index 0f3bf78826..952f6da326 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/SharedASTProviderCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/SharedASTProviderCore.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -20,7 +20,6 @@ import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; -import org.eclipse.jdt.core.manipulation.CoreASTProvider; /** @@ -112,7 +111,7 @@ public class SharedASTProviderCore { * <p> * Clients are not allowed to modify the AST and must not keep any references. * </p> - * + * * @param element the {@link ITypeRoot}, must not be <code>null</code> * @param waitFlag {@link #WAIT_YES}, {@link #WAIT_NO} or {@link #WAIT_ACTIVE_ONLY} * @param progressMonitor the progress monitor or <code>null</code> diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/CodeTemplateContext.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/CodeTemplateContext.java index cac72feea2..1fa70ff167 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/CodeTemplateContext.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/CodeTemplateContext.java @@ -52,7 +52,7 @@ public class CodeTemplateContext extends TemplateContext { } return super.getAdapter(adapter); } - + public IJavaProject getJavaProject() { return fProject; } diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/StubUtility.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/StubUtility.java index e5cf4e9668..cba5c4645e 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/StubUtility.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/core/manipulation/StubUtility.java @@ -116,7 +116,7 @@ import org.eclipse.jdt.internal.corext.dom.IASTSharedValues; /** * Implementations for {@link CodeGeneration} APIs, and other helper methods * to create source code stubs based on {@link IJavaElement}s. - * + * * See StubUtility2 * See JDTUIHelperClasses */ @@ -384,7 +384,7 @@ public class StubUtility { /** * Don't use this method directly, use CodeGeneration. - * + * * @param templateID the template id of the type body to get. Valid id's are * {@link CodeTemplateContextType#CLASSBODY_ID}, * {@link CodeTemplateContextType#INTERFACEBODY_ID}, @@ -890,7 +890,7 @@ public class StubUtility { /** * Returns the line delimiter which is used in the specified project. - * + * * @param project the java project, or <code>null</code> * @return the used line delimiter */ @@ -944,7 +944,7 @@ public class StubUtility { /** * Evaluates the indentation used by a Java element. (in tabulators) - * + * * @param elem the element to get the indent of * @return return the indent unit * @throws JavaModelException thrown if the element could not be accessed @@ -974,7 +974,7 @@ public class StubUtility { /** * Returns the element after the give element. - * + * * @param member a Java element * @return the next sibling of the given element or <code>null</code> * @throws JavaModelException thrown if the element could not be accessed @@ -1114,7 +1114,7 @@ public class StubUtility { /** * Returns variable name suggestions for the given base name. This is a layer over the JDT.Core * NamingConventions API to fix its shortcomings. JDT UI code should only use this API. - * + * * @param variableKind specifies what type the variable is: {@link NamingConventions#VK_LOCAL}, * {@link NamingConventions#VK_PARAMETER}, {@link NamingConventions#VK_STATIC_FIELD}, * {@link NamingConventions#VK_INSTANCE_FIELD}, or @@ -1127,7 +1127,7 @@ public class StubUtility { * are excluded * @param evaluateDefault if set, the result is guaranteed to contain at least one result. If * not, the result can be an empty array. - * + * * @return the name suggestions sorted by relevance (best proposal first). If * <code>evaluateDefault</code> is set to true, the returned array is never empty. If * <code>evaluateDefault</code> is set to false, an empty array is returned if there is @@ -1384,7 +1384,7 @@ public class StubUtility { } return names; } - + public static String getBaseName(IField field) throws JavaModelException { return NamingConventions.getBaseName(getFieldKind(field.getFlags()), field.getElementName(), field.getJavaProject()); } @@ -1395,7 +1395,7 @@ public class StubUtility { /** * Returns the kind of the given binding. - * + * * @param binding variable binding * @return one of the <code>NamingConventions.VK_*</code> constants * @since 3.5 @@ -1532,7 +1532,7 @@ public class StubUtility { /** * Only to be used by tests - * + * * @param templateId the template id * @param pattern the new pattern * @param project not used diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/JdtViewerDropAdapterConstants.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/JdtViewerDropAdapterConstants.java index 5e5bce55a1..7c944a861c 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/JdtViewerDropAdapterConstants.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/JdtViewerDropAdapterConstants.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (c) 2018 IBM Corporation and others. - * + * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java index 972bfb1d41..42efac69a0 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -104,6 +104,7 @@ public class MultiFixMessages extends NLS { public static String CodeFormatFix_description; public static String LambdaExpressionsCleanUp_use_lambda_where_possible; public static String LambdaExpressionsCleanUp_use_anonymous; + public static String LambdaExpressionAndMethodRefCleanUp_description; public static String NullAnnotationsCleanUp_add_nullable_annotation; public static String NullAnnotationsCleanUp_add_nonnull_annotation; diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties index 73f7320fdb..9041e0e902 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties @@ -84,6 +84,7 @@ CodeFormatCleanUp_description=Format source code ImportsCleanUp_OrganizeImports_Description=Organize imports LambdaExpressionsCleanUp_use_lambda_where_possible=Use lambda where possible LambdaExpressionsCleanUp_use_anonymous=Use anonymous class creations +LambdaExpressionAndMethodRefCleanUp_description=Simplify lambda expression and method reference syntax SortMembersCleanUp_AllMembers_description=Sort all members SortMembersCleanUp_Excluding_description=Sort members excluding fields, enum constants, and initializers SortMembersCleanUp_RemoveMarkersWarning0=The file ''{0}'' in project ''{1}'' contains markers which may be removed by Sort Members diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/HighlightedPositionCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/HighlightedPositionCore.java index d93dcb6492..1859d3285c 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/HighlightedPositionCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/HighlightedPositionCore.java @@ -18,14 +18,14 @@ import org.eclipse.jface.text.Position; /** * Highlighted Positions. - * + * * @since 1.11 */ public class HighlightedPositionCore extends Position { /** Lock object */ private Object fLock; - + /** Highlighting object */ private Object fHighlighting; diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/PositionCollectorCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/PositionCollectorCore.java index 8dc4c834e2..dc1b67b240 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/PositionCollectorCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/PositionCollectorCore.java @@ -30,7 +30,7 @@ import org.eclipse.jdt.internal.corext.dom.GenericVisitor; /** * Collects positions from the AST. - * + * * @since 1.11 */ public abstract class PositionCollectorCore extends GenericVisitor { @@ -85,7 +85,7 @@ public abstract class PositionCollectorCore extends GenericVisitor { * @since 3.5 */ @Override - public abstract boolean visit(SuperConstructorInvocation node); + public abstract boolean visit(SuperConstructorInvocation node); @Override public abstract boolean visit(SimpleType node); @@ -94,7 +94,7 @@ public abstract class PositionCollectorCore extends GenericVisitor { * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SimpleName) */ @Override - public abstract boolean visit(SimpleName node); + public abstract boolean visit(SimpleName node); /** * Retain the positions completely contained in the given range. @@ -102,5 +102,5 @@ public abstract class PositionCollectorCore extends GenericVisitor { * @param length The range length */ protected abstract void retainPositions(int offset, int length); - + } diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingCore.java index 9232ef4180..7a7d277edc 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingCore.java @@ -16,7 +16,7 @@ package org.eclipse.jdt.internal.ui.javaeditor; /** * Semantic highlighting - * + * * @since 1.11 */ public abstract class SemanticHighlightingCore { diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingPresenterCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingPresenterCore.java index 7fd859e06d..f09719f9f9 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingPresenterCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingPresenterCore.java @@ -248,7 +248,7 @@ public class SemanticHighlightingPresenterCore { * Add a position with the given range and highlighting unconditionally, only from UI thread. * The position will also be registered on the document. The text presentation is not * invalidated. - * + * * @param event The document event * @param category The category * @param offset The range offset diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingsCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingsCore.java index 89841a1a6a..7460100787 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingsCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingsCore.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * This is an implementation of an early-draft specification developed under the Java * Community Process (JCP) and is made available for testing and evaluation purposes * only. The code is not compatible with any specification of the JCP. diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java index 919be8e5cc..1b81a942c6 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -245,15 +245,19 @@ public final class CorrectionMessages extends NLS { public static String UnresolvedElementsSubProcessor_arraychangetolength_description; public static String UnresolvedElementsSubProcessor_addnewkeyword_description; public static String JavadocTagsSubProcessor_addjavadoc_method_description; + public static String JavadocTagsSubProcessor_addjavadoc_module_description; public static String JavadocTagsSubProcessor_addjavadoc_type_description; public static String JavadocTagsSubProcessor_addjavadoc_field_description; public static String JavadocTagsSubProcessor_addjavadoc_paramtag_description; + public static String JavadocTagsSubProcessor_addjavadoc_providestag_description; public static String JavadocTagsSubProcessor_addjavadoc_throwstag_description; public static String JavadocTagsSubProcessor_addjavadoc_returntag_description; + public static String JavadocTagsSubProcessor_addjavadoc_usestag_description; public static String JavadocTagsSubProcessor_addjavadoc_enumconst_description; public static String JavadocTagsSubProcessor_addjavadoc_allmissing_description; public static String JavadocTagsSubProcessor_qualifylinktoinner_description; public static String JavadocTagsSubProcessor_removetag_description; + public static String JavadocTagsSubProcessor_removeduplicatetag_description; public static String NoCorrectionProposal_description; public static String MarkerResolutionProposal_additionaldesc; public static String NewCUCompletionUsingWizardProposal_createclass_description; diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties index 81c679b699..a8fcce6f91 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2019 IBM Corporation and others. +# Copyright (c) 2000, 2020 IBM Corporation and others. # # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 @@ -272,6 +272,7 @@ UnresolvedElementsSubProcessor_add_requires_module_description=Adds ''requires { UnresolvedElementsSubProcessor_combine_two_proposals_info={0} and {1} JavadocTagsSubProcessor_addjavadoc_method_description=Add Javadoc comment +JavadocTagsSubProcessor_addjavadoc_module_description=Add Javadoc comment JavadocTagsSubProcessor_addjavadoc_type_description=Add Javadoc comment JavadocTagsSubProcessor_addjavadoc_field_description=Add Javadoc comment JavadocTagsSubProcessor_addjavadoc_paramtag_description=Add '@param' tag @@ -279,11 +280,14 @@ JavadocTagsSubProcessor_document_exception_description=Document thrown exception JavadocTagsSubProcessor_document_parameter_description=Document parameter to avoid 'unused' warning JavadocTagsSubProcessor_document_type_parameter_description=Document type parameter to avoid 'unused' warning JavadocTagsSubProcessor_addjavadoc_throwstag_description=Add '@throws' tag +JavadocTagsSubProcessor_addjavadoc_providestag_description=Add '@provides' tag JavadocTagsSubProcessor_addjavadoc_returntag_description=Add '@return' tag +JavadocTagsSubProcessor_addjavadoc_usestag_description=Add '@uses' tag JavadocTagsSubProcessor_addjavadoc_enumconst_description=Add Javadoc comment JavadocTagsSubProcessor_addjavadoc_allmissing_description=Add all missing tags JavadocTagsSubProcessor_qualifylinktoinner_description=Qualify inner type name JavadocTagsSubProcessor_removetag_description=Remove tag +JavadocTagsSubProcessor_removeduplicatetag_description=Remove duplicate ''{0}'' tag NoCorrectionProposal_description=No suggestions available diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessorCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessorCore.java index 7fd86cd436..f77a5110e8 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessorCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/ModifierCorrectionSubProcessorCore.java @@ -43,8 +43,6 @@ import org.eclipse.jdt.core.manipulation.JavaManipulation; import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore; import org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroupCore; -import org.eclipse.jdt.internal.ui.text.correction.CorrectionMessages; - /** */ public class ModifierCorrectionSubProcessorCore { diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/proposals/EditAnnotator.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/proposals/EditAnnotator.java index 4a2a2b1bc3..3be2ab6d03 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/proposals/EditAnnotator.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/text/correction/proposals/EditAnnotator.java @@ -31,7 +31,7 @@ import org.eclipse.jdt.internal.core.manipulation.util.Strings; /** * Class to annotate edits made by a quick fix/assist to be shown via the quick fix pop-up preview. * E.g. the added changes are shown in bold. - * + * * @since 3.8 */ public class EditAnnotator extends TextEditVisitor { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java index d83f4c79a6..da559a54f3 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/ASTResolving.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -667,7 +667,7 @@ public class ASTResolving { /** * The node's enclosing method declaration or <code>null</code> if * the node is not inside a method and is not a method declaration itself. - * + * * @param node a node * @return the enclosing method declaration or <code>null</code> */ @@ -686,11 +686,11 @@ public class ASTResolving { /** * Returns the lambda expression node which encloses the given <code>node</code>, or * <code>null</code> if none. - * + * * @param node the node * @return the enclosing lambda expression node for the given <code>node</code>, or * <code>null</code> if none - * + * * @since 3.10 */ public static LambdaExpression findEnclosingLambdaExpression(ASTNode node) { @@ -717,7 +717,7 @@ public class ASTResolving { * </p> * @param node the node * @param nodeType the node type constant from {@link ASTNode} - * @return the closest ancestor of <code>node</code> (including <code>node</code> itself) + * @return the closest ancestor of <code>node</code> (including <code>node</code> itself) * whose type is <code>nodeType</code>, or <code>null</code> if none */ public static ASTNode findAncestor(ASTNode node, int nodeType) { @@ -987,7 +987,7 @@ public class ASTResolving { * if false, the type of an expression x (R r= x) * @param ast the current AST * @return the normalized binding or null when only the 'null' binding - * + * * @see Bindings#normalizeForDeclarationUse(ITypeBinding, AST) */ public static ITypeBinding normalizeWildcardType(ITypeBinding wildcardType, boolean isBindingToAssign, AST ast) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/NecessaryParenthesesChecker.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/NecessaryParenthesesChecker.java index 9734ebd413..c3e22a4a18 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/NecessaryParenthesesChecker.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/dom/NecessaryParenthesesChecker.java @@ -45,7 +45,7 @@ import org.eclipse.jdt.core.dom.WhileStatement; /** * Helper class to check if an expression requires parentheses. - * + * * @see JDTUIHelperClasses * @since 3.7 */ @@ -109,18 +109,18 @@ public class NecessaryParenthesesChecker { ITypeBinding binding= leftOperandType; if (binding == null) return false; - + ITypeBinding current= rightOperandType; if (binding != current) return false; - + for (Iterator<Expression> iterator= expression.extendedOperands().iterator(); iterator.hasNext();) { Expression operand= iterator.next(); current= operand.resolveTypeBinding(); if (binding != current) return false; } - + return true; } @@ -147,7 +147,7 @@ public class NecessaryParenthesesChecker { /* * Is the given expression associative? - * + * * This is true if and only if:<br> * <code>left operator (right) == (right) operator left == right operator left</code> */ @@ -164,7 +164,7 @@ public class NecessaryParenthesesChecker { || operator == InfixExpression.Operator.OR || operator == InfixExpression.Operator.XOR) return true; - + return false; } @@ -211,15 +211,15 @@ public class NecessaryParenthesesChecker { if (parentInfixOperator != InfixExpression.Operator.TIMES) return false; - + if (operator == InfixExpression.Operator.TIMES) // x * (y * z) == x * y * z return false; - + if (operator == InfixExpression.Operator.REMAINDER || operator == InfixExpression.Operator.DIVIDE) // x * (y % z) != x * y % z , x * (y / z) == x * y / z rounding involved return true; - + return false; } return false; @@ -230,13 +230,13 @@ public class NecessaryParenthesesChecker { /** * Returns the type of infix expression based on its operands and operator. - * + * * @param operator the operator of infix expression * @param leftOperandType the type of left operand of infix expression * @param rightOperandType the type of right operand of infix expression * @return the type of infix expression if the type of both the operands is same or if the type * of either operand of a + operator is String, <code>null</code> otherwise. - * + * * @since 3.9 */ private static ITypeBinding getInfixExpressionType(InfixExpression.Operator operator, ITypeBinding leftOperandType, ITypeBinding rightOperandType) { @@ -257,11 +257,11 @@ public class NecessaryParenthesesChecker { /** * Can the parentheses be removed from the parenthesized expression ? - * + * * <p> * <b>Note:</b> The parenthesized expression must not be an unparented node. * </p> - * + * * @param expression the parenthesized expression * @return <code>true</code> if parentheses can be removed, <code>false</code> otherwise. */ @@ -272,11 +272,11 @@ public class NecessaryParenthesesChecker { /** * Can the parentheses be removed from the parenthesized expression when inserted into * <code>parent</code> at <code>locationInParent</code> ? - * + * * <p> * <b>Note:</b> The parenthesized expression can be an unparented node. * </p> - * + * * @param expression the parenthesized expression * @param parent the parent node * @param locationInParent location of expression in the parent @@ -292,7 +292,7 @@ public class NecessaryParenthesesChecker { /** * Does the <code>rightOperand</code> need parentheses when inserted into * <code>infixExpression</code> ? - * + * * <p> * <b>Note:</b> * <ul> @@ -302,13 +302,13 @@ public class NecessaryParenthesesChecker { * <li>The <code>rightOperand</code> node must have bindings.</li> * </ul> * </p> - * + * * @param rightOperand the right operand in <code>infixExpression</code> * @param infixExpression the parent infix expression * @param leftOperandType the type of the left operand in <code>infixExpression</code> * @return <code>true</code> if <code>rightOperand</code> needs parentheses, <code>false</code> * otherwise. - * + * * @since 3.9 */ public static boolean needsParenthesesForRightOperand(Expression rightOperand, InfixExpression infixExpression, ITypeBinding leftOperandType) { @@ -318,11 +318,11 @@ public class NecessaryParenthesesChecker { /** * Does the <code>expression</code> need parentheses when inserted into <code>parent</code> at * <code>locationInParent</code> ? - * + * * <p> * <b>Note:</b> The expression can be an unparented node. * </p> - * + * * @param expression the expression * @param parent the parent node * @param locationInParent location of expression in the parent @@ -336,7 +336,7 @@ public class NecessaryParenthesesChecker { /** * Does the <code>expression</code> need parentheses when inserted into <code>parent</code> at * <code>locationInParent</code> ? - * + * * @param expression the expression * @param parent the parent node * @param locationInParent location of expression in the parent @@ -345,7 +345,7 @@ public class NecessaryParenthesesChecker { * <code>expression</code> is the right operand in it, <code>null</code> otherwise * @return <code>true</code> if <code>expression</code> needs parentheses, <code>false</code> * otherwise. - * + * * @since 3.9 */ private static boolean needsParentheses(Expression expression, ASTNode parent, StructuralPropertyDescriptor locationInParent, ITypeBinding leftOperandType) { @@ -358,7 +358,7 @@ public class NecessaryParenthesesChecker { if (parent instanceof Expression) { Expression parentExpression= (Expression)parent; - + if (expression instanceof PrefixExpression) { // see bug 405096 return needsParenthesesForPrefixExpression(parentExpression, ((PrefixExpression) expression).getOperator()); } @@ -393,7 +393,7 @@ public class NecessaryParenthesesChecker { return true; } - + private static boolean needsParenthesesForPrefixExpression(Expression parentExpression, PrefixExpression.Operator expressionOperator) { if (parentExpression instanceof PrefixExpression) { PrefixExpression.Operator parentOperator= ((PrefixExpression) parentExpression).getOperator(); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/util/BasicElementLabels.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/util/BasicElementLabels.java index 3a49c48db6..aea795c447 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/util/BasicElementLabels.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/util/BasicElementLabels.java @@ -37,7 +37,7 @@ public class BasicElementLabels { private static final String FILE_PATTERN_DELIMITERS= TextProcessor.getDefaultDelimiters() + "*.?"; //$NON-NLS-1$ private static final String URL_DELIMITERS= TextProcessor.getDefaultDelimiters() + ":@?-"; //$NON-NLS-1$ - + /** * Returns the label of a path. * diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/util/Strings.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/util/Strings.java index 49f0153307..1852cf697f 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/util/Strings.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/core/manipulation/util/Strings.java @@ -54,7 +54,7 @@ public class Strings { /** * Adds special marks so that that the given string is readable in a BiDi environment. - * + * * @param string the string * @return the processed styled string * @since 3.4 @@ -68,7 +68,7 @@ public class Strings { /** * Adds special marks so that that the given string is readable in a BiDi environment. - * + * * @param string the string * @param delimiters the delimiters * @return the processed styled string @@ -84,7 +84,7 @@ public class Strings { /** * Adds special marks so that that the given Java element label is readable in a BiDi * environment. - * + * * @param string the string * @return the processed styled string * @since 3.6 diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java index add7795528..39546c9687 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/CorextMessages.java @@ -34,7 +34,7 @@ public final class CorextMessages extends NLS { public static String JavaDocLocations_noAttachedSource; public static String JavaDocLocations_noAttachments; public static String JavaDocLocations_noInformation; - + public static String History_error_serialize; public static String History_error_read; public static String TypeInfoHistory_consistency_check; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallerMethodWrapper.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallerMethodWrapper.java index e0390f042f..d2fcd00549 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallerMethodWrapper.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/CallerMethodWrapper.java @@ -46,14 +46,14 @@ import org.eclipse.jdt.internal.corext.util.SearchUtils; public class CallerMethodWrapper extends MethodWrapper { /** * Value of the expand with constructors mode. - * + * * @since 3.5 */ private boolean fExpandWithConstructors; /** * Tells whether the expand with constructors mode has been set. - * + * * @see #setExpandWithConstructors(boolean) * @since 3.5 */ @@ -179,10 +179,10 @@ public class CallerMethodWrapper extends MethodWrapper { /** * Returns the value of expand with constructors mode. - * + * * @return <code>true</code> if in expand with constructors mode, <code>false</code> otherwise or if not yet set * @see #isExpandWithConstructorsSet() - * + * * @since 3.5 */ public boolean getExpandWithConstructors() { @@ -191,7 +191,7 @@ public class CallerMethodWrapper extends MethodWrapper { /** * Sets the expand with constructors mode. - * + * * @param value <code>true</code> if in expand with constructors mode, <code>false</code> * otherwise * @since 3.5 @@ -204,7 +204,7 @@ public class CallerMethodWrapper extends MethodWrapper { /** * Tells whether the expand with constructors mode has been set. - * + * * @return <code>true</code> if expand with constructors mode has been set explicitly, <code>false</code> otherwise * @see #setExpandWithConstructors(boolean) * @since 3.5 diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/RealCallers.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/RealCallers.java index e796b325b1..7d5620ad80 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/RealCallers.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/callhierarchy/RealCallers.java @@ -15,14 +15,14 @@ package org.eclipse.jdt.internal.corext.callhierarchy; /** * Class for the real callers. - * + * * @since 3.5 */ public class RealCallers extends CallerMethodWrapper { /** * Sets the parent method wrapper. - * + * * @param methodWrapper the method wrapper * @param methodCall the method call */ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/CodeGenerationSettingsConstants.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/CodeGenerationSettingsConstants.java index c32beac150..6e57b46164 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/CodeGenerationSettingsConstants.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/CodeGenerationSettingsConstants.java @@ -15,7 +15,7 @@ package org.eclipse.jdt.internal.corext.codemanipulation; public class CodeGenerationSettingsConstants { - + /** * A named preference that controls if comment stubs will be added * automatically to newly created types and methods. @@ -24,7 +24,7 @@ public class CodeGenerationSettingsConstants { * </p> */ public static final String CODEGEN_ADD_COMMENTS= "org.eclipse.jdt.ui.javadoc"; //$NON-NLS-1$ - + /** * A named preference that controls whether the keyword "this" will be added * automatically to field accesses in generated methods. @@ -33,7 +33,7 @@ public class CodeGenerationSettingsConstants { * </p> */ public static final String CODEGEN_KEYWORD_THIS= "org.eclipse.jdt.ui.keywordthis"; //$NON-NLS-1$ - + /** * A named preference that controls whether to add a override annotation for newly created methods * <p> diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ContextSensitiveImportRewriteContext.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ContextSensitiveImportRewriteContext.java index df70e59e85..bfda4a6d88 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ContextSensitiveImportRewriteContext.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/ContextSensitiveImportRewriteContext.java @@ -61,19 +61,19 @@ public class ContextSensitiveImportRewriteContext extends ImportRewriteContext { /** * Creates an import rewrite context at the given node's start position. - * + * * @param node the node to use as context * @param importRewrite the import rewrite - * + * * @since 3.6 */ public ContextSensitiveImportRewriteContext(ASTNode node, ImportRewrite importRewrite) { this((CompilationUnit) node.getRoot(), node.getStartPosition(), importRewrite, RedundantNullnessTypeAnnotationsFilter.createIfConfigured(node)); } - + /** * Creates an import rewrite context at the given start position. - * + * * @param compilationUnit the root (must have resolved bindings) * @param position the context position * @param importRewrite the import rewrite @@ -233,7 +233,7 @@ public class ContextSensitiveImportRewriteContext extends ImportRewriteContext { } return fImportedNames; } - + @Override public IAnnotationBinding[] removeRedundantTypeAnnotations(IAnnotationBinding[] annotations, TypeLocation location, ITypeBinding type) { RedundantNullnessTypeAnnotationsFilter redundantTypeAnnotationsFilter= fRedundantTypeAnnotationsFilter; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java index 17ceddc608..67771de72a 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/GenerateHashCodeEqualsOperation.java @@ -150,7 +150,7 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable private static final String METHODNAME_GETCLASS= "getClass"; //$NON-NLS-1$ private static final String METHODNAME_EQUALS= "equals"; //$NON-NLS-1$ - + private static final String METHODNAME_DEEP_EQUALS= "deepEquals"; //$NON-NLS-1$ private static final String METHODNAME_HASH_CODE= "hashCode"; //$NON-NLS-1$ @@ -426,7 +426,7 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable Block body= fAst.newBlock(); hashCodeMethod.setBody(body); - + boolean needsNoSuperCall= needsNoSuperCall(fType, METHODNAME_HASH_CODE, new ITypeBinding[0]); boolean memberType= isMemberType(); ReturnStatement endReturn= fAst.newReturnStatement(); @@ -1085,7 +1085,7 @@ public final class GenerateHashCodeEqualsOperation implements IWorkspaceRunnable return ifSt; } - + private Statement createMultiArrayComparison(String name) { MethodInvocation invoc= fAst.newMethodInvocation(); invoc.setName(fAst.newSimpleName(METHODNAME_DEEP_EQUALS)); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java index 5e28bb7dc4..8e210ad1ab 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/StubUtility2Core.java @@ -300,7 +300,7 @@ public final class StubUtility2Core { } return decl; } - + public static MethodDeclaration createImplementationStubCore(ICompilationUnit unit, ASTRewrite rewrite, ImportRewrite imports, ImportRewriteContext context, IMethodBinding binding, ITypeBinding targetType, CodeGenerationSettings settings, boolean inInterface, ASTNode astNode, boolean snippetStringSupport) throws CoreException { @@ -312,7 +312,7 @@ public final class StubUtility2Core { IMethodBinding binding, String[] parameterNames, ITypeBinding targetType, CodeGenerationSettings settings, boolean inInterface, ASTNode astNode, boolean snippetStringSupport) throws CoreException { Assert.isNotNull(imports); Assert.isNotNull(rewrite); - + AST ast= rewrite.getAST(); String type= Bindings.getTypeQualifiedName(targetType); @@ -493,7 +493,7 @@ public final class StubUtility2Core { } type= type.getComponentType(); } - + Type elementType= imports.addImport(type, ast, context); if (dimensions == 1) { var.setType(elementType); @@ -570,7 +570,7 @@ public final class StubUtility2Core { private static void findUnimplementedInterfaceMethods(ITypeBinding typeBinding, HashSet<ITypeBinding> visited, ArrayList<IMethodBinding> allMethods, IPackageBinding currPack, ArrayList<IMethodBinding> toImplement) { - + if (visited.add(typeBinding)) { nextMethod: for (IMethodBinding curr : typeBinding.getDeclaredMethods()) { for (Iterator<IMethodBinding> allIter= allMethods.iterator(); allIter.hasNext();) { @@ -624,7 +624,7 @@ public final class StubUtility2Core { } modifiers= modifiers & ~Modifier.ABSTRACT & ~Modifier.NATIVE & ~Modifier.PRIVATE; IAnnotationBinding[] annotations= method.getAnnotations(); - + if (modifiers != Modifier.NONE && annotations.length > 0) { // need an AST of the source method to preserve order of modifiers IMethod iMethod= (IMethod) method.getJavaElement(); @@ -664,16 +664,16 @@ public final class StubUtility2Core { } } } - + ArrayList<IExtendedModifier> result= new ArrayList<>(); - + for (IAnnotationBinding annotation : annotations) { if (StubUtility2Core.isCopyOnInheritAnnotation(annotation.getAnnotationType(), javaProject, nullnessDefault, TypeLocation.RETURN_TYPE)) result.add(importRewrite.addAnnotation(annotation, ast, context)); } - + result.addAll(ASTNodeFactory.newModifiers(ast, modifiers)); - + return result; } @@ -925,7 +925,7 @@ public final class StubUtility2Core { /** * Adds <code>@Override</code> annotation to <code>methodDecl</code> if not already present and * if requested by code style settings or compiler errors/warnings settings. - * + * * @param settings the code generation style settings, may be <code>null</code> * @param project the Java project used to access the compiler settings * @param rewrite the ASTRewrite @@ -991,7 +991,7 @@ public final class StubUtility2Core { } return null; } - + public static ITypeBinding replaceWildcardsAndCaptures(ITypeBinding type) { while (type.isWildcardType() || type.isCapture() || (type.isArray() && type.getElementType().isCapture())) { ITypeBinding bound = type.getBound(); @@ -999,7 +999,7 @@ public final class StubUtility2Core { } return type; } - + /** * Creates a new stub utility. */ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java index 741398f3e5..a8190a0a05 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/AbstractToStringGenerator.java @@ -76,7 +76,7 @@ import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory; * which lists all selected fields and methods. What exactly is listed and how members are separated * is determined by a format template. * <p> - * + * * <p> * To print out items of arrays and/or limit number items printed for arrays, collections and so on, * various methods are used according to actual jdk compatibility: @@ -133,7 +133,7 @@ import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory; * Additionally, if helper method is generated it is also used for other members members (even if * other solution could be used), as it makes the code cleaner. * </p> - * + * * @since 3.5 */ public abstract class AbstractToStringGenerator { @@ -148,7 +148,7 @@ public abstract class AbstractToStringGenerator { final private String MAX_LEN_VARIABLE_NAME= "maxLen"; //$NON-NLS-1$ protected String fMaxLenVariableName= MAX_LEN_VARIABLE_NAME; - + /** * The name of the property that every <code>MethodDeclaration</code> generated should have. * This property determines whether the method should be overwritten if already exists. The data @@ -180,7 +180,7 @@ public abstract class AbstractToStringGenerator { /** * This method is an implementation of Director in Builder pattern. It goes through all elements * of the format template and calls methods responsible for processing them. - * + * * @return declaration of the generated <code>toString()</code> method * @throws CoreException if creation failed */ @@ -223,7 +223,7 @@ public abstract class AbstractToStringGenerator { /** * adds a comment (if necessary) and an <code>@Override</code> annotation to the generated * method - * + * * @throws CoreException if creation failed */ protected void createMethodComment() throws CoreException { @@ -248,7 +248,7 @@ public abstract class AbstractToStringGenerator { /** * Creates a method that takes a <code>Collection</code> or an Array and returns a * <code>String</code> containing it's first <code>fSettings.limitValue</code> elements - * + * * @param array if true, generated method will convert array to string, otherwise - * <code>Collection</code> * @return <code>arrayToString(Object[] array)</code> or </code>collectionToString(Collection @@ -428,7 +428,7 @@ public abstract class AbstractToStringGenerator { Expression indexExpression= createInfixExpression(fAst.newSimpleName(indexName), Operator.LESS, fAst.newSimpleName(maxLenParamName)); forStatement.setExpression(createInfixExpression(createMethodInvocation(iteratorName, "hasNext", null), Operator.CONDITIONAL_AND, indexExpression)); //$NON-NLS-1$ - //if (i > 0) + //if (i > 0) //stringBuilder.append(iterator.next()); MethodInvocation nextInvocation= createMethodInvocation(iteratorName, "next", null); //$NON-NLS-1$ forBlock.statements().add(fAst.newExpressionStatement(createMethodInvocation(stringBuilderName, appendMethodName, nextInvocation))); @@ -472,14 +472,14 @@ public abstract class AbstractToStringGenerator { Block body= fAst.newBlock(); toStringMethod.setBody(body); - + fMaxLenVariableName= createNameSuggestion(MAX_LEN_VARIABLE_NAME, NamingConventions.VK_LOCAL); } /** * This method is called at the end of the process of generating <code>toString</code> method. * It should make sure the processed properly and clean the environment. - * + * * @throws CoreException if creation failed */ protected void complete() throws CoreException { @@ -521,7 +521,7 @@ public abstract class AbstractToStringGenerator { } /** - * + * * @param templateElement the template element, see constants in {@link ToStringTemplateParser} * @param member the member * @return <code>String</code> or <code>Expression</code> switching @@ -575,7 +575,7 @@ public abstract class AbstractToStringGenerator { /** * Adds an element to the generated <code>toString</code> method. This method is called for * every element of the format template. - * + * * @param element String or expression to be added (<code>IVariableBinding</code> or * <code>IMethodBinding</code> */ @@ -584,7 +584,7 @@ public abstract class AbstractToStringGenerator { /** * Adds a member to the <code>toString</code> method. This method is called for every member if * "Skip null values" options is unchecked. - * + * * @param member a member to be added * @param addSeparator true, if separator should be added after the member (i.e. this is not the * last member) @@ -602,7 +602,7 @@ public abstract class AbstractToStringGenerator { * This method is called for every non-primitive type member if "Skip null values" options is * checked, or for every <code>Collection</code> and <code>Map</code> member if there's a limit * for number of elements. - * + * * @param member a member to be added * @param addSeparator true, if separator should be added after the member (i.e. this is not the * last member) @@ -613,7 +613,7 @@ public abstract class AbstractToStringGenerator { /** * Creates an invocation of a method that takes zero or one argument - * + * * @param expression the receiver expression * @param methodName the method name * @param argument the argument, can be <code>null</code> if the method does not take any arguments @@ -630,7 +630,7 @@ public abstract class AbstractToStringGenerator { /** * Creates an invocation of a method that takes zero or one argument - * + * * @param receiver the receiver name * @param methodName the method name * @param argument the argument, can be <code>null</code> if the method does not take any arguments @@ -639,10 +639,10 @@ public abstract class AbstractToStringGenerator { protected MethodInvocation createMethodInvocation(String receiver, String methodName, Expression argument) { return createMethodInvocation(fAst.newName(receiver), methodName, argument); } - + /** * Creates a statement that can be used as for/while/if-then-else block - * + * * @param expression an expression * @return a single-line statement, or a block, depending on settings */ @@ -843,7 +843,7 @@ public abstract class AbstractToStringGenerator { /** * Adds an import to the class. This method should be used for every class reference added to * the generated code. - * + * * @param typeName a fully qualified name of a type * @return simple name of a class if the import was added and fully qualified name if there was * a conflict @@ -852,7 +852,7 @@ public abstract class AbstractToStringGenerator { String importedName= fContext.getImportRewrite().addImport(typeName); return fAst.newName(importedName); } - + private Set<String> excluded; protected String createNameSuggestion(String baseName, int variableKind) { if (excluded == null) { @@ -887,7 +887,7 @@ public abstract class AbstractToStringGenerator { /** * Checks whether given type implements given interface - * + * * @param memberType binding of the type to check * @param interfaceNames fully qualified names of the interfaces to seek for * @return array of booleans, every element is set to true if interface at the same position in @@ -909,7 +909,7 @@ public abstract class AbstractToStringGenerator { } /** - * + * * @param member <code>IVariableBinding</code> or <code>IMethodBinding</code> representing a * member * @param templateElement the template element @@ -929,7 +929,7 @@ public abstract class AbstractToStringGenerator { } /** - * + * * @param member member to check * @return type of field or method's return type */ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/CustomBuilderGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/CustomBuilderGenerator.java index 14a6b5d245..e1cabf16b1 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/CustomBuilderGenerator.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/CustomBuilderGenerator.java @@ -67,7 +67,7 @@ import org.eclipse.jdt.internal.corext.util.JavaModelUtil; * </p> * <p> * Generated methods look like this: - * + * * <pre> * public String toString() { * ExternalBuilder builder= new ExternalBuilder(); @@ -76,9 +76,9 @@ import org.eclipse.jdt.internal.corext.util.JavaModelUtil; * return builder.toString(); * } * </pre> - * + * * </p> - * + * * @since 3.5 */ public class CustomBuilderGenerator extends AbstractToStringGenerator { @@ -117,9 +117,9 @@ public class CustomBuilderGenerator extends AbstractToStringGenerator { /** * Information about versions of append method in the builder type - * + * * key: String - fully qualified name of a member type - * + * * value: {@link AppendMethodInformation} - information about corresponding method */ private HashMap<String, AppendMethodInformation> appendMethodSpecificTypes= new HashMap<>(); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/GenerateToStringOperation.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/GenerateToStringOperation.java index f9bad2efa7..0de49c8ca8 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/GenerateToStringOperation.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/GenerateToStringOperation.java @@ -54,7 +54,7 @@ import org.eclipse.jdt.internal.corext.util.JavaModelUtil; * <p> * A workspace runnable to add implementation for <code>{@link java.lang.Object#toString()}</code> * </p> - * + * * @since 3.5 */ public class GenerateToStringOperation implements IWorkspaceRunnable { @@ -158,7 +158,7 @@ public class GenerateToStringOperation implements IWorkspaceRunnable { /** * Determines if given method exists in a given list - * + * * @param list list of method to search through * @param method method to find * @return declaration of method from the list that has the same name and parameter types, or @@ -217,7 +217,7 @@ public class GenerateToStringOperation implements IWorkspaceRunnable { } /** - * + * * @param toStringStyle id number of the code style (its position in the array returned by * {@link #getStyleNames()} * @return a toString() generator implementing given code style @@ -251,7 +251,7 @@ public class GenerateToStringOperation implements IWorkspaceRunnable { /** * Creates new <code>GenerateToStringOperation</code>, using <code>settings.toStringStyle</code> * field to choose the right subclass. - * + * * @param typeBinding binding for the type for which the toString() method will be created * @param selectedBindings bindings for the typetype's members to be used in created method * @param unit a compilation unit containing the type diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderChainGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderChainGenerator.java index b0fb3367c9..46ffdbd969 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderChainGenerator.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderChainGenerator.java @@ -33,7 +33,7 @@ import org.eclipse.jdt.core.dom.InfixExpression.Operator; * </p> * <p> * Generated methods look like this: - * + * * <pre> * public String toString() { * StringBuilder builder= new StringBuilder(); @@ -41,9 +41,9 @@ import org.eclipse.jdt.core.dom.InfixExpression.Operator; * return builder.toString(); * } * </pre> - * + * * </p> - * + * * @since 3.5 */ public class StringBuilderChainGenerator extends StringBuilderGenerator { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderGenerator.java index f982199a67..4d0e96e6fa 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderGenerator.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringBuilderGenerator.java @@ -38,7 +38,7 @@ import org.eclipse.jdt.core.dom.InfixExpression.Operator; * </p> * <p> * Generated methods look like this: - * + * * <pre> * public String toString() { * StringBuilder builder= new StringBuilder(); @@ -50,9 +50,9 @@ import org.eclipse.jdt.core.dom.InfixExpression.Operator; * return builder.toString(); * } * </pre> - * + * * </p> - * + * * @since 3.5 */ public class StringBuilderGenerator extends AbstractToStringGenerator { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringConcatenationGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringConcatenationGenerator.java index 251ea57af0..cd64164ce9 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringConcatenationGenerator.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringConcatenationGenerator.java @@ -33,15 +33,15 @@ import org.eclipse.jdt.core.dom.InfixExpression.Operator; * </p> * <p> * Generated methods look like this: - * + * * <pre> * public String toString() { * return "FooClass( field1=" + field1 + ", field2=" + field2 + ", method1()=" + method1 + ")"; * } * </pre> - * + * * </p> - * + * * @since 3.5 */ public class StringConcatenationGenerator extends AbstractToStringGenerator { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringFormatGenerator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringFormatGenerator.java index 5935bad7fc..a5b565efd3 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringFormatGenerator.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/StringFormatGenerator.java @@ -36,15 +36,15 @@ import org.eclipse.jdt.core.dom.StringLiteral; * method using <code>String.format()</code>. This style ignores <i>skip null values</i> option. * <p> * Generated methods look like this: - * + * * <pre> * public String toString() { * return String.format("FooClass( field1=%s, field2=%s )", field1, field2); * } * </pre> - * + * * </p> - * + * * @since 3.5 */ public class StringFormatGenerator extends AbstractToStringGenerator { @@ -68,7 +68,7 @@ public class StringFormatGenerator extends AbstractToStringGenerator { formatClass= "java.lang.String"; //$NON-NLS-1$ else formatClass= "java.text.MessageFormat"; //$NON-NLS-1$ - MethodInvocation formatInvocation= createMethodInvocation(addImport(formatClass), "format", null); //$NON-NLS-1$ + MethodInvocation formatInvocation= createMethodInvocation(addImport(formatClass), "format", null); //$NON-NLS-1$ StringLiteral literal= fAst.newStringLiteral(); literal.setLiteralValue(buffer.toString()); formatInvocation.arguments().add(literal); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringGenerationContext.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringGenerationContext.java index 85b1061f60..7cd2a7d726 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringGenerationContext.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringGenerationContext.java @@ -34,7 +34,7 @@ class ToStringGenerationContext { private ITypeBinding fType; private ToStringGenerationSettingsCore fSettings; - + private ToStringGenerationSettingsCore.CustomBuilderSettings fCustomBuilderSettings; private CompilationUnitRewrite fRewrite; @@ -116,23 +116,23 @@ class ToStringGenerationContext { public boolean isSkipNulls() { return fSettings.skipNulls; } - + public String getCustomBuilderClass() { return fCustomBuilderSettings.className; } - + public String getCustomBuilderVariableName() { return fCustomBuilderSettings.variableName; } - + public String getCustomBuilderAppendMethod() { return fCustomBuilderSettings.appendMethod; } - + public String getCustomBuilderResultMethod() { return fCustomBuilderSettings.resultMethod; } - + public boolean isCustomBuilderChainedCalls() { return fCustomBuilderSettings.chainCalls; } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringGenerationSettingsCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringGenerationSettingsCore.java index ceefd8d9b0..2585fbd8e4 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringGenerationSettingsCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringGenerationSettingsCore.java @@ -111,9 +111,9 @@ public class ToStringGenerationSettingsCore extends CodeGenerationSettings { /** * Returns a copy of customBuilderSettings. Changes made in the returned object will not affect * this settings object. To save changes made to the object, use: - * + * * ToStringGenerationSettings#writeCustomBuilderSettings(ToStringGenerationSettings.CustomBuilderSettings) - * + * * @return copy of custom builder settings object */ public CustomBuilderSettings getCustomBuilderSettings() { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringTemplateParser.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringTemplateParser.java index 753b129580..31027a9fdd 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringTemplateParser.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/codemanipulation/tostringgeneration/ToStringTemplateParser.java @@ -48,7 +48,7 @@ import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationMessages; * variable and exactly one <code>${otherMembers}</code> variable. Additionally, no * <code>${member.*}</code> variables can follow the <code>${otherMembers}</code> variable. * </p> - * + * * @since 3.5 */ public class ToStringTemplateParser { @@ -126,7 +126,7 @@ public class ToStringTemplateParser { /** * This method is used in {@link #parseTemplate(String)} to determine what member specific * variables are expected in a template. - * + * * @return member related variables recognized by this parser */ protected String[] getMemberRelatedVariables() { @@ -136,7 +136,7 @@ public class ToStringTemplateParser { /** * This method is used in {@link #parseTemplate(String)} to determine what object related * variables are expected in a template. - * + * * @return object related variables recognized by this parser */ protected String[] getObjectRelatedVariables() { @@ -146,7 +146,7 @@ public class ToStringTemplateParser { /** * This method is used in {@link #parseTemplate(String)}. It returns all variables returned by * {@link #getMemberRelatedVariables()} and {@link #getObjectRelatedVariables()} (sum of sets). - * + * * @return member and object related variables recognized by this parser (all variables but * {$otherMembers}) */ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java index ac6fe34889..07376a526b 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTFlattener.java @@ -139,7 +139,7 @@ public class ASTFlattener extends GenericVisitor { this.fBuffer.append('>'); } } - + void printTypeAnnotations(AnnotatableType node) { if (node.getAST().apiLevel() >= JLS8) { printAnnotationsList(node.annotations()); @@ -535,7 +535,7 @@ public class ASTFlattener extends GenericVisitor { this.fBuffer.append(";");//$NON-NLS-1$ return false; } - + /* * @see ASTVisitor#visit(CreationReference) */ @@ -1643,7 +1643,7 @@ public class ASTFlattener extends GenericVisitor { visitSwitchNode(node); return false; } - + @Override public boolean visit(SwitchExpression node) { visitSwitchNode(node); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodeFactory.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodeFactory.java index 718e45ff03..a0523b874e 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodeFactory.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodeFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -11,6 +11,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Red Hat Inc. - refactored to jdt.core.manipulation + * Fabrice TIERCELIN - Methods to identify a signature *******************************************************************************/ package org.eclipse.jdt.internal.corext.dom; @@ -38,6 +39,7 @@ import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.core.dom.NodeFinder; import org.eclipse.jdt.core.dom.ParameterizedType; +import org.eclipse.jdt.core.dom.ParenthesizedExpression; import org.eclipse.jdt.core.dom.PrimitiveType; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.Type; @@ -55,7 +57,7 @@ import org.eclipse.jdt.internal.corext.codemanipulation.StubUtility2Core; /** * JDT-UI-internal helper methods to create new {@link ASTNode}s. * Complements <code>AST#new*(..)</code> and <code>ImportRewrite#add*(..)</code>. - * + * * see JDTUIHelperClasses */ public class ASTNodeFactory { @@ -86,6 +88,41 @@ public class ASTNodeFactory { // no instance; } + /** + * Parenthesizes the provided expression if its type requires it. + * + * @param ast The AST to create the resulting node with. + * @param expression the expression to conditionally return parenthesized + * @return the parenthesized expression of the provided expression to return or this expression + * itself + */ + public static Expression parenthesizeIfNeeded(AST ast, Expression expression) { + switch (expression.getNodeType()) { + case ASTNode.ASSIGNMENT: + case ASTNode.CAST_EXPRESSION: + case ASTNode.CONDITIONAL_EXPRESSION: + case ASTNode.INFIX_EXPRESSION: + case ASTNode.INSTANCEOF_EXPRESSION: + return parenthesize(ast, expression); + + default: + return expression; + } + } + + /** + * Builds a new {@link ParenthesizedExpression} instance. + * + * @param ast The AST to create the resulting node with. + * @param expression the expression to wrap with parentheses + * @return a new parenthesized expression + */ + public static ParenthesizedExpression parenthesize(AST ast, Expression expression) { + final ParenthesizedExpression pe= ast.newParenthesizedExpression(); + pe.setExpression(expression); + return pe; + } + public static ASTNode newStatement(AST ast, String content) { StringBuilder buffer= new StringBuilder(STATEMENT_HEADER); buffer.append(content); @@ -139,7 +176,7 @@ public class ASTNodeFactory { * Returns an {@link ArrayType} that adds one dimension to the given type node. * If the given node is already an ArrayType, then a new {@link Dimension} * without annotations is inserted at the first position. - * + * * @param type the type to be wrapped * @return the array type * @since 3.10 @@ -170,13 +207,13 @@ public class ASTNodeFactory { * Returns the new type node corresponding to the type of the given declaration * including the extra dimensions. If the type is a {@link UnionType}, use the LUB type. * If the <code>importRewrite</code> is <code>null</code>, the type may be fully-qualified. - * + * * @param ast The AST to create the resulting type with. * @param declaration The variable declaration to get the type from * @param importRewrite the import rewrite to use, or <code>null</code> * @param context the import rewrite context, or <code>null</code> * @return a new type node created with the given AST. - * + * * @since 3.7.1 */ public static Type newType(AST ast, VariableDeclaration declaration, ImportRewrite importRewrite, ImportRewriteContext context) { @@ -206,9 +243,9 @@ public class ASTNodeFactory { return type; } } - + type= (Type) ASTNode.copySubtree(ast, type); - + List<Dimension> extraDimensions= declaration.extraDimensions(); if (!extraDimensions.isEmpty()) { ArrayType arrayType; @@ -281,14 +318,14 @@ public class ASTNodeFactory { /** * Returns the new type node representing the return type of <code>lambdaExpression</code> * including the extra dimensions. - * + * * @param lambdaExpression the lambda expression * @param ast the AST to create the return type with * @param importRewrite the import rewrite to use, or <code>null</code> * @param context the import rewrite context, or <code>null</code> * @return a new type node created with the given AST representing the return type of * <code>lambdaExpression</code> - * + * * @since 3.10 */ public static Type newReturnType(LambdaExpression lambdaExpression, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java index 5e4e0a6b55..cadff3dc94 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ASTNodes.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -19,6 +19,8 @@ * Stephan Herrmann - Configuration for * Bug 463360 - [override method][null] generating method override should not create redundant null annotations * Fabrice TIERCELIN - Methods to identify a signature + * Pierre-Yves B. (pyvesdev@gmail.com) - contributed fix for + * Bug 434747 - [inline] Inlining a local variable leads to ambiguity with overloaded methods *******************************************************************************/ package org.eclipse.jdt.internal.corext.dom; @@ -127,6 +129,8 @@ import org.eclipse.jdt.core.formatter.IndentManipulation; import org.eclipse.jdt.internal.core.manipulation.JavaManipulationPlugin; import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving; import org.eclipse.jdt.internal.core.manipulation.util.Strings; +import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType; +import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeEnvironment; import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; @@ -418,6 +422,24 @@ public class ASTNodes { return Modifier.isStatic(declaration.getModifiers()); } + /** + * True if the method is static, false if it is not or null if it is unknown. + * + * @param method The method + * @return True if the method is static, false if it is not or null if it is unknown. + */ + public static Boolean isStatic(final MethodInvocation method) { + Expression calledType= method.getExpression(); + + if (method.resolveMethodBinding() != null) { + return (method.resolveMethodBinding().getModifiers() & Modifier.STATIC) != 0; + } else if ((calledType instanceof Name) && ((Name) calledType).resolveBinding().getKind() == IBinding.TYPE) { + return Boolean.TRUE; + } + + return null; + } + public static List<BodyDeclaration> getBodyDeclarations(ASTNode node) { if (node instanceof AbstractTypeDeclaration) { return ((AbstractTypeDeclaration)node).bodyDeclarations(); @@ -838,6 +860,11 @@ public class ASTNodes { } else if (! TypeRules.canAssign(initializerType, referenceType)) { if (!Bindings.containsTypeVariables(referenceType)) return referenceType; + + } else if (!initializerType.isEqualTo(referenceType)) { + if (isTargetAmbiguous(reference, initializerType)) { + return referenceType; + } } return null; @@ -857,6 +884,71 @@ public class ASTNodes { * @since 3.10 */ public static boolean isTargetAmbiguous(Expression expression, boolean expressionIsExplicitlyTyped) { + ParentSummary targetSummary= getParentSummary(expression); + if (targetSummary == null) { + return false; + } + + if (targetSummary.methodBinding != null) { + ITypeBinding invocationTargetType= getInvocationType(expression.getParent(), targetSummary.methodBinding, targetSummary.invocationQualifier); + if (invocationTargetType != null) { + TypeBindingVisitor visitor= new FunctionalInterfaceAmbiguousMethodAnalyzer(invocationTargetType, targetSummary.methodBinding, targetSummary.argumentIndex, + targetSummary.argumentCount, expressionIsExplicitlyTyped); + return !(visitor.visit(invocationTargetType) && Bindings.visitHierarchy(invocationTargetType, visitor)); + } + } + + return true; + } + + /** + * Checks whether overloaded methods can result in an ambiguous method call or a semantic change + * when the <code>expression</code> argument is inlined. + * + * @param expression the method argument, which is a functional interface instance + * @param initializerType the initializer type of the variable to inline + * @return <code>true</code> if overloaded methods can result in an ambiguous method call or a + * semantic change, <code>false</code> otherwise + * + * @since 3.19 + */ + public static boolean isTargetAmbiguous(Expression expression, ITypeBinding initializerType) { + ParentSummary parentSummary= getParentSummary(expression); + if (parentSummary == null) { + return false; + } + + IMethodBinding methodBinding= parentSummary.methodBinding; + if (methodBinding != null) { + ITypeBinding[] parameterTypes= methodBinding.getParameterTypes(); + int argumentIndex= parentSummary.argumentIndex; + if (methodBinding.isVarargs() && argumentIndex >= parameterTypes.length - 1) { + argumentIndex= parameterTypes.length - 1; + initializerType= initializerType.createArrayType(1); + } + parameterTypes[argumentIndex]= initializerType; + + ITypeBinding invocationType= getInvocationType(expression.getParent(), methodBinding, parentSummary.invocationQualifier); + if (invocationType != null) { + TypeEnvironment typeEnvironment= new TypeEnvironment(); + TypeBindingVisitor visitor= new AmbiguousMethodAnalyzer(typeEnvironment, methodBinding, typeEnvironment.create(parameterTypes)); + if (!visitor.visit(invocationType)) { + return true; + } else if (invocationType.isInterface()) { + return !Bindings.visitInterfaces(invocationType, visitor); + } else if (Modifier.isAbstract(invocationType.getModifiers())) { + return !Bindings.visitHierarchy(invocationType, visitor); + } else { + // it is not needed to visit interfaces if receiver is a concrete class + return !Bindings.visitSuperclasses(invocationType, visitor); + } + } + } + + return true; + } + + private static ParentSummary getParentSummary(Expression expression) { StructuralPropertyDescriptor locationInParent= expression.getLocationInParent(); while (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY @@ -904,19 +996,28 @@ public class ASTNodes { argumentIndex= enumConstantDecl.arguments().indexOf(expression); argumentCount= enumConstantDecl.arguments().size(); } else { - return false; + return null; } - if (methodBinding != null) { - ITypeBinding invocationTargetType; - invocationTargetType= getInvocationType(parent, methodBinding, invocationQualifier); - if (invocationTargetType != null) { - TypeBindingVisitor visitor= new AmbiguousTargetMethodAnalyzer(invocationTargetType, methodBinding, argumentIndex, argumentCount, expressionIsExplicitlyTyped); - return !(visitor.visit(invocationTargetType) && Bindings.visitHierarchy(invocationTargetType, visitor)); - } - } + return new ParentSummary(methodBinding, argumentIndex, argumentCount, invocationQualifier); + } - return true; + private static class ParentSummary { + + private final IMethodBinding methodBinding; + + private final int argumentIndex; + + private final int argumentCount; + + private final Expression invocationQualifier; + + ParentSummary(IMethodBinding methodBinding, int argumentIndex, int argumentCount, Expression invocationQualifier) { + this.methodBinding= methodBinding; + this.argumentIndex= argumentIndex; + this.argumentCount= argumentCount; + this.invocationQualifier= invocationQualifier; + } } /** @@ -960,7 +1061,56 @@ public class ASTNodes { return invocationType; } - private static class AmbiguousTargetMethodAnalyzer implements TypeBindingVisitor { + private static class AmbiguousMethodAnalyzer implements TypeBindingVisitor { + private TypeEnvironment fTypeEnvironment; + private TType[] fTypes; + private IMethodBinding fOriginal; + + public AmbiguousMethodAnalyzer(TypeEnvironment typeEnvironment, IMethodBinding original, TType[] types) { + fTypeEnvironment= typeEnvironment; + fOriginal= original; + fTypes= types; + } + + @Override + public boolean visit(ITypeBinding node) { + IMethodBinding[] methods= node.getDeclaredMethods(); + for (int i= 0; i < methods.length; i++) { + IMethodBinding candidate= methods[i]; + if (candidate == fOriginal) { + continue; + } + if (fOriginal.getName().equals(candidate.getName())) { + if (canImplicitlyCall(candidate)) { + return false; + } + } + } + return true; + } + + /** + * Returns <code>true</code> if the method can be called without explicit casts; otherwise + * <code>false</code>. + * + * @param candidate the method to test + * @return <code>true</code> if the method can be called without explicit casts + */ + private boolean canImplicitlyCall(IMethodBinding candidate) { + ITypeBinding[] parameters= candidate.getParameterTypes(); + if (parameters.length != fTypes.length) { + return false; + } + for (int i= 0; i < parameters.length; i++) { + if (!fTypes[i].canAssignTo(fTypeEnvironment.create(parameters[i]))) { + return false; + } + } + return true; + } + } + + private static class FunctionalInterfaceAmbiguousMethodAnalyzer implements TypeBindingVisitor { private ITypeBinding fDeclaringType; private IMethodBinding fOriginalMethod; private int fArgIndex; @@ -976,7 +1126,7 @@ public class ASTNodes { * @param expressionIsExplicitlyTyped <code>true</code> iff the intended replacement for <code>expression</code> * is an explicitly typed lambda expression (JLS8 15.27.1) */ - public AmbiguousTargetMethodAnalyzer(ITypeBinding declaringType, IMethodBinding originalMethod, int argumentIndex, int argumentCount, boolean expressionIsExplicitlyTyped) { + public FunctionalInterfaceAmbiguousMethodAnalyzer(ITypeBinding declaringType, IMethodBinding originalMethod, int argumentIndex, int argumentCount, boolean expressionIsExplicitlyTyped) { fDeclaringType= declaringType; fOriginalMethod= originalMethod; fArgIndex= argumentIndex; @@ -1302,6 +1452,35 @@ public class ASTNodes { return current; } + /** + * Returns the same node after removing any parentheses around it. + * + * @param node the node around which parentheses must be removed + * @return the same node after removing any parentheses around it. If there are + * no parentheses around it then the exact same node is returned + */ + public static ASTNode getUnparenthesedExpression(ASTNode node) { + if (node instanceof Expression) { + return getUnparenthesedExpression((Expression) node); + } + return node; + } + + /** + * Returns the same expression after removing any parentheses around it. + * + * @param expression the expression around which parentheses must be removed + * @return the same expression after removing any parentheses around it If there + * are no parentheses around it then the exact same expression is + * returned + */ + public static Expression getUnparenthesedExpression(Expression expression) { + if (expression != null && expression.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION) { + return getUnparenthesedExpression(((ParenthesizedExpression) expression).getExpression()); + } + return expression; + } + /** * Returns <code>true</code> iff <code>parent</code> is a true ancestor of <code>node</code> * (i.e. returns <code>false</code> if <code>parent == node</code>). @@ -1577,6 +1756,7 @@ public class ASTNodes { return ((SimpleName) name).isDeclaration(); } } + /** * Returns whether the provided method invocation invokes a method with the * provided method signature. The method signature is compared against the @@ -1608,7 +1788,7 @@ public class ASTNodes { * @return true if the provided method invocation matches the provided method signature, false * otherwise */ - private static boolean usesGivenSignature(final IMethodBinding methodBinding, final String typeQualifiedName, final String methodName, + public static boolean usesGivenSignature(final IMethodBinding methodBinding, final String typeQualifiedName, final String methodName, final String... parameterTypesQualifiedNames) { // Let's do the fast checks first if (methodBinding == null || !methodName.equals(methodBinding.getName()) diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/BodyDeclarationRewrite.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/BodyDeclarationRewrite.java index 8f6d3a41eb..853483dd17 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/BodyDeclarationRewrite.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/BodyDeclarationRewrite.java @@ -31,9 +31,9 @@ import org.eclipse.jdt.internal.core.manipulation.MembersOrderPreferenceCacheCom /** * Rewrite helper for body declarations. - * + * * @see ASTNodes#getBodyDeclarationsProperty(ASTNode) - * + * * @since 1.10 */ public class BodyDeclarationRewrite { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/DimensionRewrite.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/DimensionRewrite.java index adf9904c26..bf172e95f9 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/DimensionRewrite.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/DimensionRewrite.java @@ -39,7 +39,7 @@ public class DimensionRewrite { /** * Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code> * and adds <code>extraDimensions</code> to it. - * + * * @param type the type to copy * @param extraDimensions the dimensions to add * @param rewrite the ASTRewrite with which to create new nodes @@ -50,7 +50,7 @@ public class DimensionRewrite { if (extraDimensions.isEmpty()) { return (Type) rewrite.createCopyTarget(type); } - + ArrayType result; if (type instanceof ArrayType) { ArrayType arrayType= (ArrayType) type; @@ -68,10 +68,10 @@ public class DimensionRewrite { /** * Returns {@link ASTRewrite#createCopyTarget(ASTNode) copies} of the given <code>dimensions</code>. - * + * * @param dimensions the dimensions to copy * @param rewrite the ASTRewrite with which to create new nodes - * + * * @return list of copy targets */ public static List<Dimension> copyDimensions(List<Dimension> dimensions, ASTRewrite rewrite) { @@ -84,7 +84,7 @@ public class DimensionRewrite { /** * Removes all children in <code>node</code>'s <code>childListProperty</code>. - * + * * @param node ASTNode * @param childListProperty child list property * @param rewrite rewrite that removes the nodes diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/GenericVisitor.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/GenericVisitor.java index 5f90c48bd1..48d3f13289 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/GenericVisitor.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/GenericVisitor.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * This is an implementation of an early-draft specification developed under the Java * Community Process (JCP) and is made available for testing and evaluation purposes * only. The code is not compatible with any specification of the JCP. @@ -47,7 +47,7 @@ public class GenericVisitor extends ASTVisitor { /** * Visits the given type-specific AST node. - * + * * @param node the AST note to visit * @return <code>true</code> if the children of this node should be visited, and * <code>false</code> if the children of this node should be skipped @@ -58,7 +58,7 @@ public class GenericVisitor extends ASTVisitor { /** * Visits the given type-specific AST node. - * + * * @param node the AST note to visit */ protected void endVisitNode(ASTNode node) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java index 225459aae6..6dbe17593c 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/HierarchicalASTVisitor.java @@ -644,7 +644,7 @@ public abstract class HierarchicalASTVisitor extends ASTVisitor { public void endVisit(StringLiteral node) { endVisit((Expression)node); } - + @Override public boolean visit(SuperFieldAccess node) { return visit((Expression)node); @@ -659,7 +659,7 @@ public abstract class HierarchicalASTVisitor extends ASTVisitor { public boolean visit(SuperMethodInvocation node) { return visit((Expression)node); } - + @Override public boolean visit(TextBlock node) { return visit((Expression)node); @@ -674,7 +674,7 @@ public abstract class HierarchicalASTVisitor extends ASTVisitor { public void endVisit(TextBlock node) { endVisit((Expression)node); } - + @Override public boolean visit(ThisExpression node) { return visit((Expression)node); @@ -771,12 +771,12 @@ public abstract class HierarchicalASTVisitor extends ASTVisitor { public boolean visit(ModuleDeclaration node) { return visit((ASTNode)node); } - + @Override public void endVisit(ModuleDeclaration node) { endVisit((ASTNode)node); } - + //---- Begin ModuleDirective Hierarchy ---------------------------------- public boolean visit(ModuleDirective node) { @@ -788,11 +788,11 @@ public abstract class HierarchicalASTVisitor extends ASTVisitor { } //---- Begin ModulePackageAccess Hierarchy ---------------------------------- - + public boolean visit(ModulePackageAccess node) { return visit((ModuleDirective)node); } - + public void endVisit(ModulePackageAccess node) { endVisit((ModuleDirective)node); } @@ -801,7 +801,7 @@ public abstract class HierarchicalASTVisitor extends ASTVisitor { public boolean visit(ExportsDirective node) { return visit((ModulePackageAccess)node); } - + @Override public void endVisit(ExportsDirective node) { endVisit((ModulePackageAccess)node); @@ -811,24 +811,24 @@ public abstract class HierarchicalASTVisitor extends ASTVisitor { public boolean visit(OpensDirective node) { return visit((ModulePackageAccess)node); } - + @Override public void endVisit(OpensDirective node) { endVisit((ModulePackageAccess)node); } - + //---- End ModulePackageAccess Hierarchy ------------------------------------ - + @Override public boolean visit(ProvidesDirective node) { return visit((ModuleDirective)node); } - + @Override public void endVisit(ProvidesDirective node) { endVisit((ModuleDirective)node); } - + @Override public boolean visit(RequiresDirective node) { return visit((ModuleDirective)node); @@ -843,24 +843,24 @@ public abstract class HierarchicalASTVisitor extends ASTVisitor { public boolean visit(UsesDirective node) { return visit((ModuleDirective)node); } - + @Override public void endVisit(UsesDirective node) { endVisit((ModuleDirective)node); } - + //---- End ModuleDirective Hierarchy ------------------------------------ - + @Override public boolean visit(ModuleModifier node) { return visit((ASTNode)node); } - + @Override public void endVisit(ModuleModifier node) { endVisit((ASTNode)node); } - + @Override public boolean visit(PackageDeclaration node) { return visit((ASTNode)node); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ModifierRewrite.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ModifierRewrite.java index c435de79ea..fe25957ca9 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ModifierRewrite.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ModifierRewrite.java @@ -97,7 +97,7 @@ public class ModifierRewrite { /** * Sets the given modifiers. Removes all other flags, but leaves annotations in place. - * + * * @param modifiers the modifiers to set * @param editGroup the edit group in which to collect the corresponding text edits, or * <code>null</code> if ungrouped @@ -110,7 +110,7 @@ public class ModifierRewrite { /** * Sets the included modifiers and removes the excluded modifiers. Does not touch other flags * and leaves annotations in place. - * + * * @param included the modifiers to set * @param excluded the modifiers to remove * @param editGroup the edit group in which to collect the corresponding text edits, or @@ -124,7 +124,7 @@ public class ModifierRewrite { /** * Sets the included visibility modifiers and removes existing visibility modifiers. Does not * touch other flags and leaves annotations in place. - * + * * @param visibilityFlags the new visibility modifiers * @param editGroup the edit group in which to collect the corresponding text edits, or * <code>null</code> if ungrouped @@ -137,7 +137,7 @@ public class ModifierRewrite { public void copyAllModifiers(ASTNode otherDecl, TextEditGroup editGroup) { copyAllModifiers(otherDecl, editGroup, false); } - + public void copyAllModifiers(ASTNode otherDecl, TextEditGroup editGroup, boolean copyIndividually) { ListRewrite modifierList= evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl); List<IExtendedModifier> originalList= modifierList.getOriginalList(); @@ -176,7 +176,7 @@ public class ModifierRewrite { /** * Sets the given modifiers and removes all other modifiers that match the consideredFlags mask. * Does not touch other flags and leaves annotations in place. - * + * * @param modifiers the modifiers to set * @param consideredFlags mask of modifiers to consider * @param editGroup the edit group in which to collect the corresponding text edits, or diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ReplaceRewrite.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ReplaceRewrite.java index 2a7a886c5f..688453292b 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ReplaceRewrite.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ReplaceRewrite.java @@ -28,7 +28,7 @@ import org.eclipse.jdt.core.dom.rewrite.ListRewrite; /** * Rewrite helper for situations where one node can be replaced by many new nodes. - * + * * see JDTUIHelperClasses */ public class ReplaceRewrite { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java index 660b082e18..f5d547600a 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/ScopeAnalyzer.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -762,7 +762,7 @@ public class ScopeAnalyzer { public boolean visit(FieldDeclaration node) { return !fBreak && isInside(node); } - + @Override public boolean visit(Expression node) { return !fBreak && isInside(node); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/StatementRewrite.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/StatementRewrite.java index 44b0d8451d..31d1c30ebd 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/StatementRewrite.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/StatementRewrite.java @@ -28,7 +28,7 @@ import org.eclipse.jdt.core.dom.rewrite.ListRewrite; /** * Rewrite helper for {@link Statement}s. Ensures that * the replacement nodes are enclosed in a Block if necessary. - * + * * see JDTUIHelperClasses */ public class StatementRewrite extends ReplaceRewrite { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/TypeRules.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/TypeRules.java index 498fca18b0..e2cf86370a 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/TypeRules.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/TypeRules.java @@ -32,7 +32,7 @@ public class TypeRules { /** * Tests if two types are assign compatible. Void types are never compatible. - * + * * @param typeToAssign The binding of the type to assign * @param definedType The type of the object that is assigned * @return <code>true</code> iff definedType = typeToAssign is a valid assignment diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/VariableDeclarationRewrite.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/VariableDeclarationRewrite.java index aab8d77e52..c68c11bfb3 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/VariableDeclarationRewrite.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/dom/VariableDeclarationRewrite.java @@ -43,7 +43,7 @@ import org.eclipse.jdt.core.dom.rewrite.ListRewrite; /** * Rewrite helper for variable declarations. - * + * * see JDTUIHelperClasses */ public class VariableDeclarationRewrite { @@ -64,15 +64,15 @@ public class VariableDeclarationRewrite { /* * Problem: Same declarationNode can be the subject of multiple calls to this method. * For the 2nd++ calls, the original declarationNode has already been rewritten, and this has to be taken into account. - * + * * Assumption: * - Modifiers for each VariableDeclarationFragment are modified at most once. - * + * * Solution: * - Maintain a map from original VariableDeclarationFragments to their new FieldDeclaration. * - Original modifiers in declarationNode belong to the first fragment. * - When a later fragment needs different modifiers, we create a new FieldDeclaration and move all successive fragments into that declaration - * - When a fragment has been moved to a new declaration, make sure we don't create a new move target again, but instead use the already created one + * - When a fragment has been moved to a new declaration, make sure we don't create a new move target again, but instead use the already created one */ List<VariableDeclarationFragment> fragments= declarationNode.fragments(); Iterator<VariableDeclarationFragment> iter= fragments.iterator(); @@ -95,7 +95,7 @@ public class VariableDeclarationRewrite { ListRewrite fragmentsRewrite= null; while (iter.hasNext()) { VariableDeclarationFragment currentFragment= iter.next(); - + @SuppressWarnings("unchecked") Map<VariableDeclarationFragment, MovedFragment> lookup= (Map<VariableDeclarationFragment, MovedFragment>) rewrite.getProperty(MovedFragment.class.getName()); if (lookup == null) { @@ -103,14 +103,14 @@ public class VariableDeclarationRewrite { rewrite.setProperty(MovedFragment.class.getName(), lookup); } MovedFragment currentMovedFragment= lookup.get(currentFragment); - + boolean changeLast= fragmentsToChange.contains(lastFragment); boolean changeCurrent= fragmentsToChange.contains(currentFragment); if (changeLast != changeCurrent || lookup.containsKey(lastFragment)) { ModifierRewrite modifierRewrite= null; if (currentMovedFragment != null) { // Current fragment has already been moved. - + if (currentMovedFragment.fUsesOriginalModifiers) { // Need to put in the right modifiers (removing any existing ones). modifierRewrite= ModifierRewrite.create(rewrite, currentMovedFragment.fDeclaration); @@ -123,11 +123,11 @@ public class VariableDeclarationRewrite { } } // otherwise, don't need to touch the modifiers, so leave modifierRewrite null - + } else { // need to split an existing field declaration VariableDeclarationFragment moveTarget; moveTarget= (VariableDeclarationFragment)rewrite.createMoveTarget(currentFragment); - + FieldDeclaration newStatement= (FieldDeclaration)ast.createInstance(FieldDeclaration.class); rewrite.getListRewrite(newStatement, FieldDeclaration.FRAGMENTS_PROPERTY).insertLast(moveTarget, group); lookup.put(currentFragment, new MovedFragment(moveTarget, newStatement, !changeCurrent)); @@ -140,7 +140,7 @@ public class VariableDeclarationRewrite { fragmentsRewrite= rewrite.getListRewrite(newStatement, FieldDeclaration.FRAGMENTS_PROPERTY); lastStatement= newStatement; } - + if (modifierRewrite != null) { if (changeCurrent) { int newModifiers= (declarationNode.getModifiers() & ~excludedModifiers) | includedModifiers; @@ -150,7 +150,7 @@ public class VariableDeclarationRewrite { modifierRewrite.setModifiers(newModifiers, Modifier.NONE, group); } } - + } else if (fragmentsRewrite != null) { VariableDeclarationFragment fragment0; boolean usesOriginalModifiers= true; @@ -167,12 +167,12 @@ public class VariableDeclarationRewrite { lastFragment= currentFragment; } } - + private static class MovedFragment { final VariableDeclarationFragment fMoveTarget; final ASTNode fDeclaration; boolean fUsesOriginalModifiers; - + public MovedFragment(VariableDeclarationFragment moveTarget, ASTNode declaration, boolean usesOriginalModifiers) { fMoveTarget= moveTarget; fDeclaration= declaration; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/AbstractSerialVersionOperationCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/AbstractSerialVersionOperationCore.java index 4cfef81ed4..0f26134e6d 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/AbstractSerialVersionOperationCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/AbstractSerialVersionOperationCore.java @@ -69,7 +69,7 @@ public abstract class AbstractSerialVersionOperationCore extends CompilationUnit /** * Adds an initializer to the specified variable declaration fragment. - * + * * @param fragment the variable declaration fragment to add an initializer * @param declarationNode the declartion node * @return false if no id could be calculated diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java index 8757d89a8d..f2a17dc5b2 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -679,6 +679,19 @@ public class CleanUpConstants { public static final String USE_ANONYMOUS_CLASS_CREATION= "cleanup.use_anonymous_class_creation"; //$NON-NLS-1$ /** + * Removes useless parenthesis, return statements and brackets from lambda expressions and + * method references. + * <p> + * Possible values: {TRUE, FALSE} + * <p> + * + * @see CleanUpOptionsCore#TRUE + * @see CleanUpOptionsCore#FALSE + * @since 4.15 + */ + public static final String SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF= "cleanup.simplify_lambda_expression_and_method_ref"; //$NON-NLS-1$ + + /** * Adds type parameters to raw type references. * <p> * Example: diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CodeStyleFixCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CodeStyleFixCore.java index f78ac8494b..5444854801 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CodeStyleFixCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/CodeStyleFixCore.java @@ -281,7 +281,7 @@ public class CodeStyleFixCore extends CompilationUnitRewriteOperationsFixCore { //the field. It's possible that the inner type inherits the same field. We must not remove //the qualifier in this case. return true; - + ITypeBinding enclosingTypeBinding= Bindings.getBindingOfParentType(node); if (enclosingTypeBinding == null || Bindings.isSuperType(variablesDeclaringClass, enclosingTypeBinding)) //We have a reference to a field of an outer type, and this type inherited @@ -474,7 +474,7 @@ public class CodeStyleFixCore extends CompilationUnitRewriteOperationsFixCore { Statement statement= ASTResolving.findParentStatement(qualifier); if (statement == null) return; - + ASTRewrite astRewrite= cuRewrite.getASTRewrite(); AST ast= cuRewrite.getAST(); @@ -710,7 +710,7 @@ public class CodeStyleFixCore extends CompilationUnitRewriteOperationsFixCore { if (accessBinding != null && qualifier != null) { if (conservative && ASTResolving.findParentStatement(qualifier) == null) return null; - + ToStaticAccessOperation declaring= null; ITypeBinding declaringTypeBinding= getDeclaringTypeBinding(accessBinding); if (declaringTypeBinding != null) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.java index e14ab864f1..3b82ce798d 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/FixMessages.java @@ -152,7 +152,7 @@ public final class FixMessages extends NLS { public static String TypeParametersFix_insert_inferred_type_arguments_name; public static String TypeParametersFix_remove_redundant_type_arguments_description; public static String TypeParametersFix_remove_redundant_type_arguments_name; - + public static String TypeAnnotationFix_move; public static String TypeAnnotationFix_remove; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/ICleanUpCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/ICleanUpCore.java index 67f8fe5e8a..bd073dcc47 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/ICleanUpCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/ICleanUpCore.java @@ -43,14 +43,14 @@ import org.eclipse.jdt.core.manipulation.ICleanUpFixCore; * <p> * At the end {@link #checkPostConditions(IProgressMonitor)} is called. * </p> - * + * * @since 3.5 */ public interface ICleanUpCore { /** * Sets the options that will be used. - * + * * @param options the options to use */ void setOptions(CleanUpOptionsCore options); @@ -60,7 +60,7 @@ public interface ICleanUpCore { * <p> * <strong>Note:</strong> This method must only be called after the options have been set. * </p> - * + * * @return descriptions an array of {@linkplain String strings} or <code>null</code> */ String[] getStepDescriptions(); @@ -70,7 +70,7 @@ public interface ICleanUpCore { * <p> * <strong>Note:</strong> This method must only be called after the options have been set. * </p> - * + * * @return the requirements used for {@link #createFixCore(CleanUpContextCore)} to work */ CleanUpRequirementsCore getRequirementsCore(); @@ -79,7 +79,7 @@ public interface ICleanUpCore { * After call to checkPreConditions clients will start creating fixes for * <code>compilationUnits</code> in <code>project</code> unless the result of checkPreConditions * contains a fatal error - * + * * @param project the project to clean up * @param compilationUnits an array of compilation units to clean up, all member of <code>project</code> * @param monitor the monitor to show progress @@ -91,7 +91,7 @@ public interface ICleanUpCore { /** * Create an <code>ICleanUpFixCore</code> which fixes all problems in <code>context</code> or * <code>null</code> if nothing to fix. - * + * * @param context a context containing all information requested by {@link #getRequirementsCore()} * @return the fix for the problems or <code>null</code> if nothing to fix * @throws CoreException if an unexpected error occurred @@ -100,7 +100,7 @@ public interface ICleanUpCore { /** * Called when done cleaning up. - * + * * @param monitor the monitor to show progress * @return the result of the postcondition check, not null * @throws CoreException if an unexpected error occurred diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFixCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFixCore.java index 98d3ab05ba..62cdb5d07a 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFixCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/LambdaExpressionsFixCore.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2019 IBM Corporation and others. + * Copyright (c) 2013, 2020 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 @@ -39,10 +39,13 @@ import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.Expression; import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.eclipse.jdt.core.dom.FieldAccess; +import org.eclipse.jdt.core.dom.FieldDeclaration; import org.eclipse.jdt.core.dom.IAnnotationBinding; import org.eclipse.jdt.core.dom.IBinding; import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.LambdaExpression; import org.eclipse.jdt.core.dom.MarkerAnnotation; import org.eclipse.jdt.core.dom.MethodDeclaration; @@ -50,6 +53,7 @@ import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.core.dom.NormalAnnotation; +import org.eclipse.jdt.core.dom.QualifiedName; import org.eclipse.jdt.core.dom.ReturnStatement; import org.eclipse.jdt.core.dom.SimpleName; import org.eclipse.jdt.core.dom.SingleMemberAnnotation; @@ -66,6 +70,7 @@ import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.TypeLocation; import org.eclipse.jdt.core.manipulation.ICleanUpFixCore; +import org.eclipse.jdt.core.util.IModifierConstants; import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving; import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; @@ -200,6 +205,109 @@ public class LambdaExpressionsFixCore extends CompilationUnitRewriteOperationsFi } } + public static final class FinalFieldAccessInFieldDeclarationFinder extends HierarchicalASTVisitor { + + private MethodDeclaration fMethodDeclaration; + private ASTNode fFieldDeclaration; + static boolean hasReference(MethodDeclaration node) { + try { + FinalFieldAccessInFieldDeclarationFinder finder= new FinalFieldAccessInFieldDeclarationFinder(); + ClassInstanceCreation cic= (ClassInstanceCreation) node.getParent().getParent(); + cic.getType().resolveBinding(); + finder.fMethodDeclaration= node; + finder.fFieldDeclaration= finder.findFieldDeclaration(node); + if (finder.fFieldDeclaration == null) { + return false; + } + node.accept(finder); + } catch (AbortSearchException e) { + return true; + } + return false; + } + + private ASTNode findFieldDeclaration(ASTNode node) { + while (node != null) { + if (node instanceof FieldDeclaration) { + return node; + } + if (node instanceof AbstractTypeDeclaration) { + return null; + } + node= node.getParent(); + } + return null; + } + + @Override + public boolean visit(AnonymousClassDeclaration node) { + return false; + } + + @Override + public boolean visit(BodyDeclaration node) { + return false; + } + + @Override + public boolean visit(MethodDeclaration node) { + return node == fMethodDeclaration; + } + + private void checkForUninitializedFinalReference(IBinding binding) { + if (binding instanceof IVariableBinding) { + int modifiers= ((IVariableBinding)binding).getModifiers(); + if ((modifiers & IModifierConstants.ACC_FINAL) == IModifierConstants.ACC_FINAL) { + if (((IVariableBinding) binding).isField()) { + ASTNode decl= ((CompilationUnit)fMethodDeclaration.getRoot()).findDeclaringNode(binding); + if (decl instanceof VariableDeclaration && ((VariableDeclaration)decl).getInitializer() == null) { + throw new AbortSearchException(); + } + } + } + } + } + + @Override + public boolean visit(SuperFieldAccess node) { + IVariableBinding binding= node.resolveFieldBinding(); + if (binding == null) { + return true; + } + IVariableBinding decl= binding.getVariableDeclaration(); + checkForUninitializedFinalReference(decl); + return true; + } + + @Override + public boolean visit(SimpleName node) { + node.getParent(); + IBinding binding= node.resolveBinding(); + checkForUninitializedFinalReference(binding); + return true; + } + + @Override + public boolean visit(QualifiedName node) { + node.getParent(); + IBinding binding= node.resolveBinding(); + checkForUninitializedFinalReference(binding); + return true; + } + + @Override + public boolean visit(FieldAccess node) { + IVariableBinding binding= node.resolveFieldBinding(); + if (binding == null) { + return true; + } + IVariableBinding decl= binding.getVariableDeclaration(); + checkForUninitializedFinalReference(decl); + return true; + } + + } + public static final class SuperThisQualifier extends HierarchicalASTVisitor { private ITypeBinding fQualifierTypeBinding; @@ -697,6 +805,13 @@ public class LambdaExpressionsFixCore extends CompilationUnitRewriteOperationsFi return false; } + // lambda cannot access this and so we should avoid lambda conversion + // when anonymous class is used to initialize field and refers to + // final fields that may or may not be initialized + if (FinalFieldAccessInFieldDeclarationFinder.hasReference(methodDecl)) { + return false; + } + if (ASTNodes.getTargetType(node) == null) { return false; } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/LinkedProposalPositionGroupCore.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/LinkedProposalPositionGroupCore.java index 59cde73207..6b0364480a 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/LinkedProposalPositionGroupCore.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/fix/LinkedProposalPositionGroupCore.java @@ -110,7 +110,7 @@ public class LinkedProposalPositionGroupCore { /** * A position that contains all of the given tracked node positions. - * + * * @since 3.7 */ public static class TrackedNodesPosition extends PositionInformation { @@ -119,7 +119,7 @@ public class LinkedProposalPositionGroupCore { /** * A position that contains all of the given tracked node positions. - * + * * @param pos the positions */ public TrackedNodesPosition(Collection<ITrackedNodePosition> pos) { @@ -154,7 +154,7 @@ public class LinkedProposalPositionGroupCore { /** * A position for the start of the given tracked node position. - * + * * @since 3.7 */ public static class StartPositionInformation extends PositionInformation { @@ -163,7 +163,7 @@ public class LinkedProposalPositionGroupCore { /** * A position for the start of the given tracked node position. - * + * * @param pos the position */ public StartPositionInformation(ITrackedNodePosition pos) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java index 65b19314c6..e02a421584 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/Checks.java @@ -211,7 +211,7 @@ public class Checks { /** * Returns OK status if the new name is OK, i.e. when no file with that name exists. * The name of the given CU is not OK. - * + * * @param cu CU to rename * @param newBareName the new name of the CU (without extension) * @return the status: FATAL if the CU already exists, OK if OK @@ -879,7 +879,7 @@ public class Checks { } if (e instanceof Annotation) return NOT_RVALUE_MISC; - + ITypeBinding tb= e.resolveTypeBinding(); boolean guessingRequired= false; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java index a750137f97..a107d00dfd 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/RefactoringCoreMessages.java @@ -655,7 +655,7 @@ public final class RefactoringCoreMessages extends NLS { public static String ExtractTempRefactoring_convention; public static String ExtractTempRefactoring_declare_final; - + public static String ExtractTempRefactoring_declare_var_type; public static String ExtractTempRefactoring_declare_local_variable; @@ -1353,7 +1353,7 @@ public final class RefactoringCoreMessages extends NLS { public static String MoveMembersRefactoring_only_public_static; public static String MoveMembersRefactoring_only_public_static_18; - + public static String MoveMembersRefactoring_read_only; public static String MoveMembersRefactoring_referenceUpdate; @@ -2310,6 +2310,12 @@ public final class RefactoringCoreMessages extends NLS { public static String SurroundWithTryCatchRefactoring_notMultipleexceptions; + public static String SurroundWithTryWithResourcesRefactoring_name; + + public static String SurroundWithTryWithResourcesRefactoring_notAutoclosable; + + public static String SurroundWithTryWithResourcesRefactoring_notAutoclosableNoExceptions; + public static String TargetProvider_cannot_local_method_in_binary; public static String TargetProvider_inaccurate_match; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/DynamicValidationStateChange.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/DynamicValidationStateChange.java index f96b4ef166..ea067dae84 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/DynamicValidationStateChange.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/changes/DynamicValidationStateChange.java @@ -42,7 +42,7 @@ public class DynamicValidationStateChange extends CompositeChange implements Wor private ISchedulingRule fSchedulingRule; private static final long DO_NOT_EXPIRE= -1; - + // 30 minutes private static final long LIFE_TIME= 30 * 60 * 1000; @@ -71,7 +71,7 @@ public class DynamicValidationStateChange extends CompositeChange implements Wor fTimeStamp= 0; } } - + @Override public void initializeValidationData(IProgressMonitor pm) { super.initializeValidationData(pm); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java index bcdfbc2878..954e803660 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/CallInliner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -23,6 +23,7 @@ * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=38093) * Nikolay Metchev <nikolaymetchev@gmail.com> - Anonymous class using final parameter breaks method inlining - https://bugs.eclipse.org/269401 * Microsoft Corporation - copied to jdt.core.manipulation + * Pierre-Yves B. <pyvesdev@gmail.com> - [inline] Inlining a local variable leads to ambiguity with overloaded methods - https://bugs.eclipse.org/434747 *******************************************************************************/ package org.eclipse.jdt.internal.corext.refactoring.code; @@ -95,18 +96,15 @@ import org.eclipse.jdt.internal.corext.CorextCore; import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory; import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.dom.Bindings; import org.eclipse.jdt.internal.corext.dom.CodeScopeBuilder; import org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor; import org.eclipse.jdt.internal.corext.dom.LocalVariableIndex; import org.eclipse.jdt.internal.corext.dom.Selection; -import org.eclipse.jdt.internal.corext.dom.TypeBindingVisitor; import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; import org.eclipse.jdt.internal.corext.refactoring.base.RefactoringStatusCodes; import org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowContext; import org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowInfo; import org.eclipse.jdt.internal.corext.refactoring.code.flow.InputFlowAnalyzer; -import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType; import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeEnvironment; import org.eclipse.jdt.internal.corext.refactoring.util.JavaStatusContext; import org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer; @@ -198,52 +196,6 @@ public class CallInliner { } } - private static class AmbiguousMethodAnalyzer implements TypeBindingVisitor { - private TypeEnvironment fTypeEnvironment; - private TType[] fTypes; - private IMethodBinding fOriginal; - - public AmbiguousMethodAnalyzer(TypeEnvironment typeEnvironment, IMethodBinding original, TType[] types) { - fTypeEnvironment= typeEnvironment; - fOriginal= original; - fTypes= types; - } - @Override - public boolean visit(ITypeBinding node) { - IMethodBinding[] methods= node.getDeclaredMethods(); - for (int i= 0; i < methods.length; i++) { - IMethodBinding candidate= methods[i]; - if (candidate == fOriginal) { - continue; - } - if (fOriginal.getName().equals(candidate.getName())) { - if (canImplicitlyCall(candidate)) { - return false; - } - } - } - return true; - } - /** - * Returns <code>true</code> if the method can be called without explicit casts; - * otherwise <code>false</code>. - * @param candidate the method to test - * @return <code>true</code> if the method can be called without explicit casts - */ - private boolean canImplicitlyCall(IMethodBinding candidate) { - ITypeBinding[] parameters= candidate.getParameterTypes(); - if (parameters.length != fTypes.length) { - return false; - } - for (int i= 0; i < parameters.length; i++) { - if (!fTypes[i].canAssignTo(fTypeEnvironment.create(parameters[i]))) { - return false; - } - } - return true; - } - } - public CallInliner(ICompilationUnit unit, CompilationUnit targetAstRoot, SourceProvider provider) throws CoreException { super(); fCUnit= unit; @@ -726,29 +678,9 @@ public class CallInliner { JavaStatusContext.create(fCUnit, methodInvocation)); return false; } - ITypeBinding[] parameters= method.getParameterTypes(); - int argumentIndex= methodInvocation.arguments().indexOf(fInvocation); ITypeBinding parameterType= returnExprs.get(0).resolveTypeBinding(); - if (method.isVarargs() && argumentIndex >= parameters.length - 1) { - argumentIndex= parameters.length - 1; - parameterType= parameterType.createArrayType(1); - } - parameters[argumentIndex]= parameterType; - - ITypeBinding type= ASTNodes.getReceiverTypeBinding(methodInvocation); - TypeBindingVisitor visitor= new AmbiguousMethodAnalyzer( - fTypeEnvironment, method, fTypeEnvironment.create(parameters)); - if(!visitor.visit(type)) { - return true; - } else if (type.isInterface()) { - return !Bindings.visitInterfaces(type, visitor); - } else if (Modifier.isAbstract(type.getModifiers())) { - return !Bindings.visitHierarchy(type, visitor); - } else { - // it is not needed to visit interfaces if receiver is a concrete class - return !Bindings.visitSuperclasses(type, visitor); - } + return ASTNodes.isTargetAmbiguous((Expression) fTargetNode, parameterType); } else { ITypeBinding explicitCast= ASTNodes.getExplicitCast(returnExprs.get(0), (Expression)fTargetNode); return explicitCast != null; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java index 6b962dd293..404bf84bed 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineConstantRefactoring.java @@ -279,7 +279,7 @@ public class InlineConstantRefactoring extends Refactoring { fNewLocationCuRewrite.getImportRemover().registerAddedImports(typeArgument); typeArgsRewrite.insertLast(typeArgument, null); } - + if (invocation instanceof MethodInvocation) { MethodInvocation methodInvocation= (MethodInvocation) invocation; Expression expression= methodInvocation.getExpression(); @@ -514,7 +514,7 @@ public class InlineConstantRefactoring extends Refactoring { return; TextEditGroup msg= fCuRewrite.createGroupDescription(RefactoringCoreMessages.InlineConstantRefactoring_Inline); - + Expression newReference; boolean isStringPlaceholder= false; @@ -532,7 +532,7 @@ public class InlineConstantRefactoring extends Refactoring { ImportRewriteContext context= new ContextSensitiveImportRewriteContext(reference, fCuRewrite.getImportRewrite()); cast.setType(fCuRewrite.getImportRewrite().addImport(explicitCast, ast, context, TypeLocation.CAST)); newReference= cast; - + } else if (fInitializer instanceof ArrayInitializer) { ArrayCreation arrayCreation= ast.newArrayCreation(); ArrayType arrayType= (ArrayType) ASTNodeFactory.newType(ast, fOriginalDeclaration); @@ -547,7 +547,7 @@ public class InlineConstantRefactoring extends Refactoring { ImportRewriteContext context= new ContextSensitiveImportRewriteContext(reference, fCuRewrite.getImportRewrite()); fCuRewrite.getImportRewrite().addImport(typeToAddToImport, context); fCuRewrite.getImportRemover().registerAddedImport(typeToAddToImport.getName()); - + } else { newReference= (Expression) fCuRewrite.getASTRewrite().createStringPlaceholder(modifiedInitializer, reference.getNodeType()); isStringPlaceholder= true; @@ -652,7 +652,7 @@ public class InlineConstantRefactoring extends Refactoring { /** * Creates a new inline constant refactoring. - * + * * @param unit the compilation unit, or <code>null</code> if invoked by scripting * @param node the compilation unit node, or <code>null</code> if invoked by scripting * @param selectionStart the start of the selection diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java index 9657219079..31a0ddfe54 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java @@ -390,7 +390,7 @@ public class InlineTempRefactoring extends Refactoring { } } } - + Expression copy= (Expression) rewrite.getASTRewrite().createCopyTarget(initializer); AST ast= rewrite.getAST(); if (NecessaryParenthesesChecker.needsParentheses(initializer, reference.getParent(), reference.getLocationInParent())) { @@ -398,7 +398,7 @@ public class InlineTempRefactoring extends Refactoring { parenthesized.setExpression(copy); copy= parenthesized; } - + ITypeBinding explicitCast= ASTNodes.getExplicitCast(initializer, reference); if (explicitCast != null) { CastExpression cast= ast.newCastExpression(); @@ -411,7 +411,7 @@ public class InlineTempRefactoring extends Refactoring { ImportRewriteContext context= new ContextSensitiveImportRewriteContext(reference, rewrite.getImportRewrite()); cast.setType(rewrite.getImportRewrite().addImport(explicitCast, ast, context, TypeLocation.CAST)); copy= cast; - + } else if (initializer instanceof ArrayInitializer && ASTNodes.getDimensions(varDecl) > 0) { ArrayType newType= (ArrayType) ASTNodeFactory.newType(ast, varDecl); @@ -426,12 +426,12 @@ public class InlineTempRefactoring extends Refactoring { private String createParameterizedInvocation(Expression invocation, ITypeBinding[] typeArguments, CompilationUnitRewrite cuRewrite) throws JavaModelException { ASTRewrite rewrite= ASTRewrite.create(invocation.getAST()); ListRewrite typeArgsRewrite= Invocations.getInferredTypeArgumentsRewrite(rewrite, invocation); - + for (ITypeBinding typeArgument : typeArguments) { Type typeArgumentNode = cuRewrite.getImportRewrite().addImport(typeArgument, cuRewrite.getAST()); typeArgsRewrite.insertLast(typeArgumentNode, null); } - + if (invocation instanceof MethodInvocation) { MethodInvocation methodInvocation= (MethodInvocation) invocation; Expression expression= methodInvocation.getExpression(); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/Invocations.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/Invocations.java index 03cd707c82..c46c313b3e 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/Invocations.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/Invocations.java @@ -42,17 +42,17 @@ public class Invocations { return ((MethodInvocation)invocation).arguments(); case ASTNode.SUPER_METHOD_INVOCATION: return ((SuperMethodInvocation)invocation).arguments(); - + case ASTNode.CONSTRUCTOR_INVOCATION: return ((ConstructorInvocation)invocation).arguments(); case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: return ((SuperConstructorInvocation)invocation).arguments(); - + case ASTNode.CLASS_INSTANCE_CREATION: return ((ClassInstanceCreation)invocation).arguments(); case ASTNode.ENUM_CONSTANT_DECLARATION: return ((EnumConstantDeclaration)invocation).arguments(); - + default: throw new IllegalArgumentException(invocation.toString()); } @@ -64,39 +64,39 @@ public class Invocations { return MethodInvocation.ARGUMENTS_PROPERTY; case ASTNode.SUPER_METHOD_INVOCATION: return SuperMethodInvocation.ARGUMENTS_PROPERTY; - + case ASTNode.CONSTRUCTOR_INVOCATION: return ConstructorInvocation.ARGUMENTS_PROPERTY; case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: return SuperConstructorInvocation.ARGUMENTS_PROPERTY; - + case ASTNode.CLASS_INSTANCE_CREATION: return ClassInstanceCreation.ARGUMENTS_PROPERTY; case ASTNode.ENUM_CONSTANT_DECLARATION: return EnumConstantDeclaration.ARGUMENTS_PROPERTY; - + default: throw new IllegalArgumentException(invocation.toString()); } } - + public static Expression getExpression(ASTNode invocation) { switch (invocation.getNodeType()) { case ASTNode.METHOD_INVOCATION: return ((MethodInvocation)invocation).getExpression(); case ASTNode.SUPER_METHOD_INVOCATION: return null; - + case ASTNode.CONSTRUCTOR_INVOCATION: return null; case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: return ((SuperConstructorInvocation)invocation).getExpression(); - + case ASTNode.CLASS_INSTANCE_CREATION: return ((ClassInstanceCreation)invocation).getExpression(); case ASTNode.ENUM_CONSTANT_DECLARATION: return null; - + default: throw new IllegalArgumentException(invocation.toString()); } @@ -107,19 +107,19 @@ public class Invocations { return type == ASTNode.METHOD_INVOCATION || type == ASTNode.SUPER_METHOD_INVOCATION || type == ASTNode.CONSTRUCTOR_INVOCATION; } - + public static boolean isInvocationWithArguments(ASTNode node) { switch (node.getNodeType()) { case ASTNode.METHOD_INVOCATION: case ASTNode.SUPER_METHOD_INVOCATION: - + case ASTNode.CONSTRUCTOR_INVOCATION: case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: - + case ASTNode.CLASS_INSTANCE_CREATION: case ASTNode.ENUM_CONSTANT_DECLARATION: return true; - + default: return false; } @@ -131,17 +131,17 @@ public class Invocations { return ((MethodInvocation)invocation).resolveMethodBinding(); case ASTNode.SUPER_METHOD_INVOCATION: return ((SuperMethodInvocation)invocation).resolveMethodBinding(); - + case ASTNode.CONSTRUCTOR_INVOCATION: return ((ConstructorInvocation)invocation).resolveConstructorBinding(); case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: return ((SuperConstructorInvocation)invocation).resolveConstructorBinding(); - + case ASTNode.CLASS_INSTANCE_CREATION: return ((ClassInstanceCreation)invocation).resolveConstructorBinding(); case ASTNode.ENUM_CONSTANT_DECLARATION: return ((EnumConstantDeclaration)invocation).resolveConstructorBinding(); - + default: throw new IllegalArgumentException(invocation.toString()); } @@ -150,7 +150,7 @@ public class Invocations { public static boolean isResolvedTypeInferredFromExpectedType(Expression invocation) { if (invocation == null) return false; - + switch (invocation.getNodeType()) { case ASTNode.METHOD_INVOCATION: return ((MethodInvocation) invocation).isResolvedTypeInferredFromExpectedType(); @@ -158,12 +158,12 @@ public class Invocations { return ((SuperMethodInvocation) invocation).isResolvedTypeInferredFromExpectedType(); case ASTNode.CLASS_INSTANCE_CREATION: return ((ClassInstanceCreation) invocation).isResolvedTypeInferredFromExpectedType(); - + default: return false; } } - + public static ListRewrite getInferredTypeArgumentsRewrite(ASTRewrite rewrite, Expression invocation) { switch (invocation.getNodeType()) { case ASTNode.METHOD_INVOCATION: @@ -173,7 +173,7 @@ public class Invocations { case ASTNode.CLASS_INSTANCE_CREATION: Type type= ((ClassInstanceCreation) invocation).getType(); return rewrite.getListRewrite(type, ParameterizedType.TYPE_ARGUMENTS_PROPERTY); - + default: throw new IllegalArgumentException(invocation.toString()); } @@ -192,7 +192,7 @@ public class Invocations { Type type= ((ClassInstanceCreation) invocation).getType(); ITypeBinding typeBinding= type.resolveBinding(); return typeBinding == null ? null : typeBinding.getTypeArguments(); - + default: throw new IllegalArgumentException(invocation.toString()); } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/ParameterData.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/ParameterData.java index e55d04b0ca..cdeba6ad8c 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/ParameterData.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/ParameterData.java @@ -65,7 +65,7 @@ import org.eclipse.jdt.internal.corext.refactoring.code.flow.FlowInfo; public boolean isUnused() { return fAccessMode == FlowInfo.UNUSED; } - + public boolean isFinal() { return Modifier.isFinal(fDeclaration.getModifiers()); } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java index e62c7bbbc4..981d6e7768 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/PromoteTempToFieldRefactoring.java @@ -344,7 +344,7 @@ public class PromoteTempToFieldRefactoring extends Refactoring { ASTNode declaringType= ASTResolving.findParentType(fTempDeclarationNode); if (declaringType instanceof TypeDeclaration && ((TypeDeclaration) declaringType).isInterface()) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.PromoteTempToFieldRefactoring_interface_methods); - + result.merge(checkTempTypeForLocalTypeUsage()); if (result.hasFatalError()) return result; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowAnalyzer.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowAnalyzer.java index 1bd59c81d4..be8bf82e1a 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowAnalyzer.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowAnalyzer.java @@ -387,7 +387,7 @@ abstract class FlowAnalyzer extends GenericVisitor { protected void endVisit(SwitchExpression node, SwitchData data) { preEndVisit(node, node.getExpression(), data); } - + private void preEndVisit(ASTNode node, Expression expression, SwitchData data) { SwitchFlowInfo switchFlowInfo= createSwitch(); setFlowInfo(node, switchFlowInfo); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowInfo.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowInfo.java index c1343c8955..85df34603c 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowInfo.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/FlowInfo.java @@ -271,7 +271,7 @@ public abstract class FlowInfo { /** * Checks whether the given local variable binding has the given access * mode. - * + * * @param context the flow context used during flow analysis * @param local local variable of interest * @param mode the access mode of the local variable diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/TryFlowInfo.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/TryFlowInfo.java index dcdf0b6d65..ad7685a58c 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/TryFlowInfo.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/code/flow/TryFlowInfo.java @@ -23,7 +23,7 @@ class TryFlowInfo extends FlowInfo { public void mergeResources(FlowInfo info, FlowContext context) { if (info == null) return; - + mergeSequential(info, context); } diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSElement.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSElement.java index 31bdae8c52..49097b50e3 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSElement.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSElement.java @@ -65,7 +65,7 @@ public class NLSElement { /** * Sets the actual string value. - * + * * @param value the value */ public void setValue(String value) { @@ -74,7 +74,7 @@ public class NLSElement { /** * Sets the tag position if one is associated with the NLS element. - * + * * @param start the start offset * @param length the length */ @@ -85,7 +85,7 @@ public class NLSElement { /** * Returns the tag position for this element. The method can return <code>null</code>. In this * case no tag has been found for this NLS element. - * + * * @return the new tag region region */ public Region getTagPosition() { @@ -94,7 +94,7 @@ public class NLSElement { /** * Returns whether this element has an associated $NON-NLS-*$ tag. - * + * * @return <code>true</code> if the NLS element has an associated $NON-NLS-*$ tag */ public boolean hasTag() { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSLine.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSLine.java index b06adb2e7e..272ac9a8bf 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSLine.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSLine.java @@ -38,7 +38,7 @@ public class NLSLine { /** * Adds a NLS element to this line. - * + * * @param element the NLS element */ public void add(NLSElement element) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSUtil.java index 82794d379f..a6ef0fb9a4 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSUtil.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/nls/NLSUtil.java @@ -83,7 +83,7 @@ public class NLSUtil { /** * Creates and returns an NLS tag edit for a string that is at the specified position in a * compilation unit. - * + * * @param cu the compilation unit * @param position position of the string * @return the edit, or <code>null</code> if the string is already NLSed or the edit could not @@ -107,7 +107,7 @@ public class NLSUtil { /** * Creates and returns NLS tag edits for strings that are at the specified positions in a * compilation unit. - * + * * @param cu the compilation unit * @param positions positions of the strings * @return the edit, or <code>null</code> if all strings are already NLSed or the edits could diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties index 90840d3e71..c9fc9d40d4 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/refactoring.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2019 IBM Corporation and others. +# Copyright (c) 2000, 2020 IBM Corporation and others. # # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 @@ -710,6 +710,9 @@ IntroduceParameterObjectRefactoring_descriptor_fields=Create fields for: SurroundWithTryCatchRefactoring_name=Surround with try/catch Block SurroundWithTryCatchRefactoring_notMultipleexceptions=The selected code does not throw multiple uncaught exceptions. A simple catch block will be created. SurroundWithTryCatchAnalyzer_doesNotContain=Selection does not contain statements from a method body or static initializer. +SurroundWithTryWithResourcesRefactoring_name=Surround with try-with-resources Block +SurroundWithTryWithResourcesRefactoring_notAutoclosable=The selected code does not contain Autoclosable items. A simple try/catch block will be created. +SurroundWithTryWithResourcesRefactoring_notAutoclosableNoExceptions=The selected code does not contain Autoclosable items and does not produce exceptions. ####################################### # org.eclipse.jdt.internal.core.refactoring.util diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/reorg/IReorgPolicy.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/reorg/IReorgPolicy.java index 76d248eac2..d680593bef 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/reorg/IReorgPolicy.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/reorg/IReorgPolicy.java @@ -31,7 +31,6 @@ import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments; -import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgDestination; import org.eclipse.jdt.internal.corext.refactoring.tagging.IQualifiedNameUpdating; import org.eclipse.jdt.internal.corext.refactoring.tagging.IReferenceUpdating; @@ -128,7 +127,7 @@ public interface IReorgPolicy extends IReorgDestinationValidator { * Checks if <b>Java</b> references to the selected element(s) can be updated if moved to * the selected destination. Even if <code>false</code>, participants could still update * non-Java references. - * + * * @return <code>true</code> iff <b>Java</b> references to the moved element can be updated * @since 3.5 */ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ASTNodeSearchUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ASTNodeSearchUtil.java index 8ccf4dcfa2..1717da9679 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ASTNodeSearchUtil.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ASTNodeSearchUtil.java @@ -60,7 +60,7 @@ import org.eclipse.jdt.internal.corext.util.JdtFlags; /** * JDT-UI-internal helper methods to find AST nodes for {@link SearchMatch}es or {@link IJavaElement}s. : - * + * * see JDTUIHelperClasses */ public class ASTNodeSearchUtil { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ImportRemover.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ImportRemover.java index 48dcd4d052..600e43c373 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ImportRemover.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/ImportRemover.java @@ -75,7 +75,7 @@ public class ImportRemover { private final String PROPERTY_KEY= String.valueOf(System.currentTimeMillis()); private final String REMOVED= "removed"; //$NON-NLS-1$ private final String RETAINED= "retained"; //$NON-NLS-1$ - + private Set<String> fAddedImports= new HashSet<>(); private Set<StaticImportData> fAddedStaticImports= new HashSet<>(); @@ -142,7 +142,7 @@ public class ImportRemover { super.postVisit(node); } }); - + for (Iterator<SimpleName> iterator= importNames.iterator(); iterator.hasNext();) { SimpleName name= iterator.next(); if (isInRemoved(name, removedStartsEnds)) @@ -258,7 +258,7 @@ public class ImportRemover { addName(node.getName()); return false; } - + @Override public boolean visit(QualifiedName node) { addName(node.getName()); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/MemberVisibilityAdjustor.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/MemberVisibilityAdjustor.java index c95af29c49..aa9da7d22d 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/MemberVisibilityAdjustor.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/MemberVisibilityAdjustor.java @@ -631,7 +631,7 @@ public final class MemberVisibilityAdjustor { boolean adjust= true; final IType declaring= member.getDeclaringType(); if (declaring != null && (JavaModelUtil.isInterfaceOrAnnotation(declaring) - || (member instanceof IField) && Flags.isEnum(member.getFlags()) + || (member instanceof IField) && Flags.isEnum(member.getFlags()) || declaring.equals(fReferenced))) adjust= false; if (adjust && hasLowerVisibility(member.getFlags(), keywordToVisibility(threshold)) && needsVisibilityAdjustment(member, threshold)) diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInstanceMethodProcessor.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInstanceMethodProcessor.java index 80858eeeaa..b9f6a30bc8 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInstanceMethodProcessor.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/structure/MoveInstanceMethodProcessor.java @@ -1732,7 +1732,7 @@ public final class MoveInstanceMethodProcessor extends MoveProcessor implements // replace move target parameter with new target arguments.add(factory.getTargetNode()); } else { - // drop unused move target parameter + // drop unused move target parameter } } else { arguments.add(factory.getArgumentNode(binding, i == size - 1)); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/tagging/IReferenceUpdating.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/tagging/IReferenceUpdating.java index 5f020c9afa..894c518062 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/tagging/IReferenceUpdating.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/tagging/IReferenceUpdating.java @@ -17,14 +17,14 @@ public interface IReferenceUpdating { /** * Informs the refactoring object whether references should be updated. - * + * * @param update <code>true</code> to enable reference updating */ public void setUpdateReferences(boolean update); /** * Asks the refactoring object whether references should be updated. - * + * * @return <code>true</code> iff reference updating is enabled */ public boolean getUpdateReferences(); diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/NullType.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/NullType.java index 9a004162fc..94132a6130 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/NullType.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/NullType.java @@ -38,7 +38,7 @@ public final class NullType extends TType { public int hashCode() { return 1234; } - + @Override public String getName() { return "null"; //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/PrimitiveType.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/PrimitiveType.java index fe3999fb26..285c9367cf 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/PrimitiveType.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/PrimitiveType.java @@ -70,7 +70,7 @@ public final class PrimitiveType extends TType { public int hashCode() { return fId; } - + @Override protected boolean doCanAssignTo(TType lhs) { if (lhs.getKind() != PRIMITIVE_TYPE) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TType.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TType.java index 1c65123fd1..5ef1ffe333 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TType.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TType.java @@ -25,10 +25,10 @@ import org.eclipse.jdt.core.dom.ITypeBinding; /** * TTypes are lightweight fully-resolved type objects that stand for {@link ITypeBinding}s. * TTypes can answer basic questions about the relationship between types. - * + * * They do not hold references to their corresponding {@link ITypeBinding}s, and they * don't carry any information about members of a type. - * + * * @see TypeEnvironment * @see TType#canAssignTo(TType) * @see HierarchyType#isSubType(HierarchyType) @@ -78,7 +78,7 @@ public abstract class TType { /** * Creates a new type with the given environment as an owner. * The type environment <em>must</em> call {@link #initialize(ITypeBinding)} after using this constructor. - * + * * @param environment owner */ protected TType(TypeEnvironment environment) { @@ -88,7 +88,7 @@ public abstract class TType { /** * Creates a new type with the given environment as an owner. * The type environment must <em>not</em> call {@link #initialize(ITypeBinding)} after using this constructor. - * + * * @param environment owner * @param key this type's binding key */ @@ -482,7 +482,7 @@ public abstract class TType { @Override public abstract int hashCode(); - + /** * Performs the actual equals check. * @@ -544,7 +544,7 @@ public abstract class TType { * Returns whether the receiver type is type equivalent to the other type. * This method considers the erasure for generic, raw and parameterized * types. - * + * * @param other the other type * @return whether the receiver is type equivalent to other */ @@ -557,7 +557,7 @@ public abstract class TType { * a type argument of a parameterized type is compatible with the given type * <code>rhs</code>. For example if * <code>List<this>= List<rhs></code> is a valid assignment. - * + * * @param rhs the right-hand-side type * @return <code>true</code> iff <code>this</code> contains <code>rhs</code> according to JLS3 4.5.1.1 */ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeEnvironment.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeEnvironment.java index 3ef28048c0..8e776f3355 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeEnvironment.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/TypeEnvironment.java @@ -40,7 +40,7 @@ import org.eclipse.jdt.internal.corext.dom.IASTSharedValues; * A type environment comprises a set of {@link TType}s that stand for Java {@link ITypeBinding}s. * In contrast to type bindings, TTypes of the same type environment also work across project boundaries and * across compiler environments, i.e. a type environment can handle bindings from multiple {@link ASTParser} sessions. - * + * * @see TType */ public class TypeEnvironment { @@ -174,7 +174,7 @@ public class TypeEnvironment { public TypeEnvironment(boolean rememberSubtypes) { this(rememberSubtypes, false); } - + public TypeEnvironment(boolean rememberSubtypes, boolean removeCapures) { if (rememberSubtypes) { fSubTypes= new HashMap<>(); @@ -234,7 +234,7 @@ public class TypeEnvironment { * has already created its first hierarchy type or it has been initialized explicitly. * * @return the TType for java.lang.Object - * + * * @see #initializeJavaLangObject(IJavaProject) */ public TType getJavaLangObject() { @@ -244,11 +244,11 @@ public class TypeEnvironment { public void initializeJavaLangObject(IJavaProject project) { if (OBJECT_TYPE != null) return; - + TType objectType= createStandardType("java.lang.Object", project); //$NON-NLS-1$ Assert.isTrue(objectType.isJavaLangObject()); } - + void initializeJavaLangObject(ITypeBinding object) { if (OBJECT_TYPE != null) return; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/VoidType.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/VoidType.java index 6e4c4c42d9..971609e8cb 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/VoidType.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/types/VoidType.java @@ -41,7 +41,7 @@ public final class VoidType extends TType { public int hashCode() { return 12345; } - + @Override protected boolean doCanAssignTo(TType lhs) { return false; diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/JavaElementUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/JavaElementUtil.java index feeae6b426..7eb66b1f8d 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/JavaElementUtil.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/JavaElementUtil.java @@ -48,7 +48,7 @@ import org.eclipse.jdt.internal.corext.util.JavaModelUtil; /** * Utility methods for the Java Model. - * + * * @see JavaModelUtil (a better place for new methods) * see JDTUIHelperClasses */ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/RefactoringASTParser.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/RefactoringASTParser.java index bb78409f31..77c30f8965 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/RefactoringASTParser.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/RefactoringASTParser.java @@ -142,7 +142,7 @@ public class RefactoringASTParser { * Turns all errors, warnings and infos into ignore and disables task tags. The customizable set of * compiler options only contains additional Eclipse options. The standard JDK compiler options * can't be changed anyway. - * + * * @param element an element (not the Java model) * @return compiler options */ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TightSourceRangeComputer.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TightSourceRangeComputer.java index f6b3796ea4..192c8fa14d 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TightSourceRangeComputer.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/refactoring/util/TightSourceRangeComputer.java @@ -33,7 +33,7 @@ import org.eclipse.jdt.internal.corext.dom.ASTNodes; * <p> * For nodes inside "tight" nodes, the source range is the extended source range, unless this would * violate the no-overlapping condition from the superclass. - * + * * @since 3.2 */ public class TightSourceRangeComputer extends TargetSourceRangeComputer { @@ -41,7 +41,7 @@ public class TightSourceRangeComputer extends TargetSourceRangeComputer { /** * Add the given node to the set of "tight" nodes. - * + * * @param reference a node * @since 3.2 */ diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaConventionsUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaConventionsUtil.java index d9db428819..d1d4f6a52f 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaConventionsUtil.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaConventionsUtil.java @@ -28,7 +28,7 @@ import org.eclipse.jdt.core.JavaCore; * the same element, please use {@link JavaConventions} directly (with the * arguments from {@link #getSourceComplianceLevels(IJavaElement)}). * </p> - * + * * @see JDTUIHelperClasses */ public class JavaConventionsUtil { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java index b998441d83..e44debc7a9 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JavaModelUtil.java @@ -74,7 +74,7 @@ import org.eclipse.jdt.launching.environments.IExecutionEnvironment; */ // @see JDTUIHelperClasses public final class JavaModelUtil { - + /** * The latest available {@link JavaCore}{@code #VERSION_*} level. * @since 3.7 @@ -106,7 +106,7 @@ public final class JavaModelUtil { * @since 3.8 */ public static final String PACKAGE_INFO_JAVA= "package-info.java"; //$NON-NLS-1$ - + /** * The name of the package-info.class file. * @since 3.9 @@ -141,7 +141,7 @@ public final class JavaModelUtil { * Finds a type container by container name. The returned element will be of type * <code>IType</code> or a <code>IPackageFragment</code>. <code>null</code> is returned if the * type container could not be found. - * + * * @param jproject The Java project defining the context to search * @param typeContainerName A dot separated name of the type container * @return returns the container @@ -257,7 +257,7 @@ public final class JavaModelUtil { /** * Returns whether the two names match. They match if they * are equal, or if they are the same name but one is missing a dot-separated qualifier. - * + * * @param nameA a potentially qualified name * @param nameB a potentially qualified name * @return <code>true</code> iff the given names match @@ -493,7 +493,7 @@ public final class JavaModelUtil { * * @param refTypeSig the type name in signature notation (for example 'QVector') this can also be an array type, but dimensions will be ignored. * @param declaringType the context for resolving (type where the reference was made in) - * @param enclosingTypeSeparator the enclosing type separator used in the qualified type name + * @param enclosingTypeSeparator the enclosing type separator used in the qualified type name * @return returns the fully qualified type name or build-in-type name. if a unresolved type couldn't be resolved null is returned * @throws JavaModelException thrown when the type can not be accessed */ @@ -544,7 +544,7 @@ public final class JavaModelUtil { /** * Checks whether the given type signature is from a primitive type. - * + * * @param typeSignature the type signature string to check * @return <code>true</code> if the type is a primitive type, <code> false</code> otherwise * @throws JavaModelException if this element does not exist or if an exception occurs while @@ -691,7 +691,7 @@ public final class JavaModelUtil { /** * Returns the classpath entry of the given package fragment root. This is the raw entry, except * if the root is a referenced library, in which case it's the resolved entry. - * + * * @param root a package fragment root * @return the corresponding classpath entry * @throws JavaModelException if accessing the entry failed @@ -793,11 +793,11 @@ public final class JavaModelUtil { public static boolean is50OrHigher(String compliance) { return !isVersionLessThan(compliance, JavaCore.VERSION_1_5); } - + public static boolean is16OrHigher(String compliance) { return !isVersionLessThan(compliance, JavaCore.VERSION_1_6); } - + public static boolean is17OrHigher(String compliance) { return !isVersionLessThan(compliance, JavaCore.VERSION_1_7); } @@ -809,7 +809,7 @@ public final class JavaModelUtil { public static boolean is9OrHigher(String compliance) { return !isVersionLessThan(compliance, JavaCore.VERSION_9); } - + public static boolean is10OrHigher(String compliance) { return !isVersionLessThan(compliance, JavaCore.VERSION_10); } @@ -849,10 +849,10 @@ public final class JavaModelUtil { public static boolean is17OrHigher(IJavaProject project) { return is17OrHigher(getSourceCompliance(project)); } - + /** * Checks if the given project or workspace has source compliance 1.8 or greater. - * + * * @param project the project to test or <code>null</code> to test the workspace settings * @return <code>true</code> if the given project or workspace has source compliance 1.8 or * greater. @@ -863,7 +863,7 @@ public final class JavaModelUtil { /** * Checks if the given project or workspace has source compliance 9 or greater. - * + * * @param project the project to test or <code>null</code> to test the workspace settings * @return <code>true</code> if the given project or workspace has source compliance 9 or * greater. @@ -874,7 +874,7 @@ public final class JavaModelUtil { /** * Checks if the given project or workspace has source compliance 10 or greater. - * + * * @param project the project to test or <code>null</code> to test the workspace settings * @return <code>true</code> if the given project or workspace has source compliance 10 or greater. */ @@ -884,21 +884,21 @@ public final class JavaModelUtil { /** * Checks if the given project or workspace has source compliance 11 or greater. - * + * * @param project the project to test or <code>null</code> to test the workspace settings * @return <code>true</code> if the given project or workspace has source compliance 11 or greater. */ public static boolean is11OrHigher(IJavaProject project) { return is11OrHigher(getSourceCompliance(project)); } - + public static boolean is12OrHigher(IJavaProject project) { return is12OrHigher(getSourceCompliance(project)); } /** * Checks if the given project or workspace has source compliance 13 or greater. - * + * * @param project the project to test or <code>null</code> to test the workspace settings * @return <code>true</code> if the given project or workspace has source compliance 13 or greater. */ @@ -1098,7 +1098,7 @@ public final class JavaModelUtil { /** * Tells whether the given type root represents a module. - * + * * @param typeRoot the type root to test * @return <code>true</code> if the given type root is a module-info.java CU or a module-info.class class file. * @since 3.14 @@ -1110,7 +1110,7 @@ public final class JavaModelUtil { /** * Tells whether the given Java element represents a module. - * + * * @param javaElement the Java element to test * @return <code>true</code> if the given Java element represents a module. * @since 3.14 @@ -1124,7 +1124,7 @@ public final class JavaModelUtil { * Tells whether the given package fragment contains any ordinary compilation unit, * not counting the modular compilation unit module-info.java nor its class file module-info.class. * @param fragment a package fragment to test - * @return true iff at least one ordinary compilation unit (or class file) was found. + * @return true iff at least one ordinary compilation unit (or class file) was found. * @throws JavaModelException if the package fragment does not exist or if an * exception occurs while accessing its corresponding resource * @since 3.14 @@ -1143,7 +1143,7 @@ public final class JavaModelUtil { /** * Applies a text edit to a compilation unit. - * + * * @param cu the compilation unit to apply the edit to * @param edit the edit to apply * @param save is set, save the CU after the edit has been applied diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JdtFlags.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JdtFlags.java index fbab60983a..ab7703f952 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JdtFlags.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/JdtFlags.java @@ -93,7 +93,7 @@ public class JdtFlags { return true; return Modifier.isStatic(bodyDeclaration.getModifiers()); } - + public static boolean isStatic(IMember member) throws JavaModelException { if (isNestedInterfaceOrAnnotation(member)) return true; @@ -268,7 +268,7 @@ public class JdtFlags { private static boolean isNestedInterfaceOrAnnotation(BodyDeclaration bodyDeclaration) { return bodyDeclaration.getParent() instanceof AbstractTypeDeclaration && isInterfaceOrAnnotation(bodyDeclaration); } - + private static boolean isNestedInterfaceOrAnnotation(IMember member) throws JavaModelException{ return member.getElementType() == IJavaElement.TYPE && member.getDeclaringType() != null && @@ -403,7 +403,7 @@ public class JdtFlags { /** * Gets the higher visibility of the given parameters. - * + * * @param visibility1 First visibility value to compare. Valid inputs are the {@link Modifier} visibility constants. * @param visibility2 Second visibility value to compare. Valid inputs are the {@link Modifier} visibility constants. * @return The parameter value with the higher visibility. diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/LRUMap.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/LRUMap.java index 46b28a0d55..dc7c0f7651 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/LRUMap.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/LRUMap.java @@ -26,7 +26,7 @@ import java.util.Map; * the order that key-value mappings are provided by the specified map's entry set iterator. <i>No * other methods generate entry accesses.</i> In particular, operations on collection-views do * <i>not</i> affect the order of iteration of the backing map. - * + * * @param <K> type of the keys * @param <V> type of the values */ @@ -37,7 +37,7 @@ public class LRUMap<K,V> extends LinkedHashMap<K,V> { /** * Creates an empty LRU map with the given maximum size. - * + * * @param maxSize the maximum number of elements in the cache */ public LRUMap(int maxSize) { diff --git a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodsSourcePositionComparator.java b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodsSourcePositionComparator.java index 3bacf73438..5dcb1a2c87 100644 --- a/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodsSourcePositionComparator.java +++ b/org.eclipse.jdt.core.manipulation/core extension/org/eclipse/jdt/internal/corext/util/MethodsSourcePositionComparator.java @@ -36,7 +36,7 @@ import org.eclipse.jdt.core.dom.ITypeBinding; * <li><code>m1</code> and <code>m2</code> are defined in the same type (<code>T</code> or any * supertype of <code>T</code>), that type doesn't have a source attachment and name of * <code>m1</code> alphabetically precedes name of <code>m2</code></li> - * + * * <li><code>m2</code> is defined in <code>T</code> and <code>m1</code> is defined in any supertype * of <code>T</code></li> * <li><code>m2</code> is defined in a superclass of <code>T</code> and <code>m1</code> is defined diff --git a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/CompilationUnitChange.java b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/CompilationUnitChange.java index 89d35effe5..78bb13d4f3 100644 --- a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/CompilationUnitChange.java +++ b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/core/refactoring/CompilationUnitChange.java @@ -36,7 +36,7 @@ import org.eclipse.jdt.internal.core.manipulation.JavaManipulationPlugin; /** * A {@link TextFileChange} that operates on an {@link ICompilationUnit} in the workspace. - * + * * @since 1.3 */ public class CompilationUnitChange extends TextFileChange { diff --git a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/core/refactoring/descriptors/RefactoringSignatureDescriptorFactory.java b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/core/refactoring/descriptors/RefactoringSignatureDescriptorFactory.java index 5b2d9f354e..2ef44279fc 100644 --- a/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/core/refactoring/descriptors/RefactoringSignatureDescriptorFactory.java +++ b/org.eclipse.jdt.core.manipulation/refactoring/org/eclipse/jdt/internal/core/refactoring/descriptors/RefactoringSignatureDescriptorFactory.java @@ -47,7 +47,7 @@ import org.eclipse.jdt.core.refactoring.descriptors.UseSupertypeDescriptor; /** * Internal factory for Java refactoring signature descriptors. - * + * * @since 3.5 */ public class RefactoringSignatureDescriptorFactory { @@ -55,7 +55,7 @@ public class RefactoringSignatureDescriptorFactory { public static ChangeMethodSignatureDescriptor createChangeMethodSignatureDescriptor() { return new ChangeMethodSignatureDescriptor(); } - + public static ChangeMethodSignatureDescriptor createChangeMethodSignatureDescriptor(String project, String description, String comment, Map<String, String> arguments, int flags) { return new ChangeMethodSignatureDescriptor(project, description, comment, arguments, flags); } diff --git a/org.eclipse.jdt.jeview/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.jeview/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.jeview/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.jeview/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/EditorUtility.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/EditorUtility.java index 37c4cb6ffa..fd32b1dbdd 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/EditorUtility.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/EditorUtility.java @@ -1,13 +1,13 @@ /******************************************************************************* * Copyright (c) 2000, 2015 IBM Corporation and others. * - * This program and the accompanying materials + * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -47,8 +47,8 @@ public class EditorUtility { } return null; } - - + + public static IOpenable getJavaInput(IEditorPart part) { IEditorInput editorInput= part.getEditorInput(); if (editorInput != null) { @@ -57,28 +57,28 @@ public class EditorUtility { return (IOpenable) input; } } - return null; + return null; } /** * Note: This is an inlined version of {@link JavaUI#getEditorInputJavaElement(IEditorInput)}, * which is not available in 3.1. - * + * * @param editorInput the editor input * @return the Java element wrapped by <code>editorInput</code> or <code>null</code> if none */ private static IJavaElement javaUIgetEditorInputJavaElement(IEditorInput editorInput) { Assert.isNotNull(editorInput); - IJavaElement je= JavaUI.getWorkingCopyManager().getWorkingCopy(editorInput); + IJavaElement je= JavaUI.getWorkingCopyManager().getWorkingCopy(editorInput); if (je != null) return je; - + /* * This needs works, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=120340 */ return editorInput.getAdapter(IJavaElement.class); } - + public static void selectInEditor(ITextEditor editor, int offset, int length) { IEditorPart active = getActiveEditor(); if (active != editor) { diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/JEViewPlugin.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/JEViewPlugin.java index 70ae965dcc..b21e383382 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/JEViewPlugin.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/JEViewPlugin.java @@ -36,7 +36,7 @@ public class JEViewPlugin extends AbstractUIPlugin { public static String getPluginId() { return "org.eclipse.jdt.jeview"; //$NON-NLS-1$ } - + @Override public void stop(BundleContext context) throws Exception { super.stop(context); @@ -56,19 +56,19 @@ public class JEViewPlugin extends AbstractUIPlugin { public static IWorkspace getWorkspace() { return ResourcesPlugin.getWorkspace(); } - + public static void log(IStatus status) { getDefault().getLog().log(status); } - + public static void logErrorMessage(String message) { log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, null)); } - + public static void logMessage(String message) { log(new Status(IStatus.INFO, getPluginId(), IStatus.INFO, message, null)); } - + public static void logErrorStatus(String message, IStatus status) { if (status == null) { logErrorMessage(message); @@ -78,12 +78,12 @@ public class JEViewPlugin extends AbstractUIPlugin { multi.add(status); log(multi); } - + public static void log(String message, Throwable e) { - log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, e)); + log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, e)); } - + public static void log(Throwable e) { - log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, e.getLocalizedMessage(), e)); + log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, e.getLocalizedMessage(), e)); } } diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/ClasspathEntryProperties.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/ClasspathEntryProperties.java index 4935ce8a1c..2d17529cde 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/ClasspathEntryProperties.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/ClasspathEntryProperties.java @@ -30,16 +30,16 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.jeview.JEViewPlugin; public class ClasspathEntryProperties implements IPropertySource { - + private static abstract class Property extends GenericProperty<IClasspathEntry> { public Property(String name) { super(IClasspathEntry.class, name); } } - + private static HashMap<String, Property> fgIdToProperty= new HashMap<>(); private static LinkedHashMap<Class<?>, List<Property>> fgTypeToProperty= new LinkedHashMap<>(); - + static { addProperty(new Property("combineAccessRules") { @Override public Object compute(IClasspathEntry entry) { @@ -82,7 +82,7 @@ public class ClasspathEntryProperties implements IPropertySource { } }); } - + private static void addProperty(Property property) { fgIdToProperty.put(property.getId(), property); List<Property> properties= fgTypeToProperty.get(property.getType()); @@ -92,7 +92,7 @@ public class ClasspathEntryProperties implements IPropertySource { } properties.add(property); } - + static String getContentKindString(int kind) { String name; switch (kind) { @@ -108,7 +108,7 @@ public class ClasspathEntryProperties implements IPropertySource { } return kind + " (" + name + ")"; } - + static String getEntryKindString(int kind) { String name; switch (kind) { @@ -133,14 +133,14 @@ public class ClasspathEntryProperties implements IPropertySource { } return kind + " (" + name + ")"; } - - + + protected IClasspathEntry fEntry; public ClasspathEntryProperties(IClasspathEntry entry) { fEntry= entry; } - + @Override public IPropertyDescriptor[] getPropertyDescriptors() { List<IPropertyDescriptor> result= new ArrayList<>(); @@ -153,7 +153,7 @@ public class ClasspathEntryProperties implements IPropertySource { } return result.toArray(new IPropertyDescriptor[result.size()]); } - + @Override public Object getPropertyValue(Object id) { Property property= fgIdToProperty.get(id); @@ -172,22 +172,22 @@ public class ClasspathEntryProperties implements IPropertySource { } } } - + @Override public void setPropertyValue(Object name, Object value) { // do nothing } - + @Override public Object getEditableValue() { return this; } - + @Override public boolean isPropertySet(Object property) { return false; } - + @Override public void resetPropertyValue(Object property) { // do nothing diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/GenericProperty.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/GenericProperty.java index 1af4f59709..84f5e75b68 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/GenericProperty.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/GenericProperty.java @@ -18,12 +18,12 @@ import org.eclipse.ui.views.properties.PropertyDescriptor; import org.eclipse.jdt.core.JavaModelException; public abstract class GenericProperty<T> { - + private final Class<T> fType; private final String fName; private final String fId; private final PropertyDescriptor fDescriptor; - + public GenericProperty(Class<T> type, String name) { fType= type; fName= name; @@ -35,22 +35,22 @@ public abstract class GenericProperty<T> { public abstract Object compute(T element) throws JavaModelException; - + public Class<T> getType() { return fType; } - - + + public String getName() { return fName; } - + public String getId() { return fId; } - + public PropertyDescriptor getDescriptor() { return fDescriptor; } - + }
\ No newline at end of file diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/JarEntryResourceProperties.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/JarEntryResourceProperties.java index af73c805a2..96314643d1 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/JarEntryResourceProperties.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/JarEntryResourceProperties.java @@ -23,16 +23,16 @@ import org.eclipse.ui.views.properties.PropertyDescriptor; import org.eclipse.jdt.core.IJarEntryResource; public class JarEntryResourceProperties implements IPropertySource { - + private static final String C_JAR_ENTRY_RESOURCE= "IJarEntryResource"; - + private static final String P_NAME= "org.eclipse.jdt.jeview.IJarEntryResource.name"; private static final String P_FULL_PATH= "org.eclipse.jdt.jeview.IJarEntryResource.fullPath"; private static final String P_IS_FILE= "org.eclipse.jdt.jeview.IJarEntryResource.isFile"; private static final String P_IS_READ_ONLY= "org.eclipse.jdt.jeview.IJarEntryResource.isReadOnly"; - + protected IJarEntryResource fJarEntryResource; - + private static final ArrayList<IPropertyDescriptor> JAR_ENTRY_RESOURCE_PROPERTY_DESCRIPTORS= new ArrayList<>(); static { addResourceDescriptor(new PropertyDescriptor(P_NAME, "name")); @@ -46,18 +46,18 @@ public class JarEntryResourceProperties implements IPropertySource { descriptor.setCategory(C_JAR_ENTRY_RESOURCE); JAR_ENTRY_RESOURCE_PROPERTY_DESCRIPTORS.add(descriptor); } - + public JarEntryResourceProperties(IJarEntryResource jarEntryResource) { fJarEntryResource= jarEntryResource; } - + @Override public IPropertyDescriptor[] getPropertyDescriptors() { ArrayList<IPropertyDescriptor> result= new ArrayList<>(JAR_ENTRY_RESOURCE_PROPERTY_DESCRIPTORS); return result.toArray(new IPropertyDescriptor[result.size()]); } - + @Override public Object getPropertyValue(Object name) { if (name.equals(P_NAME)) { @@ -69,25 +69,25 @@ public class JarEntryResourceProperties implements IPropertySource { } else if (name.equals(P_IS_READ_ONLY)) { return fJarEntryResource.isReadOnly(); } - + return null; } - + @Override public void setPropertyValue(Object name, Object value) { // do nothing } - + @Override public Object getEditableValue() { return this; } - + @Override public boolean isPropertySet(Object property) { return false; } - + @Override public void resetPropertyValue(Object property) { // do nothing diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/JavaElementProperties.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/JavaElementProperties.java index d201e7e6ae..2d572dea09 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/JavaElementProperties.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/JavaElementProperties.java @@ -50,17 +50,17 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.jeview.JEViewPlugin; public class JavaElementProperties implements IPropertySource { - + private static HashMap<String, Property> fgIdToProperty= new HashMap<>(); private static LinkedHashMap<Class<?>, List<Property>> fgTypeToProperty= new LinkedHashMap<>(); - - + + private static abstract class Property { private final Class<?> fType; private final String fName; private final String fId; private final PropertyDescriptor fDescriptor; - + public Property(Class<?> type, String name) { fType= type; fName= name; @@ -72,26 +72,26 @@ public class JavaElementProperties implements IPropertySource { public abstract Object compute(IJavaElement javaElement) throws JavaModelException; - + public Class<?> getType() { return fType; } - - + + public String getName() { return fName; } - + public String getId() { return fId; } - + public PropertyDescriptor getDescriptor() { return fDescriptor; } - + } - + static { addJavaElementProperties(); addClassFileProperties(); @@ -242,7 +242,7 @@ public class JavaElementProperties implements IPropertySource { } }); } - + private static void addMemberProperties() { addProperty(new Property(IMember.class, "javadocRange") { @Override public Object compute(IJavaElement element) throws JavaModelException { @@ -530,13 +530,13 @@ public class JavaElementProperties implements IPropertySource { } properties.add(property); } - + protected IJavaElement fJavaElement; public JavaElementProperties(IJavaElement javaElement) { fJavaElement= javaElement; } - + @Override public IPropertyDescriptor[] getPropertyDescriptors() { List<IPropertyDescriptor> result= new ArrayList<>(); @@ -549,7 +549,7 @@ public class JavaElementProperties implements IPropertySource { } return result.toArray(new IPropertyDescriptor[result.size()]); } - + @Override public Object getPropertyValue(Object id) { Property property= fgIdToProperty.get(id); @@ -626,7 +626,7 @@ public class JavaElementProperties implements IPropertySource { } return elementType + " (" + name + ")"; } - + static String getSourceRangeString(ISourceRange range) { return range == null ? "null" : range.getOffset() + " + " + range.getLength(); } @@ -635,7 +635,7 @@ public class JavaElementProperties implements IPropertySource { StringBuffer sb = new StringBuffer().append("0x").append(Integer.toHexString(flags)).append(" ("); int prologLen= sb.length(); int rest= flags; - + rest&= ~ appendFlag(sb, flags, Flags.AccPublic, "public "); rest&= ~ appendFlag(sb, flags, Flags.AccPrivate, "private "); rest&= ~ appendFlag(sb, flags, Flags.AccProtected, "protected "); @@ -663,7 +663,7 @@ public class JavaElementProperties implements IPropertySource { if (isMethod) { rest&= ~ appendFlag(sb, flags, Flags.AccAnnotationDefault, "default(annotation) "); } - + if (rest != 0) sb.append("unknown:0x").append(Integer.toHexString(rest)).append(" "); int len = sb.length(); @@ -672,7 +672,7 @@ public class JavaElementProperties implements IPropertySource { sb.append(")"); return sb.toString(); } - + private static int appendFlag(StringBuffer sb, int flags, int flag, String name) { if ((flags & flag) != 0) { sb.append(name); @@ -686,10 +686,10 @@ public class JavaElementProperties implements IPropertySource { StringBuffer sb = new StringBuffer().append("0x").append(Integer.toHexString(kind)).append(" ("); int prologLen= sb.length(); int rest= kind; - + rest&= ~ appendFlag(sb, kind, IPackageFragmentRoot.K_BINARY, "binary "); rest&= ~ appendFlag(sb, kind, IPackageFragmentRoot.K_SOURCE, "source "); - + if (rest != 0) sb.append("unknown:0x").append(Integer.toHexString(rest)); int len = sb.length(); @@ -698,29 +698,29 @@ public class JavaElementProperties implements IPropertySource { sb.append(")"); return sb.toString(); } - + static String getSchedulingRuleString(ISchedulingRule schedulingRule) { if (schedulingRule == null) return null; else return schedulingRule.getClass().getSimpleName() + ": " + schedulingRule.toString(); } - + @Override public void setPropertyValue(Object name, Object value) { // do nothing } - + @Override public Object getEditableValue() { return this; } - + @Override public boolean isPropertySet(Object property) { return false; } - + @Override public void resetPropertyValue(Object property) { // do nothing diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/MarkerProperties.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/MarkerProperties.java index 0f11a9c0e7..5297920f8f 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/MarkerProperties.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/MarkerProperties.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -32,7 +32,7 @@ import org.eclipse.jdt.core.compiler.IProblem; public class MarkerProperties implements IPropertySource { private static final AttributeDescriptor[] NO_DESCRIPTORS= new AttributeDescriptor[0]; - + private final IMarker fMarker; private AttributeDescriptor[] fPropertyDescriptors; @@ -45,7 +45,7 @@ public class MarkerProperties implements IPropertySource { public AttributeDescriptor[] getPropertyDescriptors() { if (fPropertyDescriptors != null) return fPropertyDescriptors; - + Map<String, Object> attributes= null; boolean isJavaMarker= false; try { @@ -73,11 +73,11 @@ public class MarkerProperties implements IPropertySource { propertyDescriptor.setCategory("Attributes"); fPropertyDescriptors[i++]= propertyDescriptor; } - + MarkerPropertyDescriptor propertyDescriptor= new MarkerPropertyDescriptor("exists", fMarker.exists()); propertyDescriptor.setAlwaysIncompatible(true); fPropertyDescriptors[i++]= propertyDescriptor; - + String type; try { type= fMarker.getType(); @@ -87,7 +87,7 @@ public class MarkerProperties implements IPropertySource { propertyDescriptor= new MarkerPropertyDescriptor("type", type); propertyDescriptor.setAlwaysIncompatible(true); fPropertyDescriptors[i++]= propertyDescriptor; - + String time; try { time= DateFormat.getDateTimeInstance().format(new Date(fMarker.getCreationTime())); @@ -97,11 +97,11 @@ public class MarkerProperties implements IPropertySource { propertyDescriptor= new MarkerPropertyDescriptor("creationTime", time); propertyDescriptor.setAlwaysIncompatible(true); fPropertyDescriptors[i++]= propertyDescriptor; - + propertyDescriptor= new MarkerPropertyDescriptor("markerId", fMarker.getId()); propertyDescriptor.setAlwaysIncompatible(true); fPropertyDescriptors[i++]= propertyDescriptor; - + } return fPropertyDescriptors; } @@ -116,59 +116,59 @@ public class MarkerProperties implements IPropertySource { return null; } - + @Override public void setPropertyValue(Object name, Object value) { // do nothing } - + @Override public Object getEditableValue() { return this; } - + @Override public boolean isPropertySet(Object property) { return false; } - + @Override public void resetPropertyValue(Object property) { // do nothing } - - + + private static class AttributeDescriptor extends PropertyDescriptor { private final Object fValue; public AttributeDescriptor(String name, Object value) { this("org.eclipse.jdt.jeview.IMarker." + name, name, value); } - + protected AttributeDescriptor(String key, String name, Object value) { super(key, name); fValue= value; } - + public Object getValue() { return fValue; } } - + private static class ProblemIdAttributeDescriptor extends AttributeDescriptor { public ProblemIdAttributeDescriptor(String key, Object value) { super(key, value); } - + @Override public Object getValue() { return getErrorLabel(); } - + private String getErrorLabel() { int id= (Integer) super.getValue(); StringBuffer buf= new StringBuffer(getConstantName(id)).append(" = "); - + if ((id & IProblem.TypeRelated) != 0) { buf.append("TypeRelated + "); } @@ -194,12 +194,12 @@ public class MarkerProperties implements IPropertySource { buf.append("Javadoc + "); } buf.append(id & IProblem.IgnoreCategoriesMask); - + buf.append(" = 0x").append(Integer.toHexString(id)).append(" = ").append(id); - + return buf.toString(); } - + private static String getConstantName(int id) { Field[] fields= IProblem.class.getFields(); for (Field f : fields) { @@ -215,13 +215,13 @@ public class MarkerProperties implements IPropertySource { } return "<UNKNOWN CONSTANT>"; } - + } - + private static class MarkerPropertyDescriptor extends AttributeDescriptor { public MarkerPropertyDescriptor(String key, Object value) { super("org.eclipse.jdt.jeview.IMarker.property." + key, key, value); } } - + } diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/MemberValuePairProperties.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/MemberValuePairProperties.java index 1b0f2d920b..8ffc210ed8 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/MemberValuePairProperties.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/MemberValuePairProperties.java @@ -24,14 +24,14 @@ import org.eclipse.ui.views.properties.PropertyDescriptor; import org.eclipse.jdt.core.IMemberValuePair; public class MemberValuePairProperties implements IPropertySource { - + private static final String C_MEMBER_VALUE_PAIR= "IMemberValuePair"; - + private static final String P_MEMBER_NAME= "org.eclipse.jdt.jeview.IMemberValuePair.memberName"; private static final String P_VALUE_KIND= "org.eclipse.jdt.jeview.IMemberValuePair.valueKind"; - + protected IMemberValuePair fMemberValuePair; - + private static final ArrayList<IPropertyDescriptor> MEMBER_VALUE_PAIR_PROPERTY_DESCRIPTORS= new ArrayList<>(); static { addResourceDescriptor(new PropertyDescriptor(P_MEMBER_NAME, "memberName")); @@ -43,18 +43,18 @@ public class MemberValuePairProperties implements IPropertySource { descriptor.setCategory(C_MEMBER_VALUE_PAIR); MEMBER_VALUE_PAIR_PROPERTY_DESCRIPTORS.add(descriptor); } - + public MemberValuePairProperties(IMemberValuePair memberValuePair) { fMemberValuePair= memberValuePair; } - + @Override public IPropertyDescriptor[] getPropertyDescriptors() { ArrayList<IPropertyDescriptor> result= new ArrayList<>(MEMBER_VALUE_PAIR_PROPERTY_DESCRIPTORS); return result.toArray(new IPropertyDescriptor[result.size()]); } - + @Override public Object getPropertyValue(Object name) { if (name.equals(P_MEMBER_NAME)) { @@ -62,30 +62,30 @@ public class MemberValuePairProperties implements IPropertySource { } else if (name.equals(P_VALUE_KIND)) { return getValueKindName(fMemberValuePair.getValueKind()); } - + return null; } - + @Override public void setPropertyValue(Object name, Object value) { // do nothing } - + @Override public Object getEditableValue() { return this; } - + @Override public boolean isPropertySet(Object property) { return false; } - + @Override public void resetPropertyValue(Object property) { // do nothing } - + static String getValueKindName(int valueKind) { String name= "UNKNOWN"; Field[] fields= IMemberValuePair.class.getFields(); @@ -103,5 +103,5 @@ public class MemberValuePairProperties implements IPropertySource { } return valueKind + " (" + name + ")"; } - + } diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/ResourceProperties.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/ResourceProperties.java index 968932d7b5..47709822c1 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/ResourceProperties.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/ResourceProperties.java @@ -23,9 +23,9 @@ import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.PropertyDescriptor; public class ResourceProperties implements IPropertySource { - + private static final String C_RESOURCE= "IResource"; - + private static final String P_NAME= "org.eclipse.jdt.jeview.IResource.name"; private static final String P_FULL_PATH= "org.eclipse.jdt.jeview.IResource.fullPath"; private static final String P_LOCATION= "org.eclipse.jdt.jeview.IResource.location"; @@ -41,9 +41,9 @@ public class ResourceProperties implements IPropertySource { private static final String P_IS_PHANTOM= "org.eclipse.jdt.jeview.IResource.isPhantom"; private static final String P_IS_TEAM_PRIVATE_MEMBER= "org.eclipse.jdt.jeview.IResource.isTeamPrivateMember"; private static final String P_IS_VIRTUAL= "org.eclipse.jdt.jeview.IResource.isVirtual"; - + protected IResource fResource; - + private static final ArrayList<IPropertyDescriptor> RESOURCE_PROPERTY_DESCRIPTORS= new ArrayList<>(); static { addResourceDescriptor(new PropertyDescriptor(P_NAME, "name")); @@ -68,12 +68,12 @@ public class ResourceProperties implements IPropertySource { descriptor.setCategory(C_RESOURCE); RESOURCE_PROPERTY_DESCRIPTORS.add(descriptor); } - + public ResourceProperties(IResource resource) { fResource= resource; } - + @Override public IPropertyDescriptor[] getPropertyDescriptors() { ArrayList<IPropertyDescriptor> result= new ArrayList<>(RESOURCE_PROPERTY_DESCRIPTORS); @@ -81,11 +81,11 @@ public class ResourceProperties implements IPropertySource { // result.addAll(MEMBER_PROPERTY_DESCRIPTORS); // if (fJavaElement instanceof IParent) // result.addAll(PARENT_PROPERTY_DESCRIPTORS); - + return result.toArray(new IPropertyDescriptor[result.size()]); } - + @Override public Object getPropertyValue(Object name) { if (name.equals(P_NAME)) { @@ -119,25 +119,25 @@ public class ResourceProperties implements IPropertySource { } else if (name.equals(P_IS_VIRTUAL)) { return fResource.isVirtual(); } - + return null; } - + @Override public void setPropertyValue(Object name, Object value) { // do nothing } - + @Override public Object getEditableValue() { return this; } - + @Override public boolean isPropertySet(Object property) { return false; } - + @Override public void resetPropertyValue(Object property) { // do nothing diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/Error.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/Error.java index f000323dbc..76b28e41c9 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/Error.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/Error.java @@ -40,7 +40,7 @@ public class Error extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + Error other= (Error) obj; if (fParent == null) { if (other.fParent != null) @@ -48,31 +48,31 @@ public class Error extends JEAttribute { } else if (! fParent.equals(other.fParent)) { return false; } - + if (fName == null) { if (other.fName != null) return false; } else if (! fName.equals(other.fName)) { return false; } - + if (fException == null) { if (other.fException != null) return false; } else if (! fException.equals(other.fException)) { return false; } - + return true; } - + @Override public int hashCode() { return (fParent != null ? fParent.hashCode() : 0) + (fName != null ? fName.hashCode() : 0) + (fException != null ? fException.hashCode() : 0); } - + @Override public JEAttribute[] getChildren() { return EMPTY; @@ -86,7 +86,7 @@ public class Error extends JEAttribute { public Exception getException() { return fException; } - + @Override public Object getWrappedObject() { return fException; diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEAttribute.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEAttribute.java index fcc54dc705..88c3b63b75 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEAttribute.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEAttribute.java @@ -1,13 +1,13 @@ /******************************************************************************* * Copyright (c) 2000, 2007 IBM Corporation and others. * - * This program and the accompanying materials + * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -18,19 +18,19 @@ package org.eclipse.jdt.jeview.views; * */ public abstract class JEAttribute { - + protected static final JEAttribute[] EMPTY= new JEAttribute[0]; public abstract JEAttribute getParent(); public abstract JEAttribute[] getChildren(); public abstract String getLabel(); - + public abstract Object getWrappedObject(); - + @Override public abstract boolean equals(Object obj); - + @Override public abstract int hashCode(); - + } diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEClasspathEntry.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEClasspathEntry.java index 654836d778..5b6d3a87e8 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEClasspathEntry.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEClasspathEntry.java @@ -30,11 +30,11 @@ import org.eclipse.jdt.core.JavaCore; public class JEClasspathEntry extends JEAttribute { - + private final JEAttribute fParent; // can be null private final String fName; // can be null final IClasspathEntry fEntry; - + JEClasspathEntry(JEAttribute parent, String name, IClasspathEntry entry) { Assert.isNotNull(entry); fParent= parent; @@ -46,7 +46,7 @@ public class JEClasspathEntry extends JEAttribute { public JEAttribute getParent() { return fParent; } - + @Override public boolean equals(Object obj) { if (this == obj) @@ -54,7 +54,7 @@ public class JEClasspathEntry extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + JEClasspathEntry other= (JEClasspathEntry) obj; if (fParent == null) { if (other.fParent != null) @@ -62,33 +62,33 @@ public class JEClasspathEntry extends JEAttribute { } else if (! fParent.equals(other.fParent)) { return false; } - + if (fName == null) { if (other.fName != null) return false; } else if (! fName.equals(other.fName)) { return false; } - + return true; } - + @Override public int hashCode() { return (fParent != null ? fParent.hashCode() : 0) + (fName != null ? fName.hashCode() : 0) + fEntry.hashCode(); } - + @Override public Object getWrappedObject() { return fEntry; } - + @Override public JEAttribute[] getChildren() { ArrayList<JEAttribute> result= new ArrayList<>(); - + result.add(new JavaElementChildrenProperty(this, "ACCESS RULES") { @Override protected JEAttribute[] computeChildren() throws CoreException { IAccessRule[] accessRules= fEntry.getAccessRules(); @@ -170,7 +170,7 @@ public class JEClasspathEntry extends JEAttribute { return children; } }); - + return result.toArray(new JEAttribute[result.size()]); } @@ -181,7 +181,7 @@ public class JEClasspathEntry extends JEAttribute { label= fName + ": " + label; return label; } - + public static JEAttribute compute(JEAttribute parent, String name, Callable<IClasspathEntry> computer) { try { IClasspathEntry entry= computer.call(); @@ -198,5 +198,5 @@ public class JEClasspathEntry extends JEAttribute { return new JEClasspathEntry(parent, name, entry); } } - + } diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEJarEntryResource.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEJarEntryResource.java index c12f9521f9..5f58e39cc7 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEJarEntryResource.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEJarEntryResource.java @@ -24,11 +24,11 @@ import org.eclipse.jdt.core.IJavaElement; public class JEJarEntryResource extends JEAttribute { - + private final JEAttribute fParent; // can be null private final String fName; // can be null private IJarEntryResource fJarEntryResource; - + JEJarEntryResource(JEAttribute parent, String name, IJarEntryResource jarEntryResource) { Assert.isNotNull(jarEntryResource); fParent= parent; @@ -40,7 +40,7 @@ public class JEJarEntryResource extends JEAttribute { public JEAttribute getParent() { return fParent; } - + @Override public boolean equals(Object obj) { if (this == obj) @@ -48,7 +48,7 @@ public class JEJarEntryResource extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + JEJarEntryResource other= (JEJarEntryResource) obj; if (fParent == null) { if (other.fParent != null) @@ -56,29 +56,29 @@ public class JEJarEntryResource extends JEAttribute { } else if (! fParent.equals(other.fParent)) { return false; } - + if (fName == null) { if (other.fName != null) return false; } else if (! fName.equals(other.fName)) { return false; } - + return true; } - + @Override public int hashCode() { return (fParent != null ? fParent.hashCode() : 0) + (fName != null ? fName.hashCode() : 0) + fJarEntryResource.hashCode(); } - + @Override public Object getWrappedObject() { return fJarEntryResource; } - + public IJarEntryResource getJarEntryResource() { return fJarEntryResource; } @@ -86,15 +86,15 @@ public class JEJarEntryResource extends JEAttribute { @Override public JEAttribute[] getChildren() { ArrayList<JEAttribute> result= new ArrayList<>(); - + Object parent= fJarEntryResource.getParent(); if (parent instanceof IJarEntryResource) result.add(new JEJarEntryResource(this, "PARENT", (IJarEntryResource) parent)); else result.add(new JavaElement(this, "PARENT", (IJavaElement) parent)); - + result.add(new JavaElement(this, "PACKAGE FRAGMENT ROOT", fJarEntryResource.getPackageFragmentRoot())); - + result.add(new JavaElementChildrenProperty(this, "CHILDREN") { @Override protected JEAttribute[] computeChildren() throws CoreException { IJarEntryResource[] jarEntryResources= getJarEntryResource().getChildren(); diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEMarker.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEMarker.java index 32c7f44bcc..3254e5550b 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEMarker.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEMarker.java @@ -1,13 +1,13 @@ /******************************************************************************* * Copyright (c) 2000, 2007 IBM Corporation and others. * - * This program and the accompanying materials + * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -56,16 +56,16 @@ public class JEMarker extends JEAttribute { return e.getClass().getSimpleName(); } } - + public IMarker getMarker() { return fMarker; } - + @Override public Object getWrappedObject() { return fMarker; } - + @Override public boolean equals(Object obj) { if (this == obj) @@ -73,7 +73,7 @@ public class JEMarker extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + JEMarker other= (JEMarker) obj; if (! fParent.equals(other.fParent)) { return false; @@ -84,13 +84,13 @@ public class JEMarker extends JEAttribute { if (! fMarker.equals(other.fMarker)) { return false; } - + return true; } - + @Override public int hashCode() { return fParent.hashCode() + fName.hashCode() + fMarker.hashCode(); } - + } diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEMemberValuePair.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEMemberValuePair.java index 8242810656..2295871586 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEMemberValuePair.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEMemberValuePair.java @@ -22,11 +22,11 @@ import org.eclipse.jdt.core.JavaModelException; public class JEMemberValuePair extends JEAttribute { - + private final JEAttribute fParent; private String fName; // can be null private IMemberValuePair fMemberValuePair; // can be null - + JEMemberValuePair(JEAttribute parent, String name, IMemberValuePair memberValuePair) { Assert.isNotNull(parent); fParent= parent; @@ -37,12 +37,12 @@ public class JEMemberValuePair extends JEAttribute { JEMemberValuePair(JEAttribute parent, IMemberValuePair memberValuePair) { this(parent, null, memberValuePair); } - + @Override public JEAttribute getParent() { return fParent; } - + @Override public boolean equals(Object obj) { if (this == obj) @@ -50,7 +50,7 @@ public class JEMemberValuePair extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + JEMemberValuePair other= (JEMemberValuePair) obj; if (fParent == null) { if (other.fParent != null) @@ -58,36 +58,36 @@ public class JEMemberValuePair extends JEAttribute { } else if (! fParent.equals(other.fParent)) { return false; } - + if (fName == null) { if (other.fName != null) return false; } else if (! fName.equals(other.fName)) { return false; } - + if (fMemberValuePair == null) { if (other.fMemberValuePair != null) return false; } else if (! fMemberValuePair.getMemberName().equals(other.fMemberValuePair.getMemberName())) { return false; } - + return true; } - + @Override public int hashCode() { return (fParent != null ? fParent.hashCode() : 0) + (fName != null ? fName.hashCode() : 0) + (fMemberValuePair != null ? fMemberValuePair.getMemberName().hashCode() : 0); } - + @Override public Object getWrappedObject() { return fMemberValuePair; } - + @Override public JEAttribute[] getChildren() { if (fMemberValuePair == null) @@ -114,13 +114,13 @@ public class JEMemberValuePair extends JEAttribute { static JEAttribute createMVPairValue(JEAttribute parent, String name, Object value) { if ((value instanceof Object[])) { return createArrayValuedMVPair(parent, name, (Object[]) value); - + } else if (value instanceof IAnnotation) { return new JavaElement(parent, name, (IAnnotation) value); - + } else if (value != null) { return new JavaElementProperty(parent, name, value); - + } else { return new Null(parent, name); } @@ -133,7 +133,7 @@ public class JEMemberValuePair extends JEAttribute { JEAttribute[] children= new JEAttribute[values.length]; for (int i= 0; i < values.length; i++) { Object value= values[i]; - String childName= value == null ? "" : value.getClass().getSimpleName(); + String childName= value == null ? "" : value.getClass().getSimpleName(); children[i]= createMVPairValue(this, childName, value); } return children; diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEResource.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEResource.java index 4da41dba8f..ecc5df37f7 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEResource.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEResource.java @@ -31,11 +31,11 @@ import org.eclipse.jdt.core.JavaCore; public class JEResource extends JEAttribute { - + private final JEAttribute fParent; // can be null private final String fName; // can be null private IResource fResource; - + JEResource(JEAttribute parent, String name, IResource resource) { Assert.isNotNull(resource); fParent= parent; @@ -47,7 +47,7 @@ public class JEResource extends JEAttribute { public JEAttribute getParent() { return fParent; } - + @Override public boolean equals(Object obj) { if (this == obj) @@ -55,7 +55,7 @@ public class JEResource extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + JEResource other= (JEResource) obj; if (fParent == null) { if (other.fParent != null) @@ -63,29 +63,29 @@ public class JEResource extends JEAttribute { } else if (! fParent.equals(other.fParent)) { return false; } - + if (fName == null) { if (other.fName != null) return false; } else if (! fName.equals(other.fName)) { return false; } - + return true; } - + @Override public int hashCode() { return (fParent != null ? fParent.hashCode() : 0) + (fName != null ? fName.hashCode() : 0) + fResource.hashCode(); } - + @Override public Object getWrappedObject() { return fResource; } - + public IResource getResource() { return fResource; } @@ -93,15 +93,15 @@ public class JEResource extends JEAttribute { @Override public JEAttribute[] getChildren() { ArrayList<JEAttribute> result= new ArrayList<>(); - + IContainer parent= fResource.getParent(); if (parent != null ) result.add(new JEResource(this, "PARENT", parent)); else result.add(new JavaElementProperty(this, "PARENT", parent)); - + result.add(new JavaElement(this, "JavaCore.create(..)", JavaCore.create(fResource))); - + if (fResource instanceof IContainer) { final IContainer container= (IContainer) fResource; // result.add(new JavaElementProperty(this, "ModificationStamp") { @@ -154,7 +154,7 @@ public class JEResource extends JEAttribute { return children; } }); - + return result.toArray(new JEAttribute[result.size()]); } diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JERoot.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JERoot.java index 17423a320a..4ff1fda5dc 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JERoot.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JERoot.java @@ -38,16 +38,16 @@ public class JERoot extends JEAttribute { return new JEJarEntryResource(null, null, (IJarEntryResource) element); else throw new IllegalArgumentException(String.valueOf(element)); - + } }.mapToList(javaElementsOrResources); - + // fJavaElements= Mapper.build(javaElements, new Mapper<IJavaElement, JavaElement>() { // @Override public JavaElement map(IJavaElement element) { // return new JavaElement(null, element); // } // }); - + // fJavaElements= new ArrayList<JavaElement>(javaElements.size()); // for (IJavaElement javaElement : javaElements) { // fJavaElements.add(new JavaElement(null, javaElement)); @@ -68,7 +68,7 @@ public class JERoot extends JEAttribute { public Object getWrappedObject() { return null; } - + @Override public String getLabel() { StringBuilder buf = new StringBuilder("root: "); @@ -89,11 +89,11 @@ public class JERoot extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + JERoot other= (JERoot) obj; return fJEAttributes.equals(other.fJEAttributes); } - + @Override public int hashCode() { return fJEAttributes.hashCode(); diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEViewLabelProvider.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEViewLabelProvider.java index 4717bb0a82..39642ab168 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEViewLabelProvider.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEViewLabelProvider.java @@ -29,51 +29,51 @@ import org.eclipse.jdt.jeview.JEPluginImages; public class JEViewLabelProvider extends LabelProvider /*implements IColorProvider, IFontProvider*/ { - + JavaElementLabelProvider fJavaElementLabelProvider; private Image fChildrenImg; private Image fInfoImg; - + public JEViewLabelProvider() { fChildrenImg= JEPluginImages.IMG_CHILDREN.createImage(); fInfoImg= JEPluginImages.IMG_INFO.createImage(); fJavaElementLabelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_SMALL_ICONS); } - - + + @Override public String getText(Object element) { if (element instanceof JEAttribute) return ((JEAttribute) element).getLabel(); return super.getText(element); } - + @Override public Image getImage(Object element) { if (element instanceof JavaElement) { return fJavaElementLabelProvider.getImage(((JavaElement) element).getJavaElement()); - + } else if (element instanceof JEResource) { return fJavaElementLabelProvider.getImage(((JEResource) element).getResource()); - + } else if (element instanceof JEJarEntryResource) { return fJavaElementLabelProvider.getImage(((JEJarEntryResource) element).getJarEntryResource()); - + } else if (element instanceof JavaElementProperty) { return fInfoImg; - + } else if (element instanceof JEMemberValuePair) { return fInfoImg; - + } else if (element instanceof JavaElementChildrenProperty) { return fChildrenImg; - + } else if (element instanceof JEClasspathEntry) { return fChildrenImg; - + } else if (element instanceof Error) { return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); - + } else if (element instanceof JEMarker) { JEMarker marker= (JEMarker) element; Object severity= marker.getMarkerAttribute(IMarker.SEVERITY); @@ -89,12 +89,12 @@ public class JEViewLabelProvider extends LabelProvider /*implements IColorProvid } } return null; - + } else { return super.getImage(element); } } - + @Override public void dispose() { super.dispose(); diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElement.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElement.java index 28f2da508d..bd4b046be1 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElement.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElement.java @@ -48,7 +48,7 @@ import org.eclipse.jdt.ui.JavaElementLabels; public class JavaElement extends JEAttribute { - + private static final long LABEL_OPTIONS= JavaElementLabels.F_APP_TYPE_SIGNATURE | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_APP_RETURNTYPE | JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.T_TYPE_PARAMETERS | JavaElementLabels.USE_RESOLVED; private final JEAttribute fParent; //can be null @@ -60,7 +60,7 @@ public class JavaElement extends JEAttribute { fName= name; fJavaElement= element; } - + public JavaElement(JEAttribute parent, IJavaElement element) { this(parent, null, element); } @@ -69,11 +69,11 @@ public class JavaElement extends JEAttribute { public JEAttribute getParent() { return fParent; } - + public IJavaElement getJavaElement() { return fJavaElement; } - + @Override public boolean equals(Object obj) { if (this == obj) @@ -81,7 +81,7 @@ public class JavaElement extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + JavaElement other= (JavaElement) obj; if (fParent == null) { if (other.fParent != null) @@ -89,24 +89,24 @@ public class JavaElement extends JEAttribute { } else if (! fParent.equals(other.fParent)) { return false; } - + if (fName == null) { if (other.fName != null) return false; } else if (! fName.equals(other.fName)) { return false; } - + if (fJavaElement == null) { if (other.fJavaElement != null) return false; } else if (! fJavaElement.equals(other.fJavaElement)) { return false; } - + return true; } - + @Override public int hashCode() { return (fParent != null ? fParent.hashCode() : 0) @@ -118,13 +118,13 @@ public class JavaElement extends JEAttribute { public Object getWrappedObject() { return fJavaElement; } - + @Override public String getLabel() { StringBuilder sb= new StringBuilder(); if (fName != null) sb.append(fName).append(": "); - + if (fJavaElement == null) { sb.append("java element: null"); } else { @@ -141,15 +141,15 @@ public class JavaElement extends JEAttribute { public JEAttribute[] getChildren() { if (fJavaElement == null) return EMPTY; - + ArrayList<JEAttribute> result= new ArrayList<>(); - + if (fJavaElement instanceof IParent) { addParentChildren(result, (IParent) fJavaElement); } - + addJavaElementChildren(result, fJavaElement); - + if (fJavaElement instanceof IJavaModel) addJavaModelChildren(result, (IJavaModel) fJavaElement); if (fJavaElement instanceof IJavaProject) @@ -158,7 +158,7 @@ public class JavaElement extends JEAttribute { addPackageFragmentRootChildren(result, (IPackageFragmentRoot) fJavaElement); if (fJavaElement instanceof IPackageFragment) addPackageFragmentChildren(result, (IPackageFragment) fJavaElement); - + if (fJavaElement instanceof ITypeRoot) addTypeRootChildren(result, (ITypeRoot) fJavaElement); if (fJavaElement instanceof IOrdinaryClassFile) @@ -167,26 +167,26 @@ public class JavaElement extends JEAttribute { addModularClassFileChildren(result, (IModularClassFile) fJavaElement); if (fJavaElement instanceof ICompilationUnit) addCompilationUnitChildren(result, (ICompilationUnit) fJavaElement); - + if (fJavaElement instanceof IType) addTypeChildren(result, (IType) fJavaElement); if (fJavaElement instanceof IMethod) addMethodChildren(result, (IMethod) fJavaElement); if (fJavaElement instanceof IMember) addMemberChildren(result, (IMember) fJavaElement); - + if (fJavaElement instanceof ITypeParameter) addTypeParameterChildren(result, (ITypeParameter) fJavaElement); if (fJavaElement instanceof ILocalVariable) addLocalVariableChildren(result, (ILocalVariable) fJavaElement); - + if (fJavaElement instanceof IAnnotation) addAnnotationChildren(result, (IAnnotation) fJavaElement); if (fJavaElement instanceof IAnnotatable) addAnnotatableChildren(result, (IAnnotatable) fJavaElement); - + return result.toArray(new JEAttribute[result.size()]); - + } private void addParentChildren(ArrayList<JEAttribute> result, final IParent parent) { @@ -296,7 +296,7 @@ public class JavaElement extends JEAttribute { } }); } - + private void addPackageFragmentRootChildren(ArrayList<JEAttribute> result, final IPackageFragmentRoot packageFragmentRoot) { result.add(new JavaElementChildrenProperty(this, "NON JAVA RESOURCES") { @Override @@ -338,7 +338,7 @@ public class JavaElement extends JEAttribute { } }); } - + private void addTypeRootChildren(ArrayList<JEAttribute> result, final ITypeRoot typeRoot) { result.add(JavaElement.compute(this, "FIND PRIMARY TYPE", new Callable<IJavaElement>() { @Override @@ -347,7 +347,7 @@ public class JavaElement extends JEAttribute { } })); } - + private void addClassFileChildren(ArrayList<JEAttribute> result, final IOrdinaryClassFile classFile) { result.add(JavaElement.compute(this, "TYPE", new Callable<IJavaElement>() { @Override @@ -356,7 +356,7 @@ public class JavaElement extends JEAttribute { } })); } - + private void addModularClassFileChildren(ArrayList<JEAttribute> result, final IModularClassFile classFile) { result.add(JavaElement.compute(this, "MODULE", new Callable<IJavaElement>() { @Override @@ -395,7 +395,7 @@ public class JavaElement extends JEAttribute { } }); } - + private void addMemberChildren(ArrayList<JEAttribute> result, final IMember member) { result.add(new JavaElement(this, "CLASS FILE", member.getClassFile())); result.add(new JavaElement(this, "COMPILATION UNIT", member.getCompilationUnit())); @@ -408,7 +408,7 @@ public class JavaElement extends JEAttribute { } }); } - + private void addAnnotationChildren(ArrayList<JEAttribute> result, final IAnnotation annotation) { result.add(new JavaElementChildrenProperty(this, "MEMBER VALUE PAIRS") { @Override @@ -418,7 +418,7 @@ public class JavaElement extends JEAttribute { } }); } - + private void addAnnotatableChildren(ArrayList<JEAttribute> result, final IAnnotatable annotatable) { result.add(new JavaElementChildrenProperty(this, "ANNOTATIONS") { @Override @@ -428,7 +428,7 @@ public class JavaElement extends JEAttribute { } }); } - + private void addTypeChildren(ArrayList<JEAttribute> result, final IType type) { result.add(new JavaElementProperty(this, "IS RESOLVED", type.isResolved())); result.add(new JavaElementProperty(this, "KEY", type.getKey())); @@ -445,14 +445,14 @@ public class JavaElement extends JEAttribute { return createStrings(this, type.getTypeParameterSignatures()); } }); - + result.add(new JavaElementProperty(this, "SUPERCLASS NAME") { @Override protected Object computeValue() throws Exception { return type.getSuperclassName(); } }); - + result.add(new JavaElementProperty(this, "SUPERCLASS TYPE SIGNATURE") { @Override protected Object computeValue() throws Exception { @@ -471,7 +471,7 @@ public class JavaElement extends JEAttribute { return createStrings(this, type.getSuperInterfaceTypeSignatures()); } }); - + result.add(new JavaElementChildrenProperty(this, "FIELDS") { @Override protected JEAttribute[] computeChildren() throws JavaModelException { @@ -541,7 +541,7 @@ public class JavaElement extends JEAttribute { result.add(new Error(this, "DEFAULT_VALUE", e)); } } - + private void addTypeParameterChildren(ArrayList<JEAttribute> result, final ITypeParameter typeParameter) { result.add(new JavaElement(this, "TYPE ROOT", typeParameter.getTypeRoot())); result.add(new JavaElement(this, "DECLARING MEMBER", typeParameter.getDeclaringMember())); @@ -558,12 +558,12 @@ public class JavaElement extends JEAttribute { } }); } - + private void addLocalVariableChildren(ArrayList<JEAttribute> result, final ILocalVariable localVariable) { result.add(new JavaElement(this, "TYPE ROOT", localVariable.getTypeRoot())); result.add(new JavaElement(this, "DECLARING MEMBER", localVariable.getDeclaringMember())); } - + static JavaElement[] createJavaElements(JEAttribute parent, Object[] javaElements) { JavaElement[] jeChildren= new JavaElement[javaElements.length]; for (int i= 0; i < javaElements.length; i++) { @@ -571,7 +571,7 @@ public class JavaElement extends JEAttribute { } return jeChildren; } - + static JavaElement[] createJavaElements(JEAttribute parent, IJavaElement[] javaElements) { JavaElement[] jeChildren= new JavaElement[javaElements.length]; for (int i= 0; i < javaElements.length; i++) { @@ -579,7 +579,7 @@ public class JavaElement extends JEAttribute { } return jeChildren; } - + static JEAttribute[] createResources(JEAttribute parent, Object[] resources) { JEAttribute[] resourceChildren= new JEAttribute[resources.length]; for (int i= 0; i < resources.length; i++) { @@ -593,7 +593,7 @@ public class JavaElement extends JEAttribute { } return resourceChildren; } - + static JEAttribute[] createMemberValuePairs(JEAttribute parent, IMemberValuePair[] mvPairs) { JEAttribute[] mvPairChildren= new JEAttribute[mvPairs.length]; for (int i= 0; i < mvPairs.length; i++) { @@ -602,7 +602,7 @@ public class JavaElement extends JEAttribute { } return mvPairChildren; } - + static JEAttribute[] createCPEntries(JEAttribute parent, IClasspathEntry[] entries) { JEAttribute[] entryChildren= new JEAttribute[entries.length]; for (int i= 0; i < entries.length; i++) { @@ -620,7 +620,7 @@ public class JavaElement extends JEAttribute { return o1.getKey().compareTo(o2.getKey()); } }); - + JEAttribute[] children= new JEAttribute[entries.size()]; for (int i= 0; i < entries.size(); i++) { Entry<String, String> entry= entries.get(i); @@ -628,7 +628,7 @@ public class JavaElement extends JEAttribute { } return children; } - + static JEAttribute[] createStrings(JEAttribute parent, String[] strings) { JEAttribute[] children= new JEAttribute[strings.length]; for (int i= 0; i < strings.length; i++) { @@ -645,7 +645,7 @@ public class JavaElement extends JEAttribute { return new Error(parent, name, e); } } - + public static JEAttribute create(JEAttribute parent, String name, IJavaElement javaElement) { if (javaElement == null) { return new Null(parent, name); diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementChildrenProperty.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementChildrenProperty.java index 600ed5b48d..6e72026061 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementChildrenProperty.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementChildrenProperty.java @@ -36,7 +36,7 @@ public abstract class JavaElementChildrenProperty extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + JavaElementChildrenProperty other= (JavaElementChildrenProperty) obj; if (fParent == null) { if (other.fParent != null) @@ -44,28 +44,28 @@ public abstract class JavaElementChildrenProperty extends JEAttribute { } else if (! fParent.equals(other.fParent)) { return false; } - + if (fName == null) { if (other.fName != null) return false; } else if (! fName.equals(other.fName)) { return false; } - + return true; } - + @Override public int hashCode() { return (fParent != null ? fParent.hashCode() : 0) + (fName != null ? fName.hashCode() : 0); } - + @Override public Object getWrappedObject() { return getChildren().length; } - + @Override public JEAttribute[] getChildren() { try { diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementProperty.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementProperty.java index 2403d6135c..affee894c2 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementProperty.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementProperty.java @@ -47,7 +47,7 @@ public class JavaElementProperty extends JEAttribute { public Object getWrappedObject() { return fValueObject; } - + @Override public boolean equals(Object obj) { if (this == obj) @@ -55,7 +55,7 @@ public class JavaElementProperty extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + JavaElementProperty other= (JavaElementProperty) obj; if (fParent == null) { if (other.fParent != null) @@ -63,28 +63,28 @@ public class JavaElementProperty extends JEAttribute { } else if (! fParent.equals(other.fParent)) { return false; } - + if (fName == null) { if (other.fName != null) return false; } else if (! fName.equals(other.fName)) { return false; } - + return true; } - + @Override public int hashCode() { return (fParent != null ? fParent.hashCode() : 0) + (fName != null ? fName.hashCode() : 0); } - + @Override public JEAttribute[] getChildren() { if (fValue != null) return EMPTY; - + try { computeValue(); return EMPTY; @@ -103,7 +103,7 @@ public class JavaElementProperty extends JEAttribute { return Error.ERROR; } } - + if (fName == null) return value; else diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementView.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementView.java index 5fd6f81388..9e4ba42fb6 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementView.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementView.java @@ -144,7 +144,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT TreeViewer fViewer; private DrillDownAdapter fDrillDownAdapter; JERoot fInput; - + private Action fFocusAction; private Action fFindTypeAction; private Action fFindType2Action; @@ -160,9 +160,9 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT private Action fCompareAction; private Action fPropertiesAction; Action fDoubleClickAction; - + private Action fLogDeltasAction; - + private PropertySheetPage fPropertySheetPage; private static class InputDialog extends org.eclipse.jface.dialogs.InputDialog { @@ -193,7 +193,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT void fireSelectionChanged() { if (fSelectionChangedListeners != null) { IStructuredSelection selection = getSelection(); - + if (fLastSelection != null) { List<?> newSelection = selection.toList(); List<?> oldSelection = fLastSelection.toList(); @@ -214,15 +214,15 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } } fLastSelection= selection; - + SelectionChangedEvent event= new SelectionChangedEvent(this, selection); - + for (ISelectionChangedListener listener : fSelectionChangedListeners) { listener.selectionChanged(event); } } } - + @Override public void addSelectionChangedListener(ISelectionChangedListener listener) { fSelectionChangedListeners.add(listener); @@ -236,7 +236,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT Object element= iter.next(); if (element instanceof JavaElement) { IJavaElement javaElement= ((JavaElement) element).getJavaElement(); - if (javaElement != null && ! (javaElement instanceof IJavaModel)) // various selection listeners assume getJavaProject() is non-null + if (javaElement != null && ! (javaElement instanceof IJavaModel)) // various selection listeners assume getJavaProject() is non-null externalSelection.add(javaElement); } else if (element instanceof JEResource) { IResource resource= ((JEResource) element).getResource(); @@ -262,7 +262,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT //not supported } } - + public JavaElementView() { // } @@ -280,7 +280,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } else { setContentDescription(""); } - + } }; fViewer.setContentProvider(new JEViewContentProvider()); @@ -310,7 +310,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT void setSingleInput(Object javaElementOrResource) { setInput(Collections.singleton(javaElementOrResource)); } - + void setInput(Collection<?> javaElementsOrResources) { fInput= new JERoot(javaElementsOrResources); fViewer.setInput(fInput); @@ -328,7 +328,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT void setEmptyInput() { setInput(Collections.emptySet()); } - + private void hookContextMenu() { MenuManager menuMgr = new MenuManager("#PopupMenu"); menuMgr.setRemoveAllWhenShown(true); @@ -367,7 +367,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT manager.add(fResetAction); manager.add(fRefreshAction); manager.add(new Separator()); - + if (! getSite().getSelectionProvider().getSelection().isEmpty()) { MenuManager showInSubMenu= new MenuManager(getShowInMenuLabel()); IWorkbenchWindow workbenchWindow= getSite().getWorkbenchWindow(); @@ -376,10 +376,10 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } addElementActionsOrNot(manager); manager.add(new Separator()); - + manager.add(fCopyAction); manager.add(new Separator()); - + fDrillDownAdapter.addNavigationActions(manager); manager.add(new Separator()); // Other plug-ins can contribute there actions here @@ -401,7 +401,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT return "Sho&w In" + '\t' + keyBinding; } - + private void addFocusActionOrNot(IMenuManager manager) { if (fViewer.getSelection() instanceof IStructuredSelection) { IStructuredSelection structuredSelection= (IStructuredSelection) fViewer.getSelection(); @@ -425,7 +425,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } } } - + private void addElementActionsOrNot(IMenuManager manager) { if (fViewer.getSelection() instanceof IStructuredSelection) { IStructuredSelection structuredSelection= (IStructuredSelection) fViewer.getSelection(); @@ -448,7 +448,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } } } - + private void addCompareActionOrNot(IMenuManager manager) { if (fViewer.getSelection() instanceof ITreeSelection) { ITreeSelection treeSelection = (ITreeSelection) fViewer.getSelection(); @@ -457,7 +457,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } } } - + private void fillLocalToolBar(IToolBarManager manager) { manager.add(fCodeSelectAction); manager.add(fElementAtAction); @@ -491,7 +491,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT setEmptyInput(); return; } - + IJavaElement[] resolved; try { resolved= codeResolve(javaElement, (ITextSelection) selection); @@ -503,12 +503,12 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT setEmptyInput(); return; } - + setInput(Arrays.asList(resolved)); } }; fCodeSelectAction.setToolTipText("Set input from current editor's selection (codeSelect)"); - + fElementAtAction= new Action("Set Input from Editor location (&getElementAt)", JEPluginImages.IMG_SET_FOCUS) { @Override public void run() { IEditorPart editor= getSite().getPage().getActiveEditor(); @@ -532,7 +532,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT setEmptyInput(); return; } - + IJavaElement resolved; try { resolved= getElementAtOffset(javaElement, (ITextSelection) selection); @@ -544,12 +544,12 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT setEmptyInput(); return; } - + setSingleInput(resolved); } }; fElementAtAction.setToolTipText("Set input from current editor's selection location (getElementAt)"); - + fCreateFromHandleAction= new Action("Create From &Handle...") { @Override public void run() { InputDialog dialog= new InputDialog(getSite().getShell(), "Create Java Element From Handle Identifier", "&Handle identifier:", "", null); @@ -560,7 +560,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT setSingleInput(javaElement); } }; - + fFocusAction= new Action() { @Override public void run() { Object selected= ((IStructuredSelection) fViewer.getSelection()).getFirstElement(); @@ -572,16 +572,16 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } }; fFocusAction.setToolTipText("Focus on Selection"); - + fFindTypeAction= new Action() { @Override public void run() { Object selected= ((IStructuredSelection) fViewer.getSelection()).getFirstElement(); final IJavaProject project= (IJavaProject) ((JavaElement) selected).getJavaElement(); - + InputDialog dialog= new InputDialog(getSite().getShell(), "IJavaProject#findType(String fullyQualifiedName)", "fullyQualifiedName:", "", null); if (dialog.open() != Window.OK) return; - + final String fullyQualifiedName= dialog.getValue(); try { IType type = project.findType(fullyQualifiedName); @@ -594,17 +594,17 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } }; fFindTypeAction.setText("findType(String)..."); - + fFindType2Action= new Action() { @Override public void run() { Object selected= ((IStructuredSelection) fViewer.getSelection()).getFirstElement(); final IJavaProject project= (IJavaProject) ((JavaElement) selected).getJavaElement(); - + InputDialog dialog= new InputDialog(getSite().getShell(), "IJavaProject#findType(String fullyQualifiedName, IProgressMonitor pm)", "fullyQualifiedName:", "", null); if (dialog.open() != Window.OK) return; final String fullyQualifiedName= dialog.getValue(); - + class Runner implements IRunnableWithProgress { IType type; @Override @@ -630,17 +630,17 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } }; fFindType2Action.setText("findType(String, IProgressMonitor)..."); - + fResolveTypeAction= new Action() { @Override public void run() { Object selected= ((IStructuredSelection) fViewer.getSelection()).getFirstElement(); final IType type= (IType) ((JavaElement) selected).getJavaElement(); - + InputDialog dialog= new InputDialog(getSite().getShell(), "IType#resolveType(String typeName)", "typeName:", "", null); if (dialog.open() != Window.OK) return; final String typeName= dialog.getValue(); - + JavaElementChildrenProperty element= new JavaElementChildrenProperty(fInput, "'" + type.getFullyQualifiedName() + "'.resolveType(\"" + typeName +"\")") { @Override protected JEAttribute[] computeChildren() throws Exception { String[][] resolvedTypes= type.resolveType(typeName); @@ -661,17 +661,17 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } }; fResolveTypeAction.setText("resolveType(String)..."); - + fGetAnnotationAction= new Action() { @Override public void run() { Object selected= ((IStructuredSelection) fViewer.getSelection()).getFirstElement(); final IAnnotatable annotatable= (IAnnotatable) ((JavaElement) selected).getJavaElement(); - + InputDialog dialog= new InputDialog(getSite().getShell(), "IAnnotatable#getAnnotation(String name)", "name:", "", null); if (dialog.open() != Window.OK) return; final String name= dialog.getValue(); - + JavaElementChildrenProperty element= new JavaElementChildrenProperty(fInput, "'" + ((IJavaElement) annotatable).getElementName() + "'.getAnnotation(\"" + name +"\")") { @Override protected JEAttribute[] computeChildren() throws Exception { IAnnotation annotation= annotatable.getAnnotation(name); @@ -684,17 +684,17 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } }; fGetAnnotationAction.setText("getAnnotation(String)..."); - + fCreateFromBindingKeyAction= new Action("Create From &Binding Key...") { @Override public void run() { Object selected= ((IStructuredSelection) fViewer.getSelection()).getFirstElement(); final IJavaProject project= (IJavaProject) ((JavaElement) selected).getJavaElement(); - + InputDialog dialog= new InputDialog(getSite().getShell(), "IJavaProject#findElement(String bindingKey, WorkingCopyOwner owner)", "&bindingKey:", "", null); if (dialog.open() != Window.OK) return; final String bindingKey= dialog.getValue(); - + class Runner implements IRunnableWithProgress { IJavaElement element; @Override @@ -719,14 +719,14 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT fViewer.setSelection(new StructuredSelection(element)); } }; - + fResetAction= new Action("&Reset View", getJavaModelImageDescriptor()) { @Override public void run() { reset(); } }; fResetAction.setToolTipText("Reset View to JavaModel"); - + fRefreshAction= new Action("Re&fresh", JEPluginImages.IMG_REFRESH) { @Override public void run() { BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() { @@ -739,9 +739,9 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT }; fRefreshAction.setToolTipText("Refresh"); fRefreshAction.setActionDefinitionId("org.eclipse.ui.file.refresh"); - + fCopyAction= new TreeCopyAction(new Tree[] {fViewer.getTree()}); - + fPropertiesAction= new Action("&Properties", JEPluginImages.IMG_PROPERTIES) { @Override public void run() { @@ -758,14 +758,14 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } }; fPropertiesAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_PROPERTIES); - + fDoubleClickAction = new Action() { private Object fPreviousDouble; @Override public void run() { ISelection selection = fViewer.getSelection(); Object obj = ((IStructuredSelection)selection).getFirstElement(); - + boolean isSecondDoubleClick= (obj == fPreviousDouble); fPreviousDouble= isSecondDoubleClick ? null : obj; @@ -775,7 +775,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT switch (javaElement.getElementType()) { case IJavaElement.JAVA_MODEL : break; - + case IJavaElement.JAVA_PROJECT : case IJavaElement.PACKAGE_FRAGMENT_ROOT : case IJavaElement.PACKAGE_FRAGMENT : @@ -795,7 +795,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT showAndLogError("Could not show element", e1); } break; - + default : try { IEditorPart editorPart= JavaUI.openInEditor(javaElement); @@ -814,11 +814,11 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } } } - + } else if (obj instanceof Error) { Error error= (Error) obj; JEViewPlugin.log(error.getException()); - + } else if (obj instanceof JEMarker) { JEMarker marker= (JEMarker) obj; try { @@ -829,7 +829,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } } }; - + fCompareAction= new Action() { @Override public void run() { TreePath[] selection= ((ITreeSelection) fViewer.getSelection()).getPaths(); @@ -839,16 +839,16 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT boolean equals1= first != null && first.equals(second); boolean equals2= second != null && second.equals(first); boolean inconsistentEquals= equals1 != equals2; - + String msg= "==: " + identical + "\nequals(..): " + (inconsistentEquals ? "INCONSISTENT" : equals1); MessageDialog.openInformation(fViewer.getTree().getShell(), "Comparison", msg); } }; fCompareAction.setText("C&ompare with Each Other..."); - + fLogDeltasAction= new Action("Log Java element deltas", IAction.AS_CHECK_BOX) { - + private IElementChangedListener fListener= new IElementChangedListener() { @Override @SuppressWarnings("deprecation") @@ -871,7 +871,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT JEViewPlugin.logMessage(event.getDelta().toString() + type); } }; - + @Override public void run() { String message; if (!isChecked()) { @@ -884,10 +884,10 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT MessageDialog.openInformation(fViewer.getTree().getShell(), "Log Java Element Deltas", message); } }; - + } - + static IJavaElement[] codeResolve(IJavaElement input, ITextSelection selection) throws JavaModelException { if (input instanceof ICodeAssist) { if (input instanceof ICompilationUnit) { @@ -899,7 +899,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } return new IJavaElement[0]; } - + static IJavaElement getElementAtOffset(IJavaElement input, ITextSelection selection) throws JavaModelException { if (input instanceof ICompilationUnit) { ICompilationUnit cunit= (ICompilationUnit) input; @@ -918,18 +918,18 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } return input; } - + /* see JavaModelUtil.reconcile((ICompilationUnit) input) */ static void reconcile(ICompilationUnit unit) throws JavaModelException { synchronized(unit) { unit.reconcile( - ICompilationUnit.NO_AST, - false /* don't force problem detection */, - null /* use primary owner */, + ICompilationUnit.NO_AST, + false /* don't force problem detection */, + null /* use primary owner */, null /* no progress monitor */); } } - + private ImageDescriptor getJavaModelImageDescriptor() { JavaElementLabelProvider lp= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_SMALL_ICONS); Image modelImage= lp.getImage(getJavaModel()); @@ -946,18 +946,18 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } }); } - + void showAndLogError(String message, CoreException e) { JEViewPlugin.log(message, e); ErrorDialog.openError(getSite().getShell(), "JavaElement View", message, e.getStatus()); //$NON-NLS-1$ } - + void showAndLogError(String message, Exception e) { IStatus status= new Status(IStatus.ERROR, JEViewPlugin.getPluginId(), 0, message, e); JEViewPlugin.log(status); ErrorDialog.openError(getSite().getShell(), "JavaElement View", null, status); //$NON-NLS-1$ } - + void showMessage(String message) { MessageDialog.openInformation( fViewer.getControl().getShell(), @@ -997,7 +997,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } } } - + Object input= context.getInput(); if (input instanceof IEditorInput) { Object elementOfInput= getElementOfInput((IEditorInput)context.getInput()); @@ -1009,13 +1009,13 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT return false; } - + Object getElementOfInput(IEditorInput input) { Object adapted= input.getAdapter(IClassFile.class); if (adapted != null) { return adapted; } - + if (input instanceof IFileEditorInput) { IFile file= ((IFileEditorInput)input).getFile(); IJavaElement javaElement= JavaCore.create(file); @@ -1033,7 +1033,7 @@ public class JavaElementView extends ViewPart implements IShowInSource, IShowInT } return null; } - + @SuppressWarnings("unchecked") @Override public <T> T getAdapter(Class<T> adapter) { diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/Null.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/Null.java index 0fd03793e7..1fa320c4f8 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/Null.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/Null.java @@ -22,7 +22,7 @@ public class Null extends JEAttribute { private final JEAttribute fParent; private final String fName; - + public Null(JEAttribute parent, String name) { Assert.isNotNull(parent); Assert.isNotNull(name); @@ -44,7 +44,7 @@ public class Null extends JEAttribute { public Object getWrappedObject() { return null; } - + @Override public String getLabel() { return fName + ": null"; @@ -57,7 +57,7 @@ public class Null extends JEAttribute { if (obj == null || !obj.getClass().equals(getClass())) { return false; } - + Null other= (Null) obj; if (! fParent.equals(other.fParent)) { return false; @@ -65,10 +65,10 @@ public class Null extends JEAttribute { if (! fName.equals(other.fName)) { return false; } - + return true; } - + @Override public int hashCode() { return fParent.hashCode() + fName.hashCode(); diff --git a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/TreeCopyAction.java b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/TreeCopyAction.java index cc3f3f0e7e..5091fdc70b 100644 --- a/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/TreeCopyAction.java +++ b/org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/TreeCopyAction.java @@ -1,13 +1,13 @@ /******************************************************************************* * Copyright (c) 2000, 2011 IBM Corporation and others. * - * This program and the accompanying materials + * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -78,9 +78,9 @@ public class TreeCopyAction extends Action { return string; } } - + private final Tree[] fTrees; - + public TreeCopyAction(Tree[] trees) { fTrees= trees; setText("&Copy"); //$NON-NLS-1$ @@ -102,11 +102,11 @@ public class TreeCopyAction extends Action { } if (tree == null) return; - + TreeItem[] selection= tree.getSelection(); if (selection.length == 0) return; - + Clipboard clipboard= null; try { clipboard= new Clipboard(tree.getDisplay()); @@ -125,7 +125,7 @@ public class TreeCopyAction extends Action { HashMap<TreeItem, TreeObject> elementToTreeObj= new HashMap<>(); List<TreeObject> roots= new ArrayList<>(); int indent= Integer.MIN_VALUE; - + for (TreeItem item : selection) { TreeObject treeObj= elementToTreeObj.get(item); if (treeObj == null) { diff --git a/org.eclipse.jdt.junit.core/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.junit.core/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.junit.core/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.junit.core/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JUnitCorePlugin.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JUnitCorePlugin.java index b742c72327..0041c7f435 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JUnitCorePlugin.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JUnitCorePlugin.java @@ -51,7 +51,7 @@ public class JUnitCorePlugin extends Plugin { private static JUnitCorePlugin fgPlugin= null; public static final String CORE_PLUGIN_ID= "org.eclipse.jdt.junit.core"; //$NON-NLS-1$ - + /** * Plug-in ID of the <b>UI</b> plug-in ("org.eclipse.jdt.junit"). * @see #CORE_PLUGIN_ID @@ -151,7 +151,7 @@ public class JUnitCorePlugin extends Plugin { /** * Returns a service with the specified name or <code>null</code> if none. - * + * * @param serviceName name of service * @return service object or <code>null</code> if none * @since 3.5 @@ -278,7 +278,7 @@ public class JUnitCorePlugin extends Plugin { */ public ListenerList<TestRunListener> getNewTestRunListeners() { loadTestRunListeners(); - + return fNewTestRunListeners; } diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JUnitPreferencesConstants.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JUnitPreferencesConstants.java index de2d5fb45a..3131202303 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JUnitPreferencesConstants.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/JUnitPreferencesConstants.java @@ -98,7 +98,7 @@ public class JUnitPreferencesConstants { * Javadoc location for org.junit.jupiter.params (JUnit 5) */ public static final String JUNIT_JUPITER_PARAMS_JAVADOC= JUnitCorePlugin.PLUGIN_ID + ".junit5.jupiter.params.javadoclocation"; //$NON-NLS-1$ - + /** * Javadoc location for org.junit.platform.commons (JUnit 5) */ @@ -187,10 +187,10 @@ public class JUnitPreferencesConstants { } return buffer.toString(); } - + /** * Parses the comma-separated string into an array of strings. - * + * * @param listString a comma-separated string * @return an array of strings */ diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java index 409b9cb2d8..849f368759 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/BuildPathSupport.java @@ -49,9 +49,9 @@ import org.eclipse.jdt.internal.junit.JUnitPreferencesConstants; public class BuildPathSupport { - + public static class JUnitPluginDescription { - + private final String bundleId; private final VersionRange versionRange; private final String bundleRoot; @@ -59,7 +59,7 @@ public class BuildPathSupport { private final String sourceBundleId; private final String repositorySource; private final String javadocPreferenceKey; - + private String resolvedVersion = null; public JUnitPluginDescription(String bundleId, VersionRange versionRange, String bundleRoot, String binaryImportedRoot, String sourceBundleId, String repositorySource, String javadocPreferenceKey) { @@ -71,11 +71,11 @@ public class BuildPathSupport { this.repositorySource= repositorySource; this.javadocPreferenceKey= javadocPreferenceKey; } - + public IPath getBundleLocation() { return getBundleLocation(bundleId, versionRange); } - + public IPath getSourceBundleLocation() { return getSourceLocation(getBundleLocation()); } @@ -83,7 +83,7 @@ public class BuildPathSupport { private IPath getBundleLocation(String aBundleId, VersionRange aVersionRange) { return getBundleLocation(aBundleId, aVersionRange, false); } - + private IPath getBundleLocation(String aBundleId, VersionRange aVersionRange, boolean isSourceBundle) { BundleInfo bundleInfo = P2Utils.findBundle(aBundleId, aVersionRange, isSourceBundle); if (bundleInfo != null) { @@ -114,7 +114,7 @@ public class BuildPathSupport { } return null; } - + private IPath getBundleFileLocation(String aBundleId, VersionRange aVersionRange, String filePath) { BundleInfo bundleInfo = P2Utils.findBundle(aBundleId, aVersionRange, false); @@ -222,7 +222,7 @@ public class BuildPathSupport { } else { attributes= new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocLocation) }; } - + return JavaCore.newLibraryEntry(bundleRootLocation, srcLocation, null, getAccessRules(), attributes, false); } return null; @@ -238,7 +238,7 @@ public class BuildPathSupport { // Try source in workspace (from repository) srcLocation= getLocationIfExists(bundleLocation, repositorySource); } - + if (srcLocation == null) { if (bundleLocation != null) { // Try exact version @@ -288,13 +288,13 @@ public class BuildPathSupport { } } - + public static final JUnitPluginDescription JUNIT3_PLUGIN= new JUnitPluginDescription( "org.junit", new VersionRange("[3.8.2,3.9)"), "junit.jar", "junit.jar", "org.junit.source", "source-bundle/", JUnitPreferencesConstants.JUNIT3_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - + public static final JUnitPluginDescription JUNIT4_PLUGIN= new JUnitPluginDescription( "org.junit", new VersionRange("[4.7.0,5.0.0)"), "junit.jar", "junit.jar", "org.junit.source", "source-bundle/", JUnitPreferencesConstants.JUNIT4_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - + private static final JUnitPluginDescription HAMCREST_CORE_PLUGIN= new JUnitPluginDescription( "org.hamcrest.core", new VersionRange("[1.1.0,2.0.0)"), null, "org.hamcrest.core_1.*.jar", "org.hamcrest.core.source", "source-bundle/", JUnitPreferencesConstants.HAMCREST_CORE_JAVADOC); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ @@ -357,7 +357,7 @@ public class BuildPathSupport { }; } }; - + /** * @return the JUnit3 classpath container */ @@ -400,7 +400,7 @@ public class BuildPathSupport { public static IClasspathEntry getJUnit4as3LibraryEntry() { return JUNIT4_AS_3_PLUGIN.getLibraryEntry(); } - + /** * @return the org.hamcrest.core library, or <code>null</code> if not available */ @@ -477,7 +477,7 @@ public class BuildPathSupport { public static IClasspathEntry getJUnitVintageEngineLibraryEntry() { return JUNIT_VINTAGE_ENGINE_PLUGIN.getLibraryEntry(); } - + /** * @return the org.opentest4j library, or <code>null</code> if not available */ diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerInitializer.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerInitializer.java index 93bf572c43..b973cfac99 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerInitializer.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerInitializer.java @@ -185,11 +185,11 @@ public class JUnitContainerInitializer extends ClasspathContainerInitializer { @Override public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { IEclipsePreferences preferences= InstanceScope.INSTANCE.getNode(JUnitCorePlugin.CORE_PLUGIN_ID); - + IClasspathEntry[] entries= containerSuggestion.getClasspathEntries(); if (entries.length >= 1 && isValidJUnitContainerPath(containerPath)) { String version= containerPath.segment(1); - + // only modifiable entry is Javadoc location for (IClasspathEntry entry : entries) { String preferenceKey= getPreferenceKey(entry, version); @@ -200,7 +200,7 @@ public class JUnitContainerInitializer extends ClasspathContainerInitializer { if (!defaultValue.equals(preferences.get(preferenceKey, defaultValue))) { preferences.put(preferenceKey, defaultValue); } - + /* * The following would be correct, but would not allow to revert to the default. * There's no concept of "default value" for a classpath attribute, see diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitHomeInitializer.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitHomeInitializer.java index a31e1dd4be..8cea25a392 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitHomeInitializer.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/JUnitHomeInitializer.java @@ -57,7 +57,7 @@ public class JUnitHomeInitializer extends ClasspathVariableInitializer { IPath sourceLocation= BuildPathSupport.JUNIT3_PLUGIN.getSourceBundleLocation(); if (sourceLocation == null) sourceLocation= BuildPathSupport.JUNIT4_PLUGIN.getSourceBundleLocation(); // JUnit 4 includes most of JUnit 3, so let's cheat - + if (sourceLocation != null) { JavaCore.setClasspathVariable(JUnitCorePlugin.JUNIT_SRC_HOME, sourceLocation, null); } else { diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/P2Utils.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/P2Utils.java index e49efd35e2..1321800bf7 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/P2Utils.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/buildpath/P2Utils.java @@ -37,7 +37,7 @@ import org.eclipse.jdt.internal.junit.JUnitCorePlugin; /** * Utilities to read and write bundle and source information files. - * + * * @since 3.5 */ class P2Utils { @@ -47,7 +47,7 @@ class P2Utils { * <p> * The first match will be returned if more than one bundle matches the arguments. * </p> - * + * * @param symbolicName the symbolic name * @param version the bundle version * @param isSourceBundle <code>true</code> if it is a source bundle <code>false</code> otherwise @@ -65,7 +65,7 @@ class P2Utils { * <p> * The best match (latest version) will be returned if more than one bundle matches the arguments. * </p> - * + * * @param symbolicName the symbolic name * @param versionRange the version range for the bundle version * @param isSourceBundle <code>true</code> if it is a source bundle <code>false</code> otherwise @@ -94,7 +94,7 @@ class P2Utils { } catch (IOException e) { JUnitCorePlugin.log(e); } - + if (bundles != null) { for (BundleInfo bundleInfo : bundles) { if (symbolicName.equals(bundleInfo.getSymbolicName())) { @@ -117,18 +117,18 @@ class P2Utils { /** * Returns the bundle location path. - * + * * @param bundleInfo the bundle info or <code>null</code> * @return the bundle location or <code>null</code> if it is not possible to convert to a path */ public static IPath getBundleLocationPath(BundleInfo bundleInfo) { if (bundleInfo == null) return null; - + URI bundleLocation= bundleInfo.getLocation(); if (bundleLocation == null) return null; - + try { URL localFileURL= FileLocator.toFileURL(URIUtil.toURL(bundleLocation)); URI localFileURI= new URI(localFileURL.toExternalForm()); diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit4TestFinder.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit4TestFinder.java index 0ed32aafc1..cd86a32b30 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit4TestFinder.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/launcher/JUnit4TestFinder.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * David Saff (saff@mit.edu) - initial API and implementation * (bug 102632: [JUnit] Support for JUnit 4.) diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/ITestRunListener2.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/ITestRunListener2.java index c5a0eeba93..e20179e408 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/ITestRunListener2.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/ITestRunListener2.java @@ -87,7 +87,7 @@ public interface ITestRunListener2 { * displayName: the display name of the test * parameterTypes: comma-separated list of method parameter types if applicable, otherwise an empty string * uniqueId: the unique ID of the test provided by JUnit launcher, otherwise an empty string - * + * * Example: 324968,testPass(junit.tests.MyTest),false,1,false,-1,A simple test case,"","" * </pre> * diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/JUnitModel.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/JUnitModel.java index 5f31e0f608..0d080c230f 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/JUnitModel.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/JUnitModel.java @@ -137,7 +137,7 @@ public final class JUnitModel { private void connectTestRunner(ILaunch launch, IJavaProject javaProject, int port) { TestRunSession testRunSession= new TestRunSession(launch, javaProject, port); addTestRunSession(testRunSession); - + for (TestRunListener listener : JUnitCorePlugin.getDefault().getNewTestRunListeners()) { listener.sessionLaunched(testRunSession); } @@ -351,11 +351,11 @@ public final class JUnitModel { public void addTestRunSession(TestRunSession testRunSession) { Assert.isNotNull(testRunSession); ArrayList<TestRunSession> toRemove= new ArrayList<>(); - + synchronized (this) { Assert.isLegal(! fTestRunSessions.contains(testRunSession)); fTestRunSessions.addFirst(testRunSession); - + int maxCount = Platform.getPreferencesService().getInt(JUnitCorePlugin.CORE_PLUGIN_ID, JUnitPreferencesConstants.MAX_TEST_RUNS, 10, null); int size= fTestRunSessions.size(); if (size > maxCount) { @@ -369,7 +369,7 @@ public final class JUnitModel { } } } - + for (int i= 0; i < toRemove.size(); i++) { TestRunSession oldSession= toRemove.get(i); notifyTestRunSessionRemoved(oldSession); @@ -421,10 +421,10 @@ public final class JUnitModel { monitor.beginTask(ModelMessages.JUnitModel_importing_from_url, IProgressMonitor.UNKNOWN); final String trimmedUrl= url.trim().replaceAll("\r\n?|\n", ""); //$NON-NLS-1$ //$NON-NLS-2$ final TestRunHandler handler= new TestRunHandler(monitor); - + final CoreException[] exception= { null }; final TestRunSession[] session= { null }; - + Thread importThread= new Thread("JUnit URL importer") { //$NON-NLS-1$ @Override public void run() { @@ -453,7 +453,7 @@ public final class JUnitModel { } }; importThread.start(); - + while (session[0] == null && exception[0] == null && !monitor.isCanceled()) { try { Thread.sleep(100); @@ -469,7 +469,7 @@ public final class JUnitModel { throw new InterruptedException(); } } - + JUnitCorePlugin.getModel().addTestRunSession(session[0]); monitor.done(); return session[0]; diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/RemoteTestRunnerClient.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/RemoteTestRunnerClient.java index b5f4977213..f57b4091c6 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/RemoteTestRunnerClient.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/RemoteTestRunnerClient.java @@ -38,7 +38,7 @@ import org.eclipse.jdt.internal.junit.runner.RemoteTestRunner; * marshaling of the different messages. */ public class RemoteTestRunnerClient { - + public abstract class ListenerSafeRunnable implements ISafeRunnable { @Override public void handleException(Throwable exception) { @@ -570,7 +570,7 @@ public class RemoteTestRunnerClient { /** * Returns a comparison result from the given buffer. * Removes the terminating line delimiter. - * + * * @param buf the comparison result * @return the result or <code>null</code> if empty * @since 3.7 @@ -579,7 +579,7 @@ public class RemoteTestRunnerClient { int length= buf.length(); if (length == 0) return null; - + char last= buf.charAt(length - 1); if (last == '\n') { if (length > 1 && buf.charAt(length - 2) == '\r') @@ -591,7 +591,7 @@ public class RemoteTestRunnerClient { } return buf.toString(); } - + private void notifyTestRunTerminated() { // fix for 77771 RemoteTestRunnerClient doing work after junit shutdown [JUnit] if (JUnitCorePlugin.isStopped()) diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestCaseElement.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestCaseElement.java index d7394ea741..2f60518c2a 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestCaseElement.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestCaseElement.java @@ -69,7 +69,7 @@ public class TestCaseElement extends TestElement implements ITestCaseElement { else return super.getTestResult(includeChildren); } - + public void setIgnored(boolean ignored) { fIgnored= ignored; } diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java index 918e437018..6731e2cf21 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java @@ -397,7 +397,7 @@ public abstract class TestElement implements ITestElement { /** * Returns the display name of the test. Can be <code>null</code>. In that case, use * {@link TestElement#getTestName() getTestName()}. - * + * * @return the test display name, can be <code>null</code> */ public String getDisplayName() { @@ -416,7 +416,7 @@ public abstract class TestElement implements ITestElement { /** * Returns the unique ID of the test element. Can be <code>null</code> as it is applicable to JUnit * 5 and above. - * + * * @return the unique ID of the test, can be <code>null</code> */ public String getUniqueId() { diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunHandler.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunHandler.java index ba97cef732..e0fdf19ac2 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunHandler.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunHandler.java @@ -72,7 +72,7 @@ public class TestRunHandler extends DefaultHandler { public TestRunHandler(IProgressMonitor monitor) { fMonitor= monitor; } - + public TestRunHandler(TestRunSession testRunSession) { fTestRunSession= testRunSession; } @@ -98,7 +98,7 @@ public class TestRunHandler extends DefaultHandler { } if (Thread.interrupted()) throw new OperationCanceledException(); - + switch (qName) { case IXMLTags.NODE_TESTRUN: if (fTestRunSession == null) { diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSession.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSession.java index f03c0e7c68..cc0c5d352e 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSession.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSession.java @@ -731,7 +731,7 @@ public class TestRunSession implements ITestRunSession { @Override public void testEnded(String testId, String testName) { boolean isIgnored= testName.startsWith(MessageIds.IGNORED_TEST_PREFIX); - + TestElement testElement= getTestElement(testId); if (testElement == null) { testElement= createUnrootedTestElement(testId, testName); diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSessionSerializer.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSessionSerializer.java index 7c63a54605..1f10996e12 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSessionSerializer.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSessionSerializer.java @@ -90,7 +90,7 @@ public class TestRunSessionSerializer implements XMLReader { addCDATA(atts, IXMLTags.ATTR_INCLUDE_TAGS, includeTags); } String excludeTags= fTestRunSession.getExcludeTags(); - if (excludeTags != null && !excludeTags.trim().isEmpty()) { + if (excludeTags != null && !excludeTags.trim().isEmpty()) { addCDATA(atts, IXMLTags.ATTR_EXCLUDE_TAGS, excludeTags); } startElement(IXMLTags.NODE_TESTRUN, atts); @@ -174,14 +174,14 @@ public class TestRunSessionSerializer implements XMLReader { private void addFailure(TestElement testElement) throws SAXException { FailureTrace failureTrace= testElement.getFailureTrace(); - + if (testElement.isAssumptionFailure()) { startElement(IXMLTags.NODE_SKIPPED, NO_ATTS); if (failureTrace != null) { addCharacters(failureTrace.getTrace()); } endElement(IXMLTags.NODE_SKIPPED); - + } else if (failureTrace != null) { AttributesImpl failureAtts= new AttributesImpl(); // addCDATA(failureAtts, IXMLTags.ATTR_MESSAGE, xx); @@ -226,10 +226,10 @@ public class TestRunSessionSerializer implements XMLReader { string= escapeNonUnicodeChars(string); fHandler.characters(string.toCharArray(), 0, string.length()); } - + /** * Replaces all non-Unicode characters in the given string. - * + * * @param string a string * @return string with Java-escapes * @since 3.6 diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/util/CoreTestSearchEngine.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/util/CoreTestSearchEngine.java index 9bdb3897e6..8eb320a186 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/util/CoreTestSearchEngine.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/util/CoreTestSearchEngine.java @@ -266,7 +266,7 @@ public class CoreTestSearchEngine { new SearchEngine().search(suitePattern, participants, scope, requestor, pm); } - + // --- copied from org.eclipse.jdt.internal.corext.util.JavaModelUtil: --- /** * @param version1 the first version @@ -299,7 +299,7 @@ public class CoreTestSearchEngine { /** * Checks if the given project or workspace has source compliance 1.8 or greater. - * + * * @param project the project to test or <code>null</code> to test the workspace settings * @return <code>true</code> if the given project or workspace has source compliance 1.8 or * greater. diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/JUnitCore.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/JUnitCore.java index dd643e105b..6129a95c5a 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/JUnitCore.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/JUnitCore.java @@ -61,31 +61,31 @@ public class JUnitCore { /** * ID of the JUnit {@linkplain IClasspathContainer classpath container}. * The general format of classpath entries using this container is unspecified. - * + * * @see #JUNIT3_CONTAINER_PATH * @see #JUNIT4_CONTAINER_PATH * @see #JUNIT5_CONTAINER_PATH * @since 3.6 */ public static final String JUNIT_CONTAINER_ID= "org.eclipse.jdt.junit.JUNIT_CONTAINER"; //$NON-NLS-1$ - + /** * Path of the JUnit 3 {@linkplain IClasspathContainer classpath container}. - * + * * @since 3.6 */ public final static IPath JUNIT3_CONTAINER_PATH= new Path(JUNIT_CONTAINER_ID).append("3"); //$NON-NLS-1$ - + /** * Path of the JUnit 4 {@linkplain IClasspathContainer classpath container}. - * + * * @since 3.6 */ public final static IPath JUNIT4_CONTAINER_PATH= new Path(JUNIT_CONTAINER_ID).append("4"); //$NON-NLS-1$ /** * Path of the JUnit 5 {@linkplain IClasspathContainer classpath container}. - * + * * @since 3.10 */ public final static IPath JUNIT5_CONTAINER_PATH= new Path(JUNIT_CONTAINER_ID).append("5"); //$NON-NLS-1$ @@ -138,14 +138,14 @@ public class JUnitCore { /** * Finds types that contain JUnit tests in the given container. - * + * * @param container the container * @param monitor the progress monitor used to report progress and request cancelation, * or <code>null</code> if none * @return test types inside the given container * @throws CoreException when a problem occurs while accessing <code>container</code> or its children * @throws OperationCanceledException if the operation has been canceled - * + * * @since 3.5 */ public static IType[] findTestTypes(IJavaElement container, IProgressMonitor monitor) throws CoreException, OperationCanceledException { @@ -158,11 +158,11 @@ public class JUnitCore { /** * Exports the given test run session into an XML report file. - * + * * @param testRunSession the test run session * @param file the destination * @throws CoreException if an error occurred - * + * * @since 3.7 */ public static void exportTestRunSession(ITestRunSession testRunSession, File file) throws CoreException { @@ -171,17 +171,17 @@ public class JUnitCore { /** * Exports the given test run session to an output stream. - * + * * @param testRunSession the test run session * @param output the output stream * @throws CoreException if an error occurred - * + * * @since 3.7 */ public static void exportTestRunSession(ITestRunSession testRunSession, OutputStream output) throws CoreException { try { JUnitModel.exportTestRunSession((TestRunSession)testRunSession, output); - + } catch (TransformerException exception) { String pluginID= JUnitCorePlugin.getPluginId(); String message= ModelMessages.JUnitModel_could_not_export; @@ -191,11 +191,11 @@ public class JUnitCore { /** * Imports a test run session from the given file. - * + * * @param file a file containing a test run session transcript * @return the imported test run session * @throws CoreException if the import failed - * + * * @since 3.7 */ public static ITestRunSession importTestRunSession(File file) throws CoreException { @@ -204,24 +204,24 @@ public class JUnitCore { /** * Imports a test run session from the given URL. - * + * * @param url an URL to a test run session transcript * @param monitor a progress monitor for cancellation * @return the imported test run session, or <code>null</code> if the import has been cancelled * @throws CoreException if the import failed - * + * * @since 3.7 */ public static ITestRunSession importTestRunSession(final String url, IProgressMonitor monitor) throws CoreException { try { return JUnitModel.importTestRunSession(url, monitor); - + } catch (InvocationTargetException exception) { String pluginID= JUnitCorePlugin.getPluginId(); String message= ModelMessages.JUnitModel_could_not_import; Throwable throwable= exception.getCause() != null ? exception.getCause() : exception; throw new CoreException(new Status(IStatus.ERROR, pluginID, message, throwable)); - + } catch (InterruptedException interrupt) { return null; } diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/TestRunListener.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/TestRunListener.java index 858189e0db..2fcf3f0964 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/TestRunListener.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/TestRunListener.java @@ -21,7 +21,7 @@ import org.eclipse.jdt.junit.model.ITestRunSession; * or as a contribution to the <code>org.eclipse.jdt.junit.testRunListeners</code> extension point. * The latter approach has the advantage that the contributing plug-in is automatically loaded when a test run starts. * <p> - * A test run starts with the call to {@link #sessionLaunched(ITestRunSession)} and + * A test run starts with the call to {@link #sessionLaunched(ITestRunSession)} and * {@link #sessionStarted(ITestRunSession)}, followed by calls to * {@link #testCaseStarted(ITestCaseElement)} and {@link #testCaseFinished(ITestCaseElement)} * for all test cases contained in the tree. @@ -34,7 +34,7 @@ import org.eclipse.jdt.junit.model.ITestRunSession; * @since 3.3 */ public abstract class TestRunListener { - + /** * A test run session has been launched. The test tree is not available yet. * <p> @@ -47,7 +47,7 @@ public abstract class TestRunListener { */ public void sessionLaunched(ITestRunSession session) { } - + /** * A test run session has started. The test tree can be accessed through the session element. * <p> diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationDelegate.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationDelegate.java index e9d1bcc277..30e6890a3e 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationDelegate.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationDelegate.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation * David Saff (saff@mit.edu) - bug 102632: [JUnit] Support for JUnit 4. @@ -170,7 +170,7 @@ public class JUnitLaunchConfigurationDelegate extends AbstractJavaLaunchConfigur } String mainTypeName= verifyMainTypeName(configuration); - + File workingDir = verifyWorkingDirectory(configuration); String workingDirName = null; @@ -221,7 +221,7 @@ public class JUnitLaunchConfigurationDelegate extends AbstractJavaLaunchConfigur runConfig.setWorkingDirectory(workingDirName); runConfig.setVMSpecificAttributesMap(vmAttributesMap); runConfig.setPreviewEnabled(supportsPreviewFeatures(configuration)); - + if (!JavaRuntime.isModularConfiguration(configuration)) { // Bootpath runConfig.setBootClassPath(getBootpath(configuration)); @@ -447,7 +447,7 @@ public class JUnitLaunchConfigurationDelegate extends AbstractJavaLaunchConfigur programArguments.add("-packageNameFile"); //$NON-NLS-1$ programArguments.add(fileName); for (String pkgName : pkgNames) { - if (!DEFAULT.equals(pkgName)) { // skip --add-opens for default package + if (!DEFAULT.equals(pkgName)) { // skip --add-opens for default package collectAddOpensVmArgs(addOpensTargets, addOpensVmArgs, pkgName, configuration); } } @@ -534,7 +534,7 @@ public class JUnitLaunchConfigurationDelegate extends AbstractJavaLaunchConfigur IJavaProject javaProject= getJavaProject(configuration); String sourceModuleName= javaProject.getModuleDescription().getElementName(); addOpensVmArgs.add("--add-opens"); //$NON-NLS-1$ - addOpensVmArgs.add(sourceModuleName + "/" + pkgName + "=" + addOpensTargets); //$NON-NLS-1$ //$NON-NLS-2$ + addOpensVmArgs.add(sourceModuleName + "/" + pkgName + "=" + addOpensTargets); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -648,7 +648,7 @@ public class JUnitLaunchConfigurationDelegate extends AbstractJavaLaunchConfigur * launch(...)} has been replaced with the call to * {@link JUnitLaunchConfigurationDelegate#getClasspathAndModulepath(ILaunchConfiguration) * getClasspathAndModulepath(ILaunchConfiguration)}. - * + * */ @Override @Deprecated diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestElement.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestElement.java index a9fdfa856b..a8a5beafd4 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestElement.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestElement.java @@ -184,10 +184,10 @@ public interface ITestElement { * <strong>Note:</strong> The elapsed time is only valid for * {@link ITestElement.ProgressState#COMPLETED} test elements. * </p> - * + * * @return total execution time for the test element in seconds, or {@link Double#NaN} if * the state of the element is not {@link ITestElement.ProgressState#COMPLETED} - * + * * @since 3.4 */ public double getElapsedTimeInSeconds(); diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestRunSession.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestRunSession.java index 2696750e3c..74df9ddf93 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestRunSession.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestRunSession.java @@ -37,7 +37,7 @@ public interface ITestRunSession extends ITestElementContainer { /** * Returns the Java project from which this test run session has been launched, or <code>null</code> if not available. - * + * * @return the launched project, or <code>null</code> is not available. * @since 3.6 */ diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestSuiteElement.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestSuiteElement.java index 0e06e6c7f0..74725d7dd7 100644 --- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestSuiteElement.java +++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/junit/model/ITestSuiteElement.java @@ -29,7 +29,7 @@ public interface ITestSuiteElement extends ITestElementContainer { /** * Returns the name of the suite. This is either the qualified type name of the * suite class, or a custom name if one has been set. - * + * * @return the name of the suite */ public String getSuiteTypeName(); diff --git a/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/MessageIds.java b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/MessageIds.java index f68b68688e..bb24f00b69 100644 --- a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/MessageIds.java +++ b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/MessageIds.java @@ -121,7 +121,7 @@ public class MessageIds { * uniqueId = the unique ID of the test provided by JUnit launcher, otherwise an empty string * <br> * See: ITestRunListener2#testTreeEntry - * + * */ public static final String TEST_TREE= "%TSTTREE"; //$NON-NLS-1$ /** diff --git a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/RemoteTestRunner.java b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/RemoteTestRunner.java index 2c29c19c72..5da9e10488 100644 --- a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/RemoteTestRunner.java +++ b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/RemoteTestRunner.java @@ -405,7 +405,7 @@ public class RemoteTestRunner implements MessageSender, IVisitsTestTrees { } } } - + private void readTestNames(String testNameFile) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(new File(testNameFile)), "UTF-8")); //$NON-NLS-1$ try { @@ -590,8 +590,8 @@ public class RemoteTestRunner implements MessageSender, IVisitsTestTrees { } public void visitTreeEntry(ITestIdentifier identifier, boolean hasChildren, int testCount, boolean isDynamicTest, String parentId) { - String treeEntry= getTestId(identifier) + ',' + escapeText(identifier.getName()) + ',' + hasChildren + ',' + testCount - + ',' + isDynamicTest + ',' + parentId + ',' + escapeText(identifier.getDisplayName()) + ',' + escapeText(identifier.getParameterTypes()) + String treeEntry= getTestId(identifier) + ',' + escapeText(identifier.getName()) + ',' + hasChildren + ',' + testCount + + ',' + isDynamicTest + ',' + parentId + ',' + escapeText(identifier.getDisplayName()) + ',' + escapeText(identifier.getParameterTypes()) + ',' + escapeText(identifier.getUniqueId()); notifyTestTreeEntry(treeEntry); } diff --git a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/TestReferenceFailure.java b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/TestReferenceFailure.java index 395deda259..22205d7190 100644 --- a/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/TestReferenceFailure.java +++ b/org.eclipse.jdt.junit.runtime/src/org/eclipse/jdt/internal/junit/runner/TestReferenceFailure.java @@ -60,7 +60,7 @@ public class TestReferenceFailure { @Override public String toString() { return fStatus + " " + RemoteTestRunner.escapeText(fTest.getName()) //$NON-NLS-1$ - + " " + RemoteTestRunner.escapeText(fTest.getParameterTypes()); //$NON-NLS-1$ + + " " + RemoteTestRunner.escapeText(fTest.getParameterTypes()); //$NON-NLS-1$ } public void setComparison(FailedComparison comparison) { diff --git a/org.eclipse.jdt.junit/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.junit/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.junit/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.junit/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerWizardPage.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerWizardPage.java index db74459b6d..f42b8507e3 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerWizardPage.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/buildpath/JUnitContainerWizardPage.java @@ -175,7 +175,7 @@ public class JUnitContainerWizardPage extends NewElementWizardPage implements IC setControl(composite); } - + @Override public void setVisible(boolean visible) { super.setVisible(visible); diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/FailureTrace.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/FailureTrace.java index b7f3663c27..8cd93be331 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/FailureTrace.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/FailureTrace.java @@ -46,7 +46,7 @@ import org.eclipse.jdt.internal.junit.model.TestElement; * A pane that shows a stack trace of a failed test. */ public class FailureTrace implements IMenuListener { - + /** * Internal property change listener for handling workbench font changes. */ @@ -113,7 +113,7 @@ public class FailureTrace implements IMenuListener { } } }); - + fFontPropertyChangeListener = new FontPropertyChangeListener(); JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener); diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.java index 17773c2a52..fc60daa494 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitMessages.java @@ -168,23 +168,23 @@ public final class JUnitMessages extends NLS { public static String JUnitLaunchConfigurationTab_testdialog_message; public static String JUnitLaunchConfigurationTab_testdialog_title; - + public static String JUnitLaunchConfigurationTab_addtag_label; - + public static String JUnitLaunchConfigurationTab_addtag_text; - + public static String JUnitLaunchConfigurationTab_includetag_checkbox_label; - + public static String JUnitLaunchConfigurationTab_excludetag_checkbox_label; - + public static String JUnitLaunchConfigurationTab_includetags_description; - + public static String JUnitLaunchConfigurationTab_excludetags_description; - + public static String JUnitLaunchConfigurationTab_addincludeexcludetagdialog_title; - + public static String JUnitLaunchConfigurationTab_includetag_empty_error; - + public static String JUnitLaunchConfigurationTab_excludetag_empty_error; public static String JUnitLaunchShortcut_dialog_title; diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java index da4a3991b9..f78bfcadcf 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java @@ -256,7 +256,7 @@ public class JUnitPlugin extends AbstractUIPlugin { /** * Returns a service with the specified name or <code>null</code> if none. - * + * * @param serviceName name of service * @return service object or <code>null</code> if none * @since 3.5 @@ -343,7 +343,7 @@ public class JUnitPlugin extends AbstractUIPlugin { } return section; } - + public static void asyncShowTestRunnerViewPart() { getDisplay().asyncExec(new Runnable() { @Override @@ -372,7 +372,7 @@ public class JUnitPlugin extends AbstractUIPlugin { return null; } } - + private static Display getDisplay() { // Shell shell= getActiveWorkbenchShell(); // if (shell != null) { diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPreferencePage.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPreferencePage.java index a493405604..8c8a33a804 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPreferencePage.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPreferencePage.java @@ -374,7 +374,7 @@ public class JUnitPreferencePage extends PreferencePage implements IWorkbenchPre SWTUtil.setButtonDimensionHint(fShowInAllViewsCheckBox); setShowInAllViewsCheckBoxSelection(JUnitUIPreferencesConstants.getShowInAllViews()); } - + /** * Programatic access to enable assertions checkbox * @return boolean indicating check box selected or not @@ -390,11 +390,11 @@ public class JUnitPreferencePage extends PreferencePage implements IWorkbenchPre public boolean getShowInAllViewsCheckBoxSelection() { return fShowInAllViewsCheckBox.getSelection(); } - + public void setShowInAllViewsCheckBoxSelection(boolean selected) { fShowInAllViewsCheckBox.setSelection(selected); } - + /* * Create a group to contain the step filter related widgets */ diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java index e648ce92f2..19d77a2773 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java @@ -162,7 +162,7 @@ public class JUnitQuickFixProcessor implements IQuickFixProcessor { qualifiedName= "org.junit.jupiter.api.TestFactory"; //$NON-NLS-1$ break; case "Testable": //$NON-NLS-1$ - qualifiedName= "org.junit.platform.commons.annotation.Testable"; //$NON-NLS-1$ + qualifiedName= "org.junit.platform.commons.annotation.Testable"; //$NON-NLS-1$ break; case "TestTemplate": //$NON-NLS-1$ qualifiedName= "org.junit.jupiter.api.TestTemplate"; //$NON-NLS-1$ diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitUIPreferencesConstants.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitUIPreferencesConstants.java index 36b3df22a9..3cbdda0142 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitUIPreferencesConstants.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitUIPreferencesConstants.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.preferences.InstanceScope; /** * Defines constants which are used to refer to values in the plugin's preference store. - * + * * @since 3.7 */ public class JUnitUIPreferencesConstants { diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/OpenTestAction.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/OpenTestAction.java index 99a17d9a2a..2fccc7e0b9 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/OpenTestAction.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/OpenTestAction.java @@ -113,7 +113,7 @@ public class OpenTestAction extends OpenEditorAction { if (testCase.isIgnored() && JavaConventions.validateJavaTypeName(testCase.getTestName(), JavaCore.VERSION_1_5, JavaCore.VERSION_1_5).getSeverity() != IStatus.ERROR) { return null; } - + //workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=275308 : String testMethodName= testCase.getTestMethodName(); for (int i= 0; i < testMethodName.length(); i++) { diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java index ef68136809..aba2a3e11e 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java @@ -111,13 +111,13 @@ public class TestViewer { return ! fTestRunSession.isRunning() && status == Status.RUNNING; // rerunning } } - + private final class IgnoredOnlyFilter extends ViewerFilter { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return select(((TestElement) element)); } - + public boolean select(TestElement testElement) { if (hasIgnoredInTestResult(testElement)) return true; @@ -128,9 +128,9 @@ public class TestViewer { /** * Checks whether a test was skipped i.e. it was ignored (<code>@Ignored</code>) or had any * assumption failure. - * + * * @param testElement the test element (a test suite or a single test case) - * + * * @return <code>true</code> if the test element or any of its children has * {@link Result#IGNORED} test result */ @@ -468,7 +468,7 @@ public class TestViewer { fViewerbook.setRedraw(true); } } - + /** * It makes sense to display either failed or ignored tests, not both together. * diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/JUnitStubUtility.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/JUnitStubUtility.java index 70b4083527..d27646cf90 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/JUnitStubUtility.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/JUnitStubUtility.java @@ -277,7 +277,7 @@ public class JUnitStubUtility { * enclosing type separator in the qualified type name. Type erasure is performed on a parameterized * type, arrays use the square brackets and a type parameter is resolved while creating the return * value. - * + * * @param method the method whose parameter types are required * @param useSimpleNames <code>true</code> if the last segment of the type name should be used * instead of the fully qualified type name @@ -330,7 +330,7 @@ public class JUnitStubUtility { if (useSimpleNames) { stream= stream.map(paramTypeName -> paramTypeName.substring(paramTypeName.lastIndexOf('.') + 1)); } - paramTypes= stream.collect(Collectors.joining(", ", "(", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + paramTypes= stream.collect(Collectors.joining(", ", "(", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } return paramTypes; diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/LayoutUtil.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/LayoutUtil.java index 42c6263a82..afa5a3cd31 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/LayoutUtil.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/util/LayoutUtil.java @@ -94,7 +94,7 @@ public class LayoutUtil { /** * Sets the horizontal indent of a dependent control. Assumes that GridData is used. - * + * * @param control the control */ public static void setHorizontalIndent(Control control) { @@ -110,7 +110,7 @@ public class LayoutUtil { * <strong>Note:</strong> Use this method instead of {@link LayoutConstants#getIndent()} for * compatibility reasons. * </p> - * + * * @return the indent of dependent controls, in pixels. */ public static final int getIndent() { @@ -119,7 +119,7 @@ public class LayoutUtil { /** * Sets the horizontal grabbing of a control to true. Assumes that GridData is used. - * + * * @param control the control */ public static void setHorizontalGrabbing(Control control) { @@ -131,9 +131,9 @@ public class LayoutUtil { /** * Sets the vertical grabbing of a control to true. Assumes that GridData is used. - * + * * @param control the control - * + * */ public static void setVerticalGrabbing(Control control) { Object ld= control.getLayoutData(); @@ -146,7 +146,7 @@ public class LayoutUtil { /** * Sets the width hint of a control. Assumes that GridData is used. - * + * * @param control the control * @param widthHint the preferred width in pixels */ @@ -159,7 +159,7 @@ public class LayoutUtil { /** * Sets the heightHint hint of a control. Assumes that GridData is used. - * + * * @param control the control * @param heightHint the preferred height in pixels */ diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/wizards/SuiteClassesContentProvider.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/wizards/SuiteClassesContentProvider.java index a19e8215ca..c7aae029ed 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/wizards/SuiteClassesContentProvider.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/wizards/SuiteClassesContentProvider.java @@ -40,7 +40,7 @@ public class SuiteClassesContentProvider implements IStructuredContentProvider { public SuiteClassesContentProvider() { this(false); } - + public SuiteClassesContentProvider(boolean includeJunit4Tests) { this.fIncludeJunit4Tests = includeJunit4Tests; } @@ -72,7 +72,7 @@ public class SuiteClassesContentProvider implements IStructuredContentProvider { } else { new JUnit3TestFinder().findTestsInContainer(pack, result, null); } - + return result; } catch (CoreException e) { JUnitPlugin.log(e); @@ -87,11 +87,11 @@ public class SuiteClassesContentProvider implements IStructuredContentProvider { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } - + public void setIncludeJunit4Tests(boolean includeJunit4Tests) { fIncludeJunit4Tests= includeJunit4Tests; } - + public boolean isIncludeJunit4Tests() { return fIncludeJunit4Tests; } diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/wizards/UpdateTestSuite.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/wizards/UpdateTestSuite.java index 806b4283b0..39b0d4ef9e 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/wizards/UpdateTestSuite.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/wizards/UpdateTestSuite.java @@ -156,7 +156,7 @@ public class UpdateTestSuite implements IObjectActionDelegate { } else { noSuiteError(); } - + } else{ /* find TestClasses already in Test Suite */ IType testSuiteType= fTestSuite.findPrimaryType(); @@ -219,7 +219,7 @@ public class UpdateTestSuite implements IObjectActionDelegate { if (primaryType != null) { fIsJunit4 = primaryType.getAnnotation("RunWith").exists(); //$NON-NLS-1$ } - + } } } @@ -249,7 +249,7 @@ public class UpdateTestSuite implements IObjectActionDelegate { monitor.done(); } } - + public static void updateTestCasesInSuite(IProgressMonitor monitor, ICompilationUnit testSuite, IMethod suiteMethod, Object[] selectedTestCases) throws JavaModelException { try { monitor.beginTask(WizardMessages.UpdateAllTests_beginTask, 5); @@ -294,8 +294,8 @@ public class UpdateTestSuite implements IObjectActionDelegate { end += NewTestSuiteWizardPage.NON_COMMENT_END_MARKER.length(); return new TestSuiteClassListRange(start, end); } - - + + /* * Returns the new code to be included in a new suite() or which replaces old code in an existing suite(). @@ -317,7 +317,7 @@ public class UpdateTestSuite implements IObjectActionDelegate { suite.append("\n"+NewTestSuiteWizardPage.END_MARKER); //$NON-NLS-1$ return suite.toString(); } - + /* * Returns the new test suite annotations which replace old annotations in the existing suite */ diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchShortcut.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchShortcut.java index c2df134c45..0ea8aae01f 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchShortcut.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchShortcut.java @@ -303,7 +303,7 @@ public class JUnitLaunchShortcut implements ILaunchShortcut2 { * <code>{@link #createLaunchConfiguration(IJavaElement, String) createLaunchConfiguration}(element, null)</code>. * Extenders are recommended to extend the two-args method instead of this method. * </p> - * + * * @param element element to launch * * @return a launch configuration working copy for the given element @@ -322,7 +322,7 @@ public class JUnitLaunchShortcut implements ILaunchShortcut2 { * <p>Clients can extend this method (should call super) to configure additional attributes on the * launch configuration working copy. * </p> - * + * * @param element element to launch * @param testName name of the test to launch, e.g. the method name or an artificial name * created by a JUnit runner, or <code>null</code> if none. The testName is @@ -388,7 +388,7 @@ public class JUnitLaunchShortcut implements ILaunchShortcut2 { /** * Computes a human-readable name for a launch configuration. The name serves as a suggestion and * it's the caller's responsibility to make it valid and unique. - * + * * @param element The Java Element that will be executed. * @param fullTestName The test name. See * org.eclipse.jdt.internal.junit4.runner.DescriptionMatcher for supported formats. diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestCaseWizardPageOne.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestCaseWizardPageOne.java index 6fa742783b..efaa8ca953 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestCaseWizardPageOne.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestCaseWizardPageOne.java @@ -171,7 +171,7 @@ public class NewTestCaseWizardPageOne extends NewTypeWizardPage { /** * Available JUnit versions. - * + * * @since 3.11 */ public enum JUnitVersion { @@ -323,7 +323,7 @@ public class NewTestCaseWizardPageOne extends NewTypeWizardPage { /** * Specifies the JUnit version to create the test. - * + * * @param version the JUnit version * @since 3.11 */ @@ -352,7 +352,7 @@ public class NewTestCaseWizardPageOne extends NewTypeWizardPage { /** * Specifies if the JUnit version radio buttons are enabled. - * + * * @param enabled if <code>true</code>, the JUnit version radio buttons are enabled; otherwise they * are read-only * @since 3.11 @@ -384,7 +384,7 @@ public class NewTestCaseWizardPageOne extends NewTypeWizardPage { /** * Returns the JUnit version to create the test. - * + * * @return the JUnit version to create the test * @since 3.11 */ @@ -403,7 +403,7 @@ public class NewTestCaseWizardPageOne extends NewTypeWizardPage { /** * Returns whether the super class name is one of the default super class names. - * + * * @return <code>true</code> if the super class name is one of the default super class names, * <code>false</code> otherwise * @since 3.7 @@ -994,22 +994,22 @@ public class NewTestCaseWizardPageOne extends NewTypeWizardPage { private void createSetUp(IType type, ImportsManager imports) throws CoreException { String annotationType= fJUnitVersion == JUnitVersion.VERSION_4 ? "org.junit.Before" : "org.junit.jupiter.api.BeforeEach"; //$NON-NLS-1$ //$NON-NLS-2$ - createSetupStubs(type, "setUp", false, annotationType, imports); //$NON-NLS-1$ + createSetupStubs(type, "setUp", false, annotationType, imports); //$NON-NLS-1$ } private void createTearDown(IType type, ImportsManager imports) throws CoreException { String annotationType= fJUnitVersion == JUnitVersion.VERSION_4 ? "org.junit.After" : "org.junit.jupiter.api.AfterEach"; //$NON-NLS-1$ //$NON-NLS-2$ - createSetupStubs(type, "tearDown", false, annotationType, imports); //$NON-NLS-1$ + createSetupStubs(type, "tearDown", false, annotationType, imports); //$NON-NLS-1$ } private void createSetUpClass(IType type, ImportsManager imports) throws CoreException { String annotationType= fJUnitVersion == JUnitVersion.VERSION_4 ? "org.junit.BeforeClass" : "org.junit.jupiter.api.BeforeAll"; //$NON-NLS-1$ //$NON-NLS-2$ - createSetupStubs(type, "setUpBeforeClass", true, annotationType, imports); //$NON-NLS-1$ + createSetupStubs(type, "setUpBeforeClass", true, annotationType, imports); //$NON-NLS-1$ } private void createTearDownClass(IType type, ImportsManager imports) throws CoreException { String annotationType= fJUnitVersion == JUnitVersion.VERSION_4 ? "org.junit.AfterClass" : "org.junit.jupiter.api.AfterAll"; //$NON-NLS-1$ //$NON-NLS-2$ - createSetupStubs(type, "tearDownAfterClass", true, annotationType, imports); //$NON-NLS-1$ + createSetupStubs(type, "tearDownAfterClass", true, annotationType, imports); //$NON-NLS-1$ } private void createTestMethodStubs(IType type, ImportsManager imports) throws CoreException { @@ -1039,7 +1039,7 @@ public class NewTestCaseWizardPageOne extends NewTypeWizardPage { /** * Creates a test method. - * + * * @param type the type to create the method * @param imports the imports manager * @param method the method or <code>null</code> @@ -1388,7 +1388,7 @@ public class NewTestCaseWizardPageOne extends NewTypeWizardPage { * returned. Implementors can override this behavior to return the name of a * subclass instead. * - * @return the fully qualified name of a subclass of the JUnit 3 TestCase class. + * @return the fully qualified name of a subclass of the JUnit 3 TestCase class. * * @since 3.7 */ @@ -1398,7 +1398,7 @@ public class NewTestCaseWizardPageOne extends NewTypeWizardPage { /** * Returns the default value for the super class field. - * + * * @return the default value for the super class field * @since 3.7 */ diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestSuiteWizardPage.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestSuiteWizardPage.java index be0c1ba855..d0a3a8da64 100644 --- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestSuiteWizardPage.java +++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/wizards/NewTestSuiteWizardPage.java @@ -107,10 +107,10 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { /** Field ID of the class in suite field. */ public final static String CLASSES_IN_SUITE= PAGE_NAME + ".classesinsuite"; //$NON-NLS-1$ - + /** * Field ID of the junit4 toggle field. - * + * * @since 3.7 */ public final static String JUNIT4TOGGLE= PAGE_NAME + ".junit4toggle"; //$NON-NLS-1$ @@ -126,7 +126,7 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { private Button fJUnit3Toggle; private boolean fIsJunit4; private boolean fIsJunit4Enabled; - + /** * Creates a new <code>NewTestSuiteWizardPage</code>. */ @@ -362,7 +362,7 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { */ private String getSuiteMethodString(IType type) { String typeName= type.getElementName(); - StringBuilder suite= new StringBuilder("public static Test suite () {TestSuite suite= new TestSuite(" + typeName + ".class.getName());\n"); //$NON-NLS-1$ //$NON-NLS-2$ + StringBuilder suite= new StringBuilder("public static Test suite () {TestSuite suite= new TestSuite(" + typeName + ".class.getName());\n"); //$NON-NLS-1$ //$NON-NLS-2$ suite.append(getUpdatableString()); suite.append("\nreturn suite;}"); //$NON-NLS-1$ return suite.toString(); @@ -475,7 +475,7 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { status.setError(WizardMessages.NewTestSuiteWizPage_typeName_error_name_qualified); return status; } - + IPackageFragment pack= getPackageFragment(); if (pack != null) { ICompilationUnit cu= pack.getCompilationUnit(typeName + ".java"); //$NON-NLS-1$ @@ -509,7 +509,7 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { if (cu.exists()) { status.setWarning(isJUnit4() ? WizardMessages.NewTestSuiteWizPage_typeName_warning_already_exists_junit4 - : WizardMessages.NewTestSuiteWizPage_typeName_warning_already_exists); + : WizardMessages.NewTestSuiteWizPage_typeName_warning_already_exists); return status; } IResource resource= cu.getResource(); @@ -550,7 +550,7 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { imports.addImport("org.junit.runners.Suite.SuiteClasses"); //$NON-NLS-1$ } else { imports.addImport("junit.framework.Test"); //$NON-NLS-1$ - imports.addImport("junit.framework.TestSuite"); //$NON-NLS-1$ + imports.addImport("junit.framework.TestSuite"); //$NON-NLS-1$ } } @@ -567,9 +567,9 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { */ private void saveWidgetValues() { } - - - + + + /** * Creates the controls for the JUnit 4 toggle control. Expects a <code>GridLayout</code> with * at least 3 columns. @@ -608,10 +608,10 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { fJUnit4Toggle.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 1, 1)); fJUnit4Toggle.addSelectionListener(listener); } - + /** * Specifies if the test should be created as JUnit 4 test. - * + * * @param isJUnit4 If set, a JUnit 4 test will be created * @param isEnabled if <code>true</code> the modifier fields are * editable; otherwise they are read-only @@ -624,7 +624,7 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { fJUnit4Toggle.setSelection(isJUnit4); fJUnit3Toggle.setSelection(!isJUnit4); fJUnit4Toggle.setEnabled(isEnabled || isJUnit4); - fJUnit3Toggle.setEnabled(isEnabled || !isJUnit4); + fJUnit3Toggle.setEnabled(isEnabled || !isJUnit4); } internalSetJUnit4(isJUnit4); } @@ -654,13 +654,13 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { } handleFieldChanged(JUNIT4TOGGLE); } - + @Override protected String constructCUContent(ICompilationUnit cu, String typeContent, String lineDelimiter) throws CoreException { if (isJUnit4()) { typeContent= appendAnnotations(typeContent, lineDelimiter); } - + return super.constructCUContent(cu, typeContent, lineDelimiter); } @@ -676,7 +676,7 @@ public class NewTestSuiteWizardPage extends NewTypeWizardPage { buffer.append(".class"); //$NON-NLS-1$ if(i<checkedElements.length-1) buffer.append(','); - + } } buffer.append("})"); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.junit4.runtime/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.junit4.runtime/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.junit4.runtime/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.junit4.runtime/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.junit4.runtime/META-INF/MANIFEST.MF b/org.eclipse.jdt.junit4.runtime/META-INF/MANIFEST.MF index dae0ed6983..03ac0dcecc 100644 --- a/org.eclipse.jdt.junit4.runtime/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.junit4.runtime/META-INF/MANIFEST.MF @@ -4,7 +4,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.jdt.junit4.runtime;singleton:=true -Bundle-Version: 1.1.1100.qualifier +Bundle-Version: 1.1.1200.qualifier Bundle-Localization: plugin Export-Package: org.eclipse.jdt.internal.junit4.runner;x-internal:=true Require-Bundle: org.junit;bundle-version="4.7.0", diff --git a/org.eclipse.jdt.junit4.runtime/pom.xml b/org.eclipse.jdt.junit4.runtime/pom.xml index 5a37e9e330..f0fdd33945 100644 --- a/org.eclipse.jdt.junit4.runtime/pom.xml +++ b/org.eclipse.jdt.junit4.runtime/pom.xml @@ -18,6 +18,6 @@ </parent> <groupId>org.eclipse.jdt</groupId> <artifactId>org.eclipse.jdt.junit4.runtime</artifactId> - <version>1.1.1100-SNAPSHOT</version> + <version>1.1.1200-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/DescriptionMatcher.java b/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/DescriptionMatcher.java index fabe275cf2..6e072280e1 100644 --- a/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/DescriptionMatcher.java +++ b/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/DescriptionMatcher.java @@ -23,7 +23,7 @@ import org.junit.runners.Parameterized; /** * This class matches JUnit's {@link Description} against a string. - * + * * See {@link #create(Class, String)} for details. */ public abstract class DescriptionMatcher { @@ -76,7 +76,7 @@ public abstract class DescriptionMatcher { * This class extracts the leading chars from {@link Description#getMethodName()} which are a * valid Java identifier. If this identifier equals this class' identifier, the Description is * matched. - * + * * Please be aware that {@link Description#getMethodName()} can be any value a JUnit runner has * computed. It is not necessarily a valid method name. For example, {@link Parameterized} uses * the format 'methodname[i]', with 'i' being the row index in the table of test data. @@ -115,7 +115,7 @@ public abstract class DescriptionMatcher { /** * Creates a matcher object that can decide for {@link Description}s whether they match the * supplied 'matchString' or not. - * + * * Several strategies for matching are applied: * <ul> * <li>if 'matchString' equals {@link Description#getDisplayName()}, it's always a match</li> @@ -126,12 +126,12 @@ public abstract class DescriptionMatcher { * 'matchString' is a Java identifier, it matches Descriptions via leading identifiers. See * {@link LeadingIdentifierMatcher}</li> * </ul> - * + * * @param clazz A class that is used when 'matchString' does not have the format * methodName(className). - * + * * @param matchString A string to match JUnit's {@link Description}s against. - * + * * @return A matcher object. */ public static DescriptionMatcher create(Class<?> clazz, String matchString) { diff --git a/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/FailuresFirstSorter.java b/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/FailuresFirstSorter.java index 5796444b1f..9d8e69fde1 100644 --- a/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/FailuresFirstSorter.java +++ b/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/FailuresFirstSorter.java @@ -27,16 +27,16 @@ import org.junit.runner.Description; * A description is considered to have failures if its name or one of its transitive * children's names are in the failures list. * If neither or both have failures, returns 0. - * + * * @since 3.6 */ public class FailuresFirstSorter implements Comparator<Description> { private final Set<String> failuresList; - + /** * Creates a sorter. - * + * * @param failuresList list of failed tests based on the description's display string */ public FailuresFirstSorter(String[] failuresList) { @@ -47,12 +47,12 @@ public class FailuresFirstSorter implements Comparator<Description> { * Compares two descriptions based on the failure list. * @param d1 the first Description to compare with * @param d2 the second Description to compare with - * @return -1 if only d1 has failures, 1 if only d2 has failures, 0 otherwise + * @return -1 if only d1 has failures, 1 if only d2 has failures, 0 otherwise */ public int compare(Description d1, Description d2) { boolean d1HasFailures = hasFailures(d1); boolean d2HasFailures = hasFailures(d2); - + if (d1HasFailures) { return -1; } else if (d2HasFailures) { diff --git a/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/SubForestFilter.java b/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/SubForestFilter.java index 2739d46733..2616db309e 100644 --- a/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/SubForestFilter.java +++ b/org.eclipse.jdt.junit4.runtime/src/org/eclipse/jdt/internal/junit4/runner/SubForestFilter.java @@ -24,7 +24,7 @@ import org.junit.runner.manipulation.NoTestsRemainException; /** * This filter keeps all matched {@link Description}s in a tree, including the children and * container of the matched Description. - * + * * It is allowed to match more than one Description. */ public class SubForestFilter extends Filter { diff --git a/org.eclipse.jdt.junit5.runtime/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.junit5.runtime/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.junit5.runtime/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.junit5.runtime/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.junit5.runtime/src/org/eclipse/jdt/internal/junit5/runner/JUnit5TestListener.java b/org.eclipse.jdt.junit5.runtime/src/org/eclipse/jdt/internal/junit5/runner/JUnit5TestListener.java index 4db779a9da..bb6b7669e8 100644 --- a/org.eclipse.jdt.junit5.runtime/src/org/eclipse/jdt/internal/junit5/runner/JUnit5TestListener.java +++ b/org.eclipse.jdt.junit5.runtime/src/org/eclipse/jdt/internal/junit5/runner/JUnit5TestListener.java @@ -134,7 +134,7 @@ public class JUnit5TestListener implements TestExecutionListener { return new FailedComparison(expectedStr, actualStr); } - // Avoid reference to ComparisonFailure initially to avoid NoClassDefFoundError for ComparisonFailure when junit.jar is not on the build path + // Avoid reference to ComparisonFailure initially to avoid NoClassDefFoundError for ComparisonFailure when junit.jar is not on the build path String classname= exception.getClass().getName(); if (classname.equals("junit.framework.ComparisonFailure")) { //$NON-NLS-1$ junit.framework.ComparisonFailure comparisonFailure= (junit.framework.ComparisonFailure) exception; diff --git a/org.eclipse.jdt.text.tests/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.text.tests/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.text.tests/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.text.tests/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/BracketInserterTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/BracketInserterTest.java index b09932ef52..7b0e872400 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/BracketInserterTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/BracketInserterTest.java @@ -417,34 +417,34 @@ public class BracketInserterTest extends TestCase { public void testAngleBracketsBeforeTypeArgument15() throws Exception { use15(); - + String PRE= "new ArrayList"; String POST= "String>();"; - + fDocument.replace(BODY_OFFSET, 0, PRE + POST); setCaret(BODY_OFFSET + PRE.length()); - + type('<'); - + assertEquals(PRE + '<' + POST, fDocument.get(BODY_OFFSET, PRE.length() + 1 + POST.length())); assertFalse(LinkedModeModel.hasInstalledModel(fDocument)); } - + public void testAngleBracketsBeforeWildcard15() throws Exception { use15(); - + String PRE= "new ArrayList"; String POST= "? extends Number>();"; - + fDocument.replace(BODY_OFFSET, 0, PRE + POST); setCaret(BODY_OFFSET + PRE.length()); - + type('<'); - + assertEquals(PRE + '<' + POST, fDocument.get(BODY_OFFSET, PRE.length() + 1 + POST.length())); assertFalse(LinkedModeModel.hasInstalledModel(fDocument)); } - + public void testAngleBracketsAfterIdentifierOnFirstColumn1_15() throws Exception { //https://bugs.eclipse.org/bugs/show_bug.cgi?id=347734 use15(); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/BreakContinueTargetFinderTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/BreakContinueTargetFinderTest.java index d04db67ae2..feaeed01a5 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/BreakContinueTargetFinderTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/BreakContinueTargetFinderTest.java @@ -249,7 +249,7 @@ public class BreakContinueTargetFinderTest extends TestCase{ s.append(" }\n"); s.append(" }\n"); s.append("}\n"); - int offset= s.indexOf("break") + 2; // inside 'break' + int offset= s.indexOf("break") + 2; // inside 'break' int length= 0; OccurrenceLocation[] ranges= { find(s, "baz", 1), find(s, ";", 4) }; checkSelection(s, offset, length, ranges); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaAutoIndentStrategyTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaAutoIndentStrategyTest.java index 8d2e5bcdd2..9fedaf9c2c 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaAutoIndentStrategyTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaAutoIndentStrategyTest.java @@ -35,7 +35,7 @@ import org.eclipse.jdt.internal.ui.text.java.JavaAutoIndentStrategy; /** * JavaAutoIndentStrategyTest. - * + * * @since 3.6 */ public class JavaAutoIndentStrategyTest extends TestCase implements ILogListener { @@ -403,7 +403,7 @@ public class JavaAutoIndentStrategyTest extends TestCase implements ILogListener buf.append("}"); assertEquals(buf.toString(), fDocument.get()); } - + public void testSmartIndentAfterNewLine10() { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=404879 fDocument.setInitialLineDelimiter("\r\n"); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaElementPrefixPatternMatcherTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaElementPrefixPatternMatcherTest.java index 8da81e17d2..88cbf37b18 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaElementPrefixPatternMatcherTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaElementPrefixPatternMatcherTest.java @@ -86,13 +86,13 @@ public class JavaElementPrefixPatternMatcherTest extends TestCase { private static void doMatch(String pattern, String... labelStrings) { JavaElementPrefixPatternMatcher matcher= new JavaElementPrefixPatternMatcher(pattern); - + ArrayList<String> matched= new ArrayList<>(); for (String label : ALL_STRING_CONSTANTS) { if (matcher.matches(label)) matched.add(label); } - + StringAsserts.assertEqualStringsIgnoreOrder(CollectionsUtil.toArray(matched, String.class), labelStrings); } @@ -105,7 +105,7 @@ public class JavaElementPrefixPatternMatcherTest extends TestCase { doMatch("*", ALL_STRING_CONSTANTS); } - + public void testMethodPattern_1() throws Exception { doMatch("*tos", toString_int_int, toString_int); } @@ -144,13 +144,13 @@ public class JavaElementPrefixPatternMatcherTest extends TestCase { } public void testMethodPattern_10() throws Exception { - doMatch("to*ng(", toString_int_int, toString_int); + doMatch("to*ng(", toString_int_int, toString_int); } public void testMethodPattern_11() throws Exception { doMatch("tS*ng("); } - + public void testReturnPattern_1() throws Exception { doMatch("*: int", parseInt_String, parseInt_String_int, MIN_VALUE__int); } @@ -163,7 +163,7 @@ public class JavaElementPrefixPatternMatcherTest extends TestCase { public void testFieldPattern_1() throws Exception { doMatch("DT : ", DigitTens__char_); } - + public void testTypePattern_2() throws Exception { doMatch("AI", AtomicInteger); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java index 5d1a6b0069..aa7c535055 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaHeuristicScannerTest.java @@ -1108,7 +1108,7 @@ public class JavaHeuristicScannerTest extends TestCase { indent= fScanner.computeIndentation(offset).toString(); assertEquals("\t\t\t", indent); } - + public void testDefaultMethod1() { StringBuilder buf= new StringBuilder(); buf.append("interface I {\n"); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaModelOpCompundUndoTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaModelOpCompundUndoTest.java index 59c0e23097..f044005dbf 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaModelOpCompundUndoTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/JavaModelOpCompundUndoTest.java @@ -54,7 +54,7 @@ import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; * <p> * For details see https://bugs.eclipse.org/bugs/show_bug.cgi?id=262389 * </p> - * + * * @since 3.5 */ public class JavaModelOpCompundUndoTest extends TestCase { @@ -157,7 +157,7 @@ public class JavaModelOpCompundUndoTest extends TestCase { assertEquals(CU_CONTENTS, fDocument.get()); fUndoManager.beginCompoundChange(); - + IMethod foo= JavaModelUtil.findMethod("foo", new String[0], false, fCompilationUnit.findPrimaryType()); IMethod bar= JavaModelUtil.findMethod("bar", new String[0], false, fCompilationUnit.findPrimaryType()); IJavaModel model= JavaCore.create(JavaPlugin.getWorkspace().getRoot()); @@ -169,6 +169,6 @@ public class JavaModelOpCompundUndoTest extends TestCase { fUndoManager.undo(); assertEquals(CU_CONTENTS, fDocument.get()); - + } } diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/MarkOccurrenceTest17.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/MarkOccurrenceTest17.java index abd7bd0e7a..fb74fd38cc 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/MarkOccurrenceTest17.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/MarkOccurrenceTest17.java @@ -312,7 +312,7 @@ public class MarkOccurrenceTest17 extends TestCase { OccurrenceLocation[] ranges= { find(s, "void", 1), find(s, "reader", 1), find(s, "FileReader", 3), find(s, "read", 3), find(s, "}", 2), find(s, "}", 3) }; checkSelection(s, offset, length, ranges); } - + public void testThrowingException1() throws Exception { fFinder= new ExceptionOccurrencesFinder(); StringBuffer s= new StringBuffer(); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/MarkOccurrenceTest18.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/MarkOccurrenceTest18.java index 41dbeddf55..c16baaf9a5 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/MarkOccurrenceTest18.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/MarkOccurrenceTest18.java @@ -171,36 +171,36 @@ public class MarkOccurrenceTest18 extends TestCase { s.append(" }\n"); s.append(" }\n"); s.append("}\n"); - + fFinder= new ExceptionOccurrencesFinder(); int offset= 8 + s.indexOf("@throws E.InnerException"); // in Javadoc int length= 0; OccurrenceLocation[] ranges= { find(s, "E.InnerException", 1), find(s, "@Critical() E.@Critical() InnerException", 1), find(s, "throw", 3), find(s, "throw", 4) }; checkSelection(s, offset, length, ranges); - + fFinder= new ExceptionOccurrencesFinder(); offset= 1 + s.indexOf("@Critical() E.@Critical() InnerException"); // in annotation length= 0; checkSelection(s, offset, length, ranges); - + fFinder= new ExceptionOccurrencesFinder(); offset= s.indexOf("E.@Critical() InnerException"); // in annotated type qualifier length= 1; checkSelection(s, offset, length, ranges); - + fFinder= new ExceptionOccurrencesFinder(); offset= 1 + s.indexOf("InnerException e)"); // in annotated catch type (does NOT include modifier "@Critical() "!) length= 0; ranges= new OccurrenceLocation[] { find(s, "foo", 2), find(s, "E.@Critical() InnerException", 3)}; checkSelection(s, offset, length, ranges); - + fFinder= new ExceptionOccurrencesFinder(); offset= s.indexOf("RuntimeException |"); // in annotated union type length= 0; ranges= new OccurrenceLocation[] { find(s, "foo", 3), find(s, "RuntimeException", 2)}; checkSelection(s, offset, length, ranges); - + fFinder= new ExceptionOccurrencesFinder(); offset= s.indexOf("He"); // in annotation expression length= 0; diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/NewForLoopJavaContextTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/NewForLoopJavaContextTest.java index e6470a375d..186a7986b5 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/NewForLoopJavaContextTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/NewForLoopJavaContextTest.java @@ -10,7 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Lukas Hanke <hanke@yatta.de> - [templates][content assist] Content assist for 'for' loop should suggest member variables - https://bugs.eclipse.org/117215 + * Lukas Hanke <hanke@yatta.de> - [templates][content assist] Content assist for 'for' loop should suggest member variables - https://bugs.eclipse.org/117215 *******************************************************************************/ package org.eclipse.jdt.text.tests; diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java index afce930ee4..42b1f0896a 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java @@ -192,9 +192,9 @@ public class PluginsNotLoadedTest extends TestCase { * This activates the EGit UI bundle very early. * Because of that, EGit's org.eclipse.egit.ui.team.MergeTool command's handler class is loaded, * which in turn activates the org.eclipse.compare bundle on startup. - * + * * org.eclipse.pde.ui also contributes a sourceProvider, that's why we don't test for it... - * + * * Workaround is to remove org.eclipse.compare iff EGit is present: */ if (Platform.getBundle("org.eclipse.egit.ui") != null) { diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PropertiesFileAutoEditStrategyTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PropertiesFileAutoEditStrategyTest.java index 5c346995b1..6547f0cc0e 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PropertiesFileAutoEditStrategyTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PropertiesFileAutoEditStrategyTest.java @@ -43,7 +43,7 @@ import org.eclipse.jdt.ui.tests.core.ProjectTestSetup; /** * PropertiesFileAutoEditStratergyTest - * + * * @since 3.7 */ public class PropertiesFileAutoEditStrategyTest extends TestCase { @@ -295,7 +295,7 @@ public class PropertiesFileAutoEditStrategyTest extends TestCase { assertEquals("\\u2603 \\\\u2603", fDocumentCommand.text); assertNull(proposal); } - + public void testPasteFromPropertiesFileISO_8859_1_06() throws Exception { fDocumentCommand.text= "key=value\\\nsecond line"; Object proposal= performTestISO_8859_1(); @@ -315,7 +315,7 @@ public class PropertiesFileAutoEditStrategyTest extends TestCase { fDocumentCommand.text= "\u2603"; performTestUTF8(); assertEquals("\u2603", fDocumentCommand.text); - + fPropertiesFileUTF8.setCharset(ISO_8859_1, null); fDocumentCommand.text= "\u2603"; @@ -329,9 +329,9 @@ public class PropertiesFileAutoEditStrategyTest extends TestCase { fDocumentCommand.text= "\u2603"; performTestISO_8859_1(); assertEquals("\\u2603", fDocumentCommand.text); - + fPropertiesFileISO_8859_1.setCharset(UTF_8, null); - + fDocumentCommand.text= "\u2603"; performTestISO_8859_1(); assertEquals("\u2603", fDocumentCommand.text); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/codemining/ParameterNamesCodeMiningTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/codemining/ParameterNamesCodeMiningTest.java index 9e2fda010b..ad8285fbbc 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/codemining/ParameterNamesCodeMiningTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/codemining/ParameterNamesCodeMiningTest.java @@ -290,21 +290,21 @@ public class ParameterNamesCodeMiningTest extends TestCase { preferenceStore.setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, initial); } } - + public void testBug547232() throws Exception { - String contents= "public class Test {\n" + - " public final Object object;\n" + - " public final String string;\n" + - "\n" + - " Test(Object object, String string) {\n" + - " this.object = object;\n" + - " this.string = string;\n" + - " }\n" + - "\n" + - " void f() {\n" + - " new Test(null, \"test\");\n" + - " }\n" + - "}\n" + + String contents= "public class Test {\n" + + " public final Object object;\n" + + " public final String string;\n" + + "\n" + + " Test(Object object, String string) {\n" + + " this.object = object;\n" + + " this.string = string;\n" + + " }\n" + + "\n" + + " void f() {\n" + + " new Test(null, \"test\");\n" + + " }\n" + + "}\n" + ""; ICompilationUnit compilationUnit= fPackage.createCompilationUnit("Test.java", contents, true, new NullProgressMonitor()); JavaEditor editor= (JavaEditor) EditorUtility.openInEditor(compilationUnit); @@ -316,21 +316,21 @@ public class ParameterNamesCodeMiningTest extends TestCase { } public void testBug549023() throws Exception { - String contents= "class Base {\n" + - " public final Object object;\n" + - " public final String string;\n" + - "\n" + - " Base(Object object, String string) {\n" + - " this.object = object;\n" + - " this.string = string;\n" + - " }\n" + - "}\n" + - "\n" + - "public class Test extends Base {\n" + - " Test() {\n" + - " super(null, \"\");\n" + - " }\n" + - "}\n" + + String contents= "class Base {\n" + + " public final Object object;\n" + + " public final String string;\n" + + "\n" + + " Base(Object object, String string) {\n" + + " this.object = object;\n" + + " this.string = string;\n" + + " }\n" + + "}\n" + + "\n" + + "public class Test extends Base {\n" + + " Test() {\n" + + " super(null, \"\");\n" + + " }\n" + + "}\n" + ""; ICompilationUnit compilationUnit= fPackage.createCompilationUnit("Test.java", contents, true, new NullProgressMonitor()); JavaEditor editor= (JavaEditor) EditorUtility.openInEditor(compilationUnit); @@ -342,17 +342,17 @@ public class ParameterNamesCodeMiningTest extends TestCase { } public void testBug549126() throws Exception { - String contents= "public enum TestEnum {\n" + - " A(\"bla\", null);\n" + - "\n" + - " public final String string;\n" + - " public final Object object;\n" + - "\n" + - " TestEnum(String string, Object object) {\n" + - " this.string = string;\n" + - " this.object = object;\n" + - " }\n" + - "}\n" + + String contents= "public enum TestEnum {\n" + + " A(\"bla\", null);\n" + + "\n" + + " public final String string;\n" + + " public final Object object;\n" + + "\n" + + " TestEnum(String string, Object object) {\n" + + " this.string = string;\n" + + " this.object = object;\n" + + " }\n" + + "}\n" + ""; ICompilationUnit compilationUnit= fPackage.createCompilationUnit("TestEnum.java", contents, true, new NullProgressMonitor()); JavaEditor editor= (JavaEditor) EditorUtility.openInEditor(compilationUnit); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/AbstractCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/AbstractCompletionTest.java index 2175fbc247..80e0d469b3 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/AbstractCompletionTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/AbstractCompletionTest.java @@ -262,7 +262,7 @@ public class AbstractCompletionTest extends TestCase { * Creates a CU with a class containing <code>before</code>, then runs code assist and applies * the first proposal whose display name matches <code>selector</code> and asserts that the * method's body now has the content of <code>expected</code>. - * + * * @param before the contents of the class body line before code completion is run * @param expected the expected contents of the class body * @param selector the prefix to match a proposal with @@ -280,7 +280,7 @@ public class AbstractCompletionTest extends TestCase { /** * Creates a CU with a class containing <code>before</code>, then runs code assist and asserts * that there is no proposal. - * + * * @param before the contents of the class body line before code completion is run * @param selector the prefix to match a proposal with * @throws CoreException if asserting the proposal failed @@ -549,7 +549,7 @@ public class AbstractCompletionTest extends TestCase { * Invokes {@link Thread#sleep(long)} if {@link #waitBeforeCompleting(boolean)} was set to * <code>true</code> or camel case completions are enabled. For some reasons, inner types and * camel case matches don't show up otherwise. - * + * * @since 3.2 */ private void waitBeforeCoreCompletion() { diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/ChainCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/ChainCompletionTest.java index 60a010991c..23cc722780 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/ChainCompletionTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/ChainCompletionTest.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (c) 2019, 2020 Red Hat Inc. and others. - * + * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -122,12 +122,12 @@ public class ChainCompletionTest extends TestCase { public void testPrimitiveCompletion() throws Exception { StringBuffer buf= new StringBuffer(); - buf.append("package test;\n" + - "public class Foo {\n" + - " public void foo () {\n" + - " String s = \"\";\n" + - " int length = $\n" + - " }\n" + + buf.append("package test;\n" + + "public class Foo {\n" + + " public void foo () {\n" + + " String s = \"\";\n" + + " int length = $\n" + + " }\n" + "}"); int completionIndex= getCompletionIndex(buf); @@ -455,8 +455,8 @@ public class ChainCompletionTest extends TestCase { " public static class Subtype extends CompletionOnSupertypeMemberInMethod {\n" + " }\n" + "\n" + - " public Boolean findMe() {\n" + - " return Boolean.TRUE;\n" + + " public Boolean findMe() {\n" + + " return Boolean.TRUE;\n" + " }\n" + "\n" + " public static void test_onAttribute() {\n" + @@ -476,17 +476,17 @@ public class ChainCompletionTest extends TestCase { public void testCompletionOnThisAndLocal() throws Exception { StringBuffer buf= new StringBuffer(); - buf.append("import java.util.Collection;\n" + - "import java.util.HashMap;\n" + - "import java.util.Map;\n" + - "\n" + - "package test;\n" + - "\n" + - "public class TestCompletionOnThisAndLocal {\n" + - " public void method() {\n" + - " final Map map = new HashMap();\n" + - " final Collection c = $ \n" + - " }\n" + + buf.append("import java.util.Collection;\n" + + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "package test;\n" + + "\n" + + "public class TestCompletionOnThisAndLocal {\n" + + " public void method() {\n" + + " final Map map = new HashMap();\n" + + " final Collection c = $ \n" + + " }\n" + "}"); int completionIndex= getCompletionIndex(buf); @@ -504,26 +504,26 @@ public class ChainCompletionTest extends TestCase { public void testCompletionOnType() throws Exception { StringBuffer buf= new StringBuffer(); - buf.append("package test;\n" + - "\n" + - "public class TestCompletionOnType {\n" + - " public class S {\n" + - "\n" + - " private static S INSTANCE = new S();\n" + - " private S () {}\n" + - "\n" + - " public Integer findMe() {\n" + - " return 0;\n" + - " }\n" + - "\n" + - " public static S getInstance() {\n" + - " return INSTANCE;\n" + - " }\n" + - " }\n" + - "\n" + - " public void __test() {\n" + - " Integer i = S.$\n" + - " } \n" + + buf.append("package test;\n" + + "\n" + + "public class TestCompletionOnType {\n" + + " public class S {\n" + + "\n" + + " private static S INSTANCE = new S();\n" + + " private S () {}\n" + + "\n" + + " public Integer findMe() {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " public static S getInstance() {\n" + + " return INSTANCE;\n" + + " }\n" + + " }\n" + + "\n" + + " public void __test() {\n" + + " Integer i = S.$\n" + + " } \n" + "}"); int completionIndex= getCompletionIndex(buf); @@ -541,35 +541,35 @@ public class ChainCompletionTest extends TestCase { // test.TestBug552849 -> test.Foo -> test2.Bar -> test3.Foo StringBuffer buf= new StringBuffer(); - buf.append("import java.io.File;\n" + - "package test3;\n" + - "public class Foo {\n" + - " protected File fVal= \"\";\n" + + buf.append("import java.io.File;\n" + + "package test3;\n" + + "public class Foo {\n" + + " protected File fVal= \"\";\n" + "}"); ICompilationUnit cu= getCompilationUnit(pkg3, buf, "Foo.java"); buf= new StringBuffer(); - buf.append("package test2;\n" + - "import test3.Foo;\n" + - "public class Bar extends Foo {\n" + + buf.append("package test2;\n" + + "import test3.Foo;\n" + + "public class Bar extends Foo {\n" + "}"); cu= getCompilationUnit(pkg2, buf, "Bar.java"); buf= new StringBuffer(); - buf.append("package test;\n" + - "import test2.Bar;\n" + - "public class Foo extends Bar {\n" + + buf.append("package test;\n" + + "import test2.Bar;\n" + + "public class Foo extends Bar {\n" + "}"); cu= getCompilationUnit(pkg, buf, "Foo.java"); buf= new StringBuffer(); - buf.append("import java.io.File;\n" + - "package test;\n" + - "public class TestBug552849 extends Foo {\n" + - " public void test () {\n" + - " TestBug552849 foo = new TestBug552849();\n" + - " File res = $\n" + - " }\n" + + buf.append("import java.io.File;\n" + + "package test;\n" + + "public class TestBug552849 extends Foo {\n" + + " public void test () {\n" + + " TestBug552849 foo = new TestBug552849();\n" + + " File res = $\n" + + " }\n" + "}"); int completionIndex= getCompletionIndex(buf); @@ -583,21 +583,21 @@ public class ChainCompletionTest extends TestCase { public void testBug559385 () throws Exception { StringBuffer buf= new StringBuffer(); - buf.append("package test;\n" + - "public @interface Command {\n" + - " String name();\n" + + buf.append("package test;\n" + + "public @interface Command {\n" + + " String name();\n" + "}"); ICompilationUnit cu= getCompilationUnit(pkg, buf, "Command.java"); buf= new StringBuffer(); - buf.append("package test;\n" + - "import java.util.concurrent.Callable;\n" + - "@Command(name = $\"\")\n" + - "public class TestBug559385 implements Callable<String> {\n" + - " @Override\n" + - " public String call() throws Exception {\n" + - " return null;\n" + - " }\n" + + buf.append("package test;\n" + + "import java.util.concurrent.Callable;\n" + + "@Command(name = $\"\")\n" + + "public class TestBug559385 implements Callable<String> {\n" + + " @Override\n" + + " public String call() throws Exception {\n" + + " return null;\n" + + " }\n" + "}"); cu= getCompilationUnit(pkg, buf, "TestBug559385.java"); int completionIndex= getCompletionIndex(buf); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CheckUIThreadReactivityThread.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CheckUIThreadReactivityThread.java index cc14e27238..1228f22136 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CheckUIThreadReactivityThread.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CheckUIThreadReactivityThread.java @@ -17,7 +17,7 @@ import org.eclipse.swt.widgets.Display; * request and computes how long it take for display to process the request. * The time to handle request is time when display is busy doing other work, so * it's actually a UI Freeze. - * + * * This could be moved to SWT or other common place where we need to check * UI Freezes and reused form there, */ diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java index 4af16e902b..198b67426e 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -86,6 +86,7 @@ import org.eclipse.jdt.internal.ui.text.java.FillArgumentNamesCompletionProposal import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor; import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposalComputer; import org.eclipse.jdt.internal.ui.text.java.JavaNoTypeCompletionProposalComputer; +import org.eclipse.jdt.internal.ui.text.java.JavaTypeCompletionProposalComputer; import junit.extensions.TestSetup; import junit.framework.Test; @@ -183,6 +184,7 @@ public class CodeCompletionTest extends AbstractCompletionTest { store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, true); store.setValue(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS, false); store.setValue(PreferenceConstants.CODEASSIST_SHOW_VISIBLE_PROPOSALS, false); + store.setValue(PreferenceConstants.CODEASSIST_INSERT_COMPLETION, true); StubUtility.setCodeTemplate(CodeTemplateContextType.OVERRIDECOMMENT_ID, "/* (non-Javadoc)\n * ${see_to_overridden}\n */", null); StubUtility.setCodeTemplate(CodeTemplateContextType.DELEGATECOMMENT_ID, "/* (non-Javadoc)\n * ${see_to_target}\n */", null); @@ -2325,6 +2327,127 @@ public class CodeCompletionTest extends AbstractCompletionTest { } } + /* + * Ensure no extra ';' is inserted + */ + public void testImport() throws Exception { + IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); + + IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.util.ArrayL; // here\n"); + buf.append("public class A {\n"); + buf.append("}\n"); + String contents= buf.toString(); + ICompilationUnit cu= pack1.createCompilationUnit("A.java", contents, false, null); + + String str= "; // here"; + int offset= contents.indexOf(str); + + IEditorPart part= JavaUI.openInEditor(cu); + ISourceViewer viewer= ((JavaEditor) part).getViewer(); + JavaContentAssistInvocationContext context= new JavaContentAssistInvocationContext(viewer, offset, part); + JavaCompletionProposalComputer computer= new JavaTypeCompletionProposalComputer(); + + // make sure we get an import rewrite context + SharedASTProviderCore.getAST(cu, SharedASTProviderCore.WAIT_YES, null); + + List<ICompletionProposal> proposals= computer.computeCompletionProposals(context, null); + assertEquals("Expecting 1 proposal", 1, proposals.size()); + + IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput()); + proposals.get(0).apply(doc); + + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.util.ArrayList; // here\n"); + buf.append("public class A {\n"); + buf.append("}\n"); + assertEquals(buf.toString(), doc.get()); + } + + /* + * Ensure no extra ';' is inserted, whereas a selected text part is correctly replaced + */ + public void testImportReplacingSelection() throws Exception { + IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); + + IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.util.ArrayLWrong;\n"); + buf.append("public class A {\n"); + buf.append("}\n"); + String contents= buf.toString(); + ICompilationUnit cu= pack1.createCompilationUnit("A.java", contents, false, null); + + IEditorPart part= JavaUI.openInEditor(cu); + String str= "Wrong"; + + int offset= contents.indexOf(str); + + CompletionProposalCollector collector= createCollector(cu, offset); + collector.setAllowsRequiredProposals(CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true); + collector.setReplacementLength("Wrong".length()); + + codeComplete(cu, offset, collector); + IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals(); + + assertEquals("expect 1 proposal", 1, proposals.length); + + IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput()); + proposals[0].apply(doc); + + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.util.ArrayList;\n"); + buf.append("public class A {\n"); + buf.append("}\n"); + assertEquals(buf.toString(), doc.get()); + } + + /* + * Ensure no extra ';' is inserted, whereas remain text is replaced as per the preference option + */ + public void testImportReplacing() throws Exception { + getJDTUIPrefs().setValue(PreferenceConstants.CODEASSIST_INSERT_COMPLETION, false); + + IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); + + IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); + StringBuffer buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.util.ArrayLWrong;\n"); + buf.append("public class A {\n"); + buf.append("}\n"); + String contents= buf.toString(); + ICompilationUnit cu= pack1.createCompilationUnit("A.java", contents, false, null); + + IEditorPart part= JavaUI.openInEditor(cu); + String str= "Wrong"; + + int offset= contents.indexOf(str); + + CompletionProposalCollector collector= createCollector(cu, offset); + collector.setAllowsRequiredProposals(CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true); + + codeComplete(cu, offset, collector); + IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals(); + + assertEquals("expect 1 proposal", 1, proposals.length); + + IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput()); + proposals[0].apply(doc); + + buf= new StringBuffer(); + buf.append("package test1;\n"); + buf.append("import java.util.ArrayList;\n"); + buf.append("public class A {\n"); + buf.append("}\n"); + assertEquals(buf.toString(), doc.get()); + } + public void testConstructorCompletion_Bug336451() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest18.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest18.java index 59bb23668f..0581d54418 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest18.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest18.java @@ -65,7 +65,7 @@ import junit.framework.TestSuite; public class CodeCompletionTest18 extends AbstractCompletionTest { private static final Class<CodeCompletionTest18> THIS= CodeCompletionTest18.class; - + public static Test suite() { return new Java18ProjectTestSetup(new TestSuite(THIS)); } @@ -153,8 +153,8 @@ public class CodeCompletionTest18 extends AbstractCompletionTest { String contents= "package test1\n" + "public class X {\n" + - " void foo() {\n" + - " java.util.Comparator.reverseOrder(). // content assist after '.' => NPE\n" + + " void foo() {\n" + + " java.util.Comparator.reverseOrder(). // content assist after '.' => NPE\n" + " }\n" + "}\n"; ICompilationUnit cu= pack1.createCompilationUnit("X.java", contents, false, null); @@ -186,8 +186,8 @@ public class CodeCompletionTest18 extends AbstractCompletionTest { String expectedContents= "package test1\n" + "public class X {\n" + - " void foo() {\n" + - " java.util.Comparator.reverseOrder().thenComparingLong() // content assist after '.' => NPE\n" + + " void foo() {\n" + + " java.util.Comparator.reverseOrder().thenComparingLong() // content assist after '.' => NPE\n" + " }\n" + "}\n"; assertEquals(expectedContents, doc.get()); @@ -311,20 +311,20 @@ public class CodeCompletionTest18 extends AbstractCompletionTest { buf.append(" getSize\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("I.java", buf.toString(), false, null); - + String str= "getSize"; int offset= buf.toString().lastIndexOf(str) + str.length(); - + CompletionProposalCollector collector= createCollector(cu, offset); collector.setReplacementLength(0); codeComplete(cu, offset, collector); - + IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals(); assertEquals(1, proposals.length); IEditorPart part= JavaUI.openInEditor(cu); IDocument doc= JavaUI.getDocumentProvider().getDocument(part.getEditorInput()); proposals[0].apply(doc); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public interface I {\n"); @@ -795,26 +795,26 @@ public class CodeCompletionTest18 extends AbstractCompletionTest { buf.append("}\n"); buf.append(""); String contents= buf.toString(); - + ICompilationUnit cu= pack1.createCompilationUnit("A.java", contents, false, null); - + String str= "new A("; - + int offset= contents.indexOf(str) + str.length(); - + CompletionProposalCollector collector= createCollector(cu, offset); collector.setReplacementLength(0); - + codeComplete(cu, offset, collector); - + IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals(); - + assertNumberOf("proposals", proposals.length, 1); - + IDocument doc= new Document(contents); - + proposals[0].apply(doc); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/PostFixCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/PostFixCompletionTest.java index c35651b81d..bae18b2ce3 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/PostFixCompletionTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/PostFixCompletionTest.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (c) 2019, 2020 Red Hat Inc. and others. - * + * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/DisplayHelper.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/DisplayHelper.java index bf67288c02..93ed0cd605 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/DisplayHelper.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/DisplayHelper.java @@ -108,7 +108,7 @@ public abstract class DisplayHelper { /** * The condition which has to be met in order for {@link #waitForCondition(Display, long)} to * return before the timeout elapses. - * + * * @return <code>true</code> if the condition is met, <code>false</code> if the event loop * should be driven some more */ diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/InvocationCountPerformanceMeter.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/InvocationCountPerformanceMeter.java index 6cd17386fd..b1b7814220 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/InvocationCountPerformanceMeter.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/InvocationCountPerformanceMeter.java @@ -541,7 +541,7 @@ public class InvocationCountPerformanceMeter extends InternalPerformanceMeter { * Returns the JNI-style signature of the given method. See * http://download.oracle.com/javase/6/docs * /jdk/api/jpda/jdi/com/sun/jdi/doc-files/signature.html - * + * * @param method the method * @return the JNI style signature */ @@ -553,7 +553,7 @@ public class InvocationCountPerformanceMeter extends InternalPerformanceMeter { * Returns the JNI-style signature of the given constructor. See * http://download.oracle.com/javase * /6/docs/jdk/api/jpda/jdi/com/sun/jdi/doc-files/signature.html - * + * * @param constructor the constructor * @return the JNI style signature */ @@ -565,7 +565,7 @@ public class InvocationCountPerformanceMeter extends InternalPerformanceMeter { * Returns the JNI-style signature of the given parameter types. See * http://download.oracle.com/javase * /6/docs/jdk/api/jpda/jdi/com/sun/jdi/doc-files/signature.html - * + * * @param paramTypes the parameter types * @return the JNI style signature */ @@ -582,7 +582,7 @@ public class InvocationCountPerformanceMeter extends InternalPerformanceMeter { * Returns the JNI-style signature of the given class. See * http://download.oracle.com/javase/6/docs * /jdk/api/jpda/jdi/com/sun/jdi/doc-files/signature.html - * + * * @param clazz the class * @return the JNI style signature */ diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaDocIndentStrategyTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaDocIndentStrategyTest.java index f33414b674..77609f0589 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaDocIndentStrategyTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaDocIndentStrategyTest.java @@ -125,7 +125,7 @@ public class JavaDocIndentStrategyTest extends TextPerformanceTestCase implement * Places the caret behind a Javadoc prefix after which the declaration of a method with many * arguments and declared exceptions follows and measures the time it takes to auto edit when * entering a newline. See also <code>testResources/javaDocIndentStrategyTest1/Test.java<code>. - * + * * @throws Exception if something fails while executing this test */ public void testJavaDocIndentStrategy() throws Exception { diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaTypingInvocationCountTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaTypingInvocationCountTest.java index 70a02f76cf..407094d1ab 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaTypingInvocationCountTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/JavaTypingInvocationCountTest.java @@ -23,7 +23,7 @@ import org.eclipse.jface.text.source.AnnotationPainter; * Counts number of repaints ( * {@link AnnotationPainter#paintControl(org.eclipse.swt.events.PaintEvent)}) when typing on a line * with annotations shown as squiggles in the Java editor. - * + * * @since 3.1 * @deprecated since INVOCATION_COUNT dimension is no longer supported. */ diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/MoveLineTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/MoveLineTest.java index 786fc439c4..633093f154 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/MoveLineTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/MoveLineTest.java @@ -62,7 +62,7 @@ public abstract class MoveLineTest extends TextPerformanceTestCase { /** * Measures the time to move a line within a large file. - * + * * @throws Exception if something goes wrong while moving a line */ public void test() throws Exception { @@ -97,7 +97,7 @@ public abstract class MoveLineTest extends TextPerformanceTestCase { for (int j= 0; j < DISTANCE; j++) { event.type= SWT.KeyDown; display.post(event); - + event.type= SWT.KeyUp; display.post(event); } diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/NonInitialTypingTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/NonInitialTypingTest.java index 59f225b3f4..84f4b43c49 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/NonInitialTypingTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/NonInitialTypingTest.java @@ -102,7 +102,7 @@ public abstract class NonInitialTypingTest extends TextPerformanceTestCase { /** * Measures the time to type in one single method into a large file. - * + * * @throws BadLocationException if the insert position can't be detected */ public void testTypeAMethod() throws BadLocationException { diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/SpellCheckingTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/SpellCheckingTest.java index ccb7e9783e..96f7720480 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/SpellCheckingTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/SpellCheckingTest.java @@ -45,7 +45,7 @@ import org.eclipse.jdt.ui.PreferenceConstants; /** * Measures the time to spell check a large compilation unit. - * + * * @since 3.6 */ public class SpellCheckingTest extends TextPerformanceTestCase { @@ -124,7 +124,7 @@ public class SpellCheckingTest extends TextPerformanceTestCase { private int fProblemCount; private boolean fPrintCount; - + public SpellingProblemCollector(boolean printCount) { fPrintCount= printCount; } diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextPerformanceTestCase.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextPerformanceTestCase.java index 1d92150dc2..45a226a027 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextPerformanceTestCase.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextPerformanceTestCase.java @@ -61,7 +61,7 @@ public class TextPerformanceTestCase extends TestCase { } } static boolean DEBUG= false; - + private static final SimpleDateFormat DATE_FORMAT= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z", Locale.US); diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextTypingInvocationCountTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextTypingInvocationCountTest.java index e56ef5447c..e14ca5f196 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextTypingInvocationCountTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/TextTypingInvocationCountTest.java @@ -23,7 +23,7 @@ import org.eclipse.jface.text.source.AnnotationPainter; * Counts number of repaints ( * {@link AnnotationPainter#paintControl(org.eclipse.swt.events.PaintEvent)}) when typing on a line * with annotations shown as squiggles in the text editor. - * + * * @since 3.1 * @deprecated since INVOCATION_COUNT dimension is no longer supported. */ diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/WhitespaceCharacterPainterTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/WhitespaceCharacterPainterTest.java index a1d5bbd535..8e298e7760 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/WhitespaceCharacterPainterTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/WhitespaceCharacterPainterTest.java @@ -31,7 +31,7 @@ import junit.framework.TestSuite; /** * Measure the time spent while scrolling in the text editor with 'Show whitespace characters' * option enabled. - * + * * @since 3.7 */ public class WhitespaceCharacterPainterTest extends ScrollEditorTest { @@ -43,7 +43,7 @@ public class WhitespaceCharacterPainterTest extends ScrollEditorTest { public static Test suite() { return new PerformanceTestSetup(new TestSuite(THIS)); } - + public static Test setUpTest(Test test) { return new PerformanceTestSetup(test) { @Override @@ -53,7 +53,7 @@ public class WhitespaceCharacterPainterTest extends ScrollEditorTest { field.setAccessible(true); Set<?> set = (Set<?>) field.get(null); set.clear(); - + super.setUp(); } }; @@ -78,7 +78,7 @@ public class WhitespaceCharacterPainterTest extends ScrollEditorTest { /** * Measure the time spent while scrolling page wise in the text editor. - * + * * @throws Exception if something goes wrong */ public void testScrollTextEditorPageWise() throws Exception { @@ -87,7 +87,7 @@ public class WhitespaceCharacterPainterTest extends ScrollEditorTest { /** * Measure the time spent while scrolling line wise in the text editor. - * + * * @throws Exception if something goes wrong */ public void testScrollTextEditorLineWiseMoveCaret2() throws Exception { @@ -96,7 +96,7 @@ public class WhitespaceCharacterPainterTest extends ScrollEditorTest { /** * Measure the time spent while scrolling and selecting line wise in the text editor. - * + * * @throws Exception if something goes wrong */ public void testScrollTextEditorLineWiseSelect2() throws Exception { @@ -105,7 +105,7 @@ public class WhitespaceCharacterPainterTest extends ScrollEditorTest { /** * Measure the time spent while scrolling line wise without moving the caret in the text editor. - * + * * @throws Exception if something goes wrong */ public void testScrollTextEditorLineWise2() throws Exception { diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/WordRulePerformanceTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/WordRulePerformanceTest.java index 3963707fbd..8f62a8f8b5 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/WordRulePerformanceTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/performance/WordRulePerformanceTest.java @@ -28,7 +28,7 @@ import org.eclipse.jface.text.rules.WordRule; /** * Performance tests for {@link WordRule}. - * + * * @since 3.6 */ public class WordRulePerformanceTest extends TextPerformanceTestCase2 { diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/templates/TemplateCompletionTests.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/templates/TemplateCompletionTests.java index f9b97fcb62..a6f39f2089 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/templates/TemplateCompletionTests.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/templates/TemplateCompletionTests.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (c) 2019 Red Hat Inc. and others. - * + * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 * which is available at https://www.eclipse.org/legal/epl-2.0/ @@ -75,10 +75,10 @@ public class TemplateCompletionTests extends TestCase { applyProposal(viewer, proposals, "new_class", completionIndex); StringBuffer expected= new StringBuffer(); - expected.append(" package test;\n" + - "\n" + - "public class EmptyFile {\n" + - "\n" + + expected.append(" package test;\n" + + "\n" + + "public class EmptyFile {\n" + + "\n" + "}"); assertEquals(expected.toString(), viewer.getDocument().get()); diff --git a/org.eclipse.jdt.ui.examples.javafamily/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.ui.examples.javafamily/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.ui.examples.javafamily/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/IIndex.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/IIndex.java index a627169cac..6767603d56 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/IIndex.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/IIndex.java @@ -18,8 +18,8 @@ import java.util.HashSet; public interface IIndex { void addRef(String word, String path); - + void remove(String path); - + void queryPrefix(HashSet result, String prefix); } diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/IIndexQuery.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/IIndexQuery.java index 7dd8393b3d..3fcd885776 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/IIndexQuery.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/IIndexQuery.java @@ -29,14 +29,14 @@ public interface IIndexQuery { * Compute the list of paths which are keying index files and add them to the given list. */ void computePathsKeyingIndexFiles(ArrayList requiredIndexKeys); - + /** * Perform the query on the given index and adds the paths of all found documents to the given collector. */ void findIndexMatches(IIndex index, HashSet collector, IProgressMonitor progressMonitor) throws IOException; /** - * Locate all matches of this query in the given file candidate and return them via the resultcollector. + * Locate all matches of this query in the given file candidate and return them via the resultcollector. */ void locateMatches(IFile candidate, ISearchResultCollector resultCollector); } diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/ISearchResultCollector.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/ISearchResultCollector.java index e419fc8ace..0b37f0f39d 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/ISearchResultCollector.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/ISearchResultCollector.java @@ -21,7 +21,7 @@ import org.eclipse.core.runtime.CoreException; * query to a <code>SearchEngine</code>. Clients must implement this interface and pass * an instance to the <code>search(...)</code> methods. * <p> - * The order of the results is unspecified. Clients must not rely on this order to display results, + * The order of the results is unspecified. Clients must not rely on this order to display results, * but they should sort these results. * <p> * Clients may implement this interface. @@ -30,7 +30,7 @@ import org.eclipse.core.runtime.CoreException; * @see SearchEngine#search */ public interface ISearchResultCollector { - + /** * Accepts the given search result. * diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/SearchEngine.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/SearchEngine.java index 587caab453..496c8728b2 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/SearchEngine.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/core/indexsearch/SearchEngine.java @@ -35,11 +35,11 @@ import org.eclipse.core.resources.ResourcesPlugin; * This class may be instantiated; it is not intended to be subclassed. */ public class SearchEngine { - + static class MyIndex implements IIndex { - + private HashMap fMap= new HashMap(); - + @Override public void addRef(String word, String path) { System.err.println("Index.add: " + path + " " + word); //$NON-NLS-1$ //$NON-NLS-2$ @@ -50,13 +50,13 @@ public class SearchEngine { } words.put(word, word); } - + @Override public void remove(String path) { System.err.println("Index.remove: " + path); //$NON-NLS-1$ fMap.remove(path); } - + @Override public void queryPrefix(HashSet results, String w) { Iterator iter= fMap.keySet().iterator(); @@ -68,7 +68,7 @@ public class SearchEngine { } } } - + /* Waiting policies */ /** * The search operation throws an <code>org.eclipse.core.runtime.OperationCanceledException</code> @@ -81,16 +81,16 @@ public class SearchEngine { */ public static int WAIT_UNTIL_READY_TO_SEARCH = 1; - + private static SearchEngine fgSearchEngine; - + private HashMap fIndexes= new HashMap(); - + private SearchEngine() { } - + /** - * + * * @return */ public static SearchEngine getSearchEngine() { @@ -98,7 +98,7 @@ public class SearchEngine { fgSearchEngine= new SearchEngine(); return fgSearchEngine; } - + /** * Trigger removal of a resource to an index * Note: the actual operation is performed in background @@ -108,7 +108,7 @@ public class SearchEngine { if (index != null) index.remove(resourceName); } - + public void add(IPath indexedContainer, IIndexer indexer) { IIndex index= getIndex(indexedContainer, true); try { @@ -131,17 +131,17 @@ public class SearchEngine { } return result; } - + /** * Perform the given query against the index and return results via the resultCollector. */ public void search(IIndexQuery search, ISearchResultCollector resultCollector, IProgressMonitor progressMonitor, int waitingPolicy) { - + HashSet pathCollector= new HashSet(); IProgressMonitor pm= progressMonitor == null ? null : new SubProgressMonitor(progressMonitor, 5); execute(search, pathCollector, pm); - + /* TODO_SEARCH */ for (IFile file : getFiles(pathCollector, ResourcesPlugin.getWorkspace())) { search.locateMatches(file, resultCollector); @@ -156,7 +156,7 @@ public class SearchEngine { } return ix; } - + private boolean execute(IIndexQuery search, HashSet pathCollector, IProgressMonitor progressMonitor) { if (progressMonitor != null && progressMonitor.isCanceled()) @@ -185,7 +185,7 @@ public class SearchEngine { } } } - + private IIndex[] getIndexes(IIndexQuery search) { IPath[] fIndexKeys= null; // cache of the keys for looking index up ArrayList requiredIndexKeys= new ArrayList(); diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/AnnotationAdapter.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/AnnotationAdapter.java index 8c0286dacf..6af8dabd9f 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/AnnotationAdapter.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/AnnotationAdapter.java @@ -21,21 +21,21 @@ import org.eclipse.jface.text.source.Annotation; /** * Adapts a temporary or persitent annotation to a reconcile result. - * + * * @since 3.0 */ public abstract class AnnotationAdapter implements IReconcileResult { /** * Creates and returns the annotation adapted by this adapter. - * + * * @return an annotation (can be temporary or persistent) */ public abstract Annotation createAnnotation(); - + /** * The position of the annotation adapted by this adapter. - * + * * @return the position */ public abstract Position getPosition(); diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/DocumentAdapter.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/DocumentAdapter.java index 92e21ccee5..574dd0b8a9 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/DocumentAdapter.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/DocumentAdapter.java @@ -28,7 +28,7 @@ public class DocumentAdapter implements IReconcilableModel { /** * Creates a text model adapter for the given document. - * + * * @param document */ public DocumentAdapter(IDocument document) { diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JavaReconcileStep.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JavaReconcileStep.java index 21358ad7ec..5d89a33826 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JavaReconcileStep.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JavaReconcileStep.java @@ -65,7 +65,7 @@ import org.eclipse.jdt.internal.core.BufferManager; public class JavaReconcileStep extends AbstractReconcileStep { private AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup(); - + private static class TemporaryWorkingCopyOwner extends WorkingCopyOwner { @@ -80,10 +80,10 @@ public class JavaReconcileStep extends AbstractReconcileStep { } private class ProblemAdapter extends AnnotationAdapter { - + private IProblem fProblem; private Position fPosition; - + ProblemAdapter(IProblem problem) { fProblem= problem; } @@ -100,7 +100,7 @@ public class JavaReconcileStep extends AbstractReconcileStep { int start= fProblem.getSourceStart(); if (start < 0) return null; - + int length= fProblem.getSourceEnd() - fProblem.getSourceStart() + 1; if (length < 0) return null; @@ -110,29 +110,29 @@ public class JavaReconcileStep extends AbstractReconcileStep { type= IMarker.SEVERITY_ERROR; else if (fProblem.isWarning()) type= IMarker.SEVERITY_WARNING; - + return new Annotation(fAnnotationTypeLookup.getAnnotationType(IMarker.PROBLEM, type), false, fProblem.getMessage()); } - + private Position createPositionFromProblem() { int start= fProblem.getSourceStart(); if (start < 0) return null; - + int length= fProblem.getSourceEnd() - fProblem.getSourceStart() + 1; if (length < 0) return null; - + return new Position(start, length); } } private class ProblemRequestor implements IProblemRequestor { - + private List fCollectedProblems; private boolean fIsActive= false; private boolean fIsRunning= false; - + /* * @see IProblemRequestor#beginReporting() */ @@ -141,7 +141,7 @@ public class JavaReconcileStep extends AbstractReconcileStep { fIsRunning= true; fCollectedProblems= new ArrayList(); } - + /* * @see IProblemRequestor#acceptProblem(IProblem) */ @@ -150,7 +150,7 @@ public class JavaReconcileStep extends AbstractReconcileStep { if (isActive()) fCollectedProblems.add(problem); } - + /* * @see IProblemRequestor#endReporting() */ @@ -165,7 +165,7 @@ public class JavaReconcileStep extends AbstractReconcileStep { // if (isCanceled()) // return; } - + public IReconcileResult[] getReconcileResult() { Assert.isTrue(!fIsRunning); @@ -174,10 +174,10 @@ public class JavaReconcileStep extends AbstractReconcileStep { for (int i= 0; i < size; i++) result[i]= new ProblemAdapter((IProblem)fCollectedProblems.get(i)); - + return result; } - + /* * @see IProblemRequestor#isActive() */ @@ -185,10 +185,10 @@ public class JavaReconcileStep extends AbstractReconcileStep { public boolean isActive() { return fIsActive && fCollectedProblems != null && !isCanceled(); } - + /** * Sets the active state of this problem requestor. - * + * * @param isActive the state of this problem requestor */ public void setIsActive(boolean isActive) { @@ -220,13 +220,13 @@ public class JavaReconcileStep extends AbstractReconcileStep { * Adapts an <code>ICompilationUnit</code> to the <code>ITextModel</code> interface. */ class CompilationUnitAdapter implements IReconcilableModel { - + private ICompilationUnit fCompilationUnit; - + CompilationUnitAdapter(ICompilationUnit cu) { fCompilationUnit= cu; } - + private ICompilationUnit getCompilationUnit() { return fCompilationUnit; } @@ -277,7 +277,7 @@ public class JavaReconcileStep extends AbstractReconcileStep { return null; System.out.println("reconciling java model..."); //$NON-NLS-1$ - + IBuffer buffer; try { buffer= cu.getBuffer(); @@ -285,7 +285,7 @@ public class JavaReconcileStep extends AbstractReconcileStep { e.printStackTrace(); buffer= null; } - + if (buffer != null) buffer.setContents(((DocumentAdapter)getInputModel()).getDocument().get()); @@ -310,7 +310,7 @@ public class JavaReconcileStep extends AbstractReconcileStep { public IReconcilableModel getModel() { return fWorkingCopy; } - + /* * @see org.eclipse.jdt.internal.corext.util.WorkingCopyUtil#getNewWorkingCopy */ @@ -319,7 +319,7 @@ public class JavaReconcileStep extends AbstractReconcileStep { IContainer parent= jspFile.getParent(); IPackageFragment packageFragment= null; IJavaElement je= JavaCore.create(parent); - + if (je == null || !je.exists()) return null; @@ -334,12 +334,12 @@ public class JavaReconcileStep extends AbstractReconcileStep { case IJavaElement.JAVA_PROJECT: IJavaProject jProject= (IJavaProject)je; - + if (!jProject.exists()) { System.out.println("Abort reconciling: cannot create working copy: JSP is not in a Java project"); //$NON-NLS-1$ return null; } - + packageFragmentRoot= null; IPackageFragmentRoot[] packageFragmentRoots= jProject.getPackageFragmentRoots(); int i= 0; @@ -360,9 +360,9 @@ public class JavaReconcileStep extends AbstractReconcileStep { default : return null; } - + fProblemRequestor= new ProblemRequestor(); - + return packageFragment.getCompilationUnit("Demo.java").getWorkingCopy(fTemporaryWorkingCopyOwner, fProblemRequestor, getProgressMonitor()); //$NON-NLS-1$ } } diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaReconcileStep.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaReconcileStep.java index b3e7d8695e..f3c8a62475 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaReconcileStep.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaReconcileStep.java @@ -34,14 +34,14 @@ import org.eclipse.jface.text.source.translation.ITranslator; import org.eclipse.jsp.JspTranslator; /** - * This reconcile step has a JSP source document as + * This reconcile step has a JSP source document as * input model and maintains a document that contains the Java * source. * * @since 3.0 */ public class Jsp2JavaReconcileStep extends AbstractReconcileStep { - + private DocumentAdapter fModel; private ITranslator fJspTranslator; @@ -60,7 +60,7 @@ public class Jsp2JavaReconcileStep extends AbstractReconcileStep { super(step); initialize(); } - + protected void initialize() { fJspTranslator= new JspTranslator(); fJspTranslator.setTagHandlerFactory(new Jsp2JavaTagHandlerFactory()); @@ -74,7 +74,7 @@ public class Jsp2JavaReconcileStep extends AbstractReconcileStep { Assert.isTrue(getInputModel() instanceof DocumentAdapter, "wrong model"); //$NON-NLS-1$ System.out.println("reconciling jsp2java..."); //$NON-NLS-1$ - + Reader reader= new StringReader(((DocumentAdapter)fInputModel).getDocument().get()); try { String javaSource= fJspTranslator.translate(reader, "Demo"); //$NON-NLS-1$ @@ -119,16 +119,16 @@ public class Jsp2JavaReconcileStep extends AbstractReconcileStep { int javaLine; try { javaLine= fModel.getDocument().getLineOfOffset(pos.offset); - + // Adjust offset to be relative to line beginning pos.offset -= fModel.getDocument().getLineOffset(javaLine); int relativeLineOffsetInJava= pos.offset; int jspLine= smap[javaLine + 1]; // document is 0-based, smap is 1-based - + // Add Jsp line offset pos.offset += ((DocumentAdapter)getInputModel()).getDocument().getLineOffset(jspLine-1); // document is 0-based, smap is 1-based - + String jspLineStr= ((DocumentAdapter)getInputModel()).getDocument().get(((DocumentAdapter)getInputModel()).getDocument().getLineOffset(jspLine-1), ((DocumentAdapter)getInputModel()).getDocument().getLineLength(jspLine-1)); // XXX: Once partitioner is in place the partition can be used to ease section detection diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaTagHandler.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaTagHandler.java index e980d46477..69182e37f3 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaTagHandler.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaTagHandler.java @@ -22,7 +22,7 @@ import org.eclipse.jface.text.source.translation.ITagHandler; import org.eclipse.jface.text.source.translation.ITranslatorResultCollector; /** - * + * * @since 3.0 */ public class Jsp2JavaTagHandler implements ITagHandler { @@ -35,7 +35,7 @@ public class Jsp2JavaTagHandler implements ITagHandler { private String fSource; private boolean fInDeclaration; private boolean fInJavaSection; - + /* * @see org.eclipse.jface.text.source.ITagHandler#canHandleTag(java.lang.String) @@ -102,7 +102,7 @@ public class Jsp2JavaTagHandler implements ITagHandler { int javaFileOffset= "System.out.println(".length(); //$NON-NLS-1$ return jspLineStr.indexOf("<c:out value=\"${") + 16 - javaFileOffset; //$NON-NLS-1$ } - + /* * This is a good example where the relative line offset in the Java * document cannot be directly mapped back to Jsp document. @@ -116,7 +116,7 @@ public class Jsp2JavaTagHandler implements ITagHandler { int typeStart= jspLineStr.indexOf("class=\"") + 7; //$NON-NLS-1$ int typeLength= Math.max(0, jspLineStr.indexOf('"', typeStart) - typeStart); - + if (relativeLineOffsetInJava < typeLength) { javaPartitionStart= typeStart; } else if (relativeLineOffsetInJava < typeLength + variableNameLength) @@ -136,7 +136,7 @@ public class Jsp2JavaTagHandler implements ITagHandler { Assert.isTrue(resultCollector instanceof JspTranslatorResultCollector); JspTranslatorResultCollector jspResultCollector= (JspTranslatorResultCollector)resultCollector; - + if (fInUseBean) { if (fId != null && fClass != null) { jspResultCollector.appendLocalDeclaration(fClass + " " + fId + "= new " + fClass + "();\n", sourceLineNumber); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -158,7 +158,7 @@ public class Jsp2JavaTagHandler implements ITagHandler { jspResultCollector.appendContent(out.toString() + "\n", sourceLineNumber++); //$NON-NLS-1$ out.setLength(0); } else { - out.append(c); + out.append(c); } } if (out.length() > 0) { @@ -174,7 +174,7 @@ public class Jsp2JavaTagHandler implements ITagHandler { jspResultCollector.appendDeclaration(out.toString() + "\n", sourceLineNumber++); //$NON-NLS-1$ out.setLength(0); } else { - out.append(c); + out.append(c); } } if (out.length() > 0) { diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaTagHandlerFactory.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaTagHandlerFactory.java index 2635965f65..00f33951ea 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaTagHandlerFactory.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaTagHandlerFactory.java @@ -20,11 +20,11 @@ import org.eclipse.jface.text.source.translation.ITagHandlerFactory; /** * First cut of JSP to Java tag handler factory. * Only one handler is used to do the job. - * + * * @since 3.0 */ public class Jsp2JavaTagHandlerFactory implements ITagHandlerFactory { - + private ITagHandler fTagHandler= new Jsp2JavaTagHandler(); /* diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspEditor.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspEditor.java index b5d1352145..280eda7f0f 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspEditor.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspEditor.java @@ -24,7 +24,7 @@ import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; /** * A simple JSP Editor. - * + * * @since 3.0 */ public class JspEditor extends TextEditor { @@ -36,8 +36,8 @@ public class JspEditor extends TextEditor { super(); setSourceViewerConfiguration(new JspSourceViewerConfiguration(this)); setDocumentProvider(new FileDocumentProvider()); - - + + /* * FIXME: * This would be the right thing to do. Currently diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspReconcilingStrategy.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspReconcilingStrategy.java index 21ea187771..a6de445389 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspReconcilingStrategy.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspReconcilingStrategy.java @@ -50,7 +50,7 @@ public class JspReconcilingStrategy implements IReconcilingStrategy, IReconcilin private IReconcileStep fFirstStep; private ITextEditor fTextEditor; private IProgressMonitor fProgressMonitor; - + public JspReconcilingStrategy(ISourceViewer sourceViewer, ITextEditor textEditor) { fTextEditor= textEditor; IReconcileStep javaReconcileStep= new JavaReconcileStep(getFile()); @@ -64,7 +64,7 @@ public class JspReconcilingStrategy implements IReconcilingStrategy, IReconcilin public void setDocument(IDocument document) { fFirstStep.setInputModel(new DocumentAdapter(document)); } - + /* * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion) */ @@ -73,7 +73,7 @@ public class JspReconcilingStrategy implements IReconcilingStrategy, IReconcilin removeTemporaryAnnotations(); process(fFirstStep.reconcile(dirtyRegion, subRegion)); } - + /* * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion) */ @@ -90,7 +90,7 @@ public class JspReconcilingStrategy implements IReconcilingStrategy, IReconcilin public void setProgressMonitor(IProgressMonitor monitor) { fFirstStep.setProgressMonitor(monitor); fProgressMonitor= monitor; - + } /* @@ -99,11 +99,11 @@ public class JspReconcilingStrategy implements IReconcilingStrategy, IReconcilin @Override public void initialReconcile() { fFirstStep.reconcile(null); - + } private void process(final IReconcileResult[] results) { - + if (results == null) return; @@ -132,7 +132,7 @@ public class JspReconcilingStrategy implements IReconcilingStrategy, IReconcilin e.printStackTrace(); } } - + private IAnnotationModel getAnnotationModel() { return fTextEditor.getDocumentProvider().getAnnotationModel(fTextEditor.getEditorInput()); } @@ -141,7 +141,7 @@ public class JspReconcilingStrategy implements IReconcilingStrategy, IReconcilin * XXX: A "real" implementation must be smarter * i.e. don't remove and add the annotations * which are the same. - */ + */ private void removeTemporaryAnnotations() { Iterator iter= getAnnotationModel().getAnnotationIterator(); while (iter.hasNext()) { @@ -158,7 +158,7 @@ public class JspReconcilingStrategy implements IReconcilingStrategy, IReconcilin IEditorInput input= fTextEditor.getEditorInput(); if (!(input instanceof IFileEditorInput)) return null; - - return ((IFileEditorInput)input).getFile(); + + return ((IFileEditorInput)input).getFile(); } } diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspSourceViewerConfiguration.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspSourceViewerConfiguration.java index 73b1d79408..c3a4996492 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspSourceViewerConfiguration.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspSourceViewerConfiguration.java @@ -29,7 +29,7 @@ import org.eclipse.ui.texteditor.ITextEditor; /** * Configuration information for a simple JSP source viewer. - * + * * @since 3.0 */ public class JspSourceViewerConfiguration extends SourceViewerConfiguration { @@ -39,13 +39,13 @@ public class JspSourceViewerConfiguration extends SourceViewerConfiguration { /** * Creates a new JSP source viewer configuration that behaves according to * the specification of this class' methods. - * + * * @param textEditor the text editor */ public JspSourceViewerConfiguration(ITextEditor textEditor) { fTextEditor= textEditor; } - + /* * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer) */ diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspTranslatorResultCollector.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspTranslatorResultCollector.java index a9d5687a8f..99e0dbec8f 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspTranslatorResultCollector.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspTranslatorResultCollector.java @@ -20,7 +20,7 @@ import org.eclipse.jface.text.source.translation.ITranslatorResultCollector; /** * Collects the result for the JspTranslator. - * + * * @since 3.0 */ public class JspTranslatorResultCollector implements ITranslatorResultCollector { @@ -28,7 +28,7 @@ public class JspTranslatorResultCollector implements ITranslatorResultCollector private StringBuffer fDeclarations= new StringBuffer(); private StringBuffer fContent= new StringBuffer(); private StringBuffer fLocalDeclarations= new StringBuffer(); - + private ArrayList fContentLines= new ArrayList(); private ArrayList fDeclarationLines= new ArrayList(); private ArrayList fLocalDeclarationLines= new ArrayList(); diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITagHandler.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITagHandler.java index ec47ccf4c3..daecea03ca 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITagHandler.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITagHandler.java @@ -25,64 +25,64 @@ import java.io.IOException; * <p> * Tag handlers are used by translators via tag handler factories. The factory * can either return a new tag or one that already has some attributes. </p> - * + * * @see org.eclipse.jface.text.source.translation.ITranslator * @see org.eclipse.jface.text.source.translation.ITagHandlerFactory * @since 3.0 */ public interface ITagHandler { - + /** * Tells whether this handler can handle the given tag. - * + * * @param tag the tag to check * @return <code>true</code> if this handler handles the given tag */ boolean canHandleTag(String tag); - + /** * Tells whether this handler can handle the given text. Most * likely the handler will check if the text contains a tag * that he can handle. - * + * * @param text the text to check * @return <code>true</code> if this handler handles the given text */ boolean canHandleText(String text); - + /** * Adds an attribute to this tag handler. - * + * * @param name the name of the attribute * @param value the attribute value * @param sourceLineNumber the line number of the attribute in the source or <code>-1</code> if unknown */ void addAttribute(String name, String value, int sourceLineNumber); - + /** * Resets this handler and sets the current tag to the given tag. * A handler can handle more than one tag but only one tag at a time. * <p> * Resetting the handler clears the attributes.</p> - * + * * @param tag the tag to check */ void reset(String tag); - + /** - * Writes the tag and line mapping information to the + * Writes the tag and line mapping information to the * given translator result collector. - * + * * @param resultCollector the translator's result collector * @param sourceLineNumber the line number of the attribute in the source or <code>-1</code> if unknown * @throws IOException */ void processEndTag(ITranslatorResultCollector resultCollector, int sourceLineNumber) throws IOException; - + /** * Computes the offset in the source line that corresponds - * to the given offset in the translated line. - * + * to the given offset in the translated line. + * * @param sourceLine the source line * @param translatedLine the translated line * @param offsetInTranslatedLine the offset in the translated line diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITagHandlerFactory.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITagHandlerFactory.java index 6e121bf50b..6810cccc4f 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITagHandlerFactory.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITagHandlerFactory.java @@ -17,31 +17,31 @@ package org.eclipse.jface.text.source.translation; /** * A tag handler factory provides access to tag * handlers. - * + * * @since 3.0 */ public interface ITagHandlerFactory { - + /** * Returns a handler that can handle the * given tag. * <p> * Depending on the used handler the factory might - * return a new or a shared instance.</p> + * return a new or a shared instance.</p> * - * @param tag the tag for which to return the handler + * @param tag the tag for which to return the handler * @return a tag handler or <code>null</code> if no handler * is available */ public ITagHandler getHandler(String tag); - + /** * Finds and returns a handler that can handle * the given text snippet. * <p> * Depending on the used handler the factory might - * return a new or a shared instance.</p> - * + * return a new or a shared instance.</p> + * * @param text the text for which to find a handler * @return a tag handler or <code>null</code> if no handler * is available diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITranslator.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITranslator.java index 581673e84c..eb208cbc74 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITranslator.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITranslator.java @@ -23,16 +23,16 @@ import java.io.Reader; * information for the translation and to compute which offset * in an original line corresponds to a given offset in a * target line. - * + * * @since 3.0 */ public interface ITranslator { - + /** * Reads the source from the given reader and creates * translates it into another language. The translated * source might be given the optional name. - * + * * @param reader the reader to access the source * @param name the name of the translated source or <code>null</code> if none * @return @@ -42,29 +42,29 @@ public interface ITranslator { /** * Returns the line mapping information. - * + * * @return an int array where the index corresponds to line * numbers in the translation and the value is a * source line number - */ + */ int[] getLineMapping(); - + /** * Assigns an optional tag handler factory to this translator. * <p> * A translator can delegate the handling of individual tags * to tag handlers. The factory is responsible to provide * the correct tag handlers.</p> - * + * * @param tagHandlerFactory a tag handler factory or <code>null</code> - * if this translator does all work itself + * if this translator does all work itself */ void setTagHandlerFactory(ITagHandlerFactory tagHandlerFactory); - + /** * Computes the offset in the source line that corresponds - * to the given offset in the translated line. - * + * to the given offset in the translated line. + * * @param sourceLine the source line * @param translatedLine the translated line * @param offsetInTranslatedLine the offset in the translated line @@ -73,5 +73,5 @@ public interface ITranslator { * @return the offset in the source line or <code>-1</code> if * it was not possible to compute the offset */ - int backTranslateOffsetInLine(String sourceLine, String translatedLine, int offsetInTranslatedLine, String tag); + int backTranslateOffsetInLine(String sourceLine, String translatedLine, int offsetInTranslatedLine, String tag); } diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITranslatorResultCollector.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITranslatorResultCollector.java index aa6878c194..bea4948a10 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITranslatorResultCollector.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/ITranslatorResultCollector.java @@ -16,7 +16,7 @@ package org.eclipse.jface.text.source.translation; /** * Tagging interface for a translator result collector. - * + * * @since 3.0 */ public interface ITranslatorResultCollector { diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/TagHandlerFactory.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/TagHandlerFactory.java index 1af5b68cab..bd5d83d9f7 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/TagHandlerFactory.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/translation/TagHandlerFactory.java @@ -22,7 +22,7 @@ import org.eclipse.core.runtime.Assert; /** * Default implementation of a tag handler factory - * + * * @since 3.0 */ public class TagHandlerFactory implements ITagHandlerFactory { @@ -32,7 +32,7 @@ public class TagHandlerFactory implements ITagHandlerFactory { public void addTagHandler(String tag, ITagHandler handler) { Assert.isNotNull(tag); Assert.isNotNull(handler); - + fHandlers.put(tag, handler); } diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/AbstractJspParser.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/AbstractJspParser.java index 9e80dae65e..0231ad1633 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/AbstractJspParser.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/AbstractJspParser.java @@ -16,18 +16,18 @@ package org.eclipse.jsp; import java.io.IOException; import java.io.Reader; -public abstract class AbstractJspParser { - +public abstract class AbstractJspParser { + private Reader fReader; private boolean fHasUnread; private int fUnread; private int fPos; protected int fLines= 1; - + AbstractJspParser() { super(); } - + private int getc() throws IOException { fPos++; if (fHasUnread) { @@ -47,13 +47,13 @@ public abstract class AbstractJspParser { } return ch; } - + private void ungetc(int c) { fHasUnread= true; fUnread= c; fPos--; } - + private void parseDirective() throws IOException { StringBuilder sb= new StringBuilder(); int pos= fPos; @@ -70,7 +70,7 @@ public abstract class AbstractJspParser { sb.append((char)c); } } - + private void parseTag(boolean endTag) throws IOException { StringBuilder sb= new StringBuilder(); int pos= fPos; @@ -93,7 +93,7 @@ public abstract class AbstractJspParser { sb.append((char)c); } } - + private void parseComment() throws IOException { while (true) { int c = getc(); @@ -127,13 +127,13 @@ public abstract class AbstractJspParser { sb.append((char)c); } } - + protected void java(char tagType, String contents, int line) { // empty implementation } private void parseAttributes(int pos, String s) { - + boolean hasValue= false; StringBuilder name= new StringBuilder(); StringBuffer value= new StringBuffer(); @@ -143,14 +143,14 @@ public abstract class AbstractJspParser { int startName= 0; int startValue= 0; char c= s.charAt(i++); - + try { while (true) { - - // whitespace + + // whitespace while (Character.isWhitespace(c)) c= s.charAt(i++); - + startName= i; while (Character.isLetterOrDigit(c) || c == ':') { name.append(c); @@ -160,19 +160,19 @@ public abstract class AbstractJspParser { // avoid endless loop, e.g. for <!DOCTYPE html> return; } - - // whitespace + + // whitespace while (Character.isWhitespace(c)) c= s.charAt(i++); - + hasValue= false; if (c == '=') { c= s.charAt(i++); - + // value while (Character.isWhitespace(c)) c= s.charAt(i++); - + startValue= i; // Special handling for this taglib tag @@ -197,14 +197,14 @@ public abstract class AbstractJspParser { } hasValue= true; } - + if (ix == 0) { startTag= name.toString(); startTag(false, startTag, startName+pos); - } else + } else tagAttribute(name.toString(), hasValue ? value.toString() : null, startName+pos, startValue+pos); ix++; - + name.setLength(0); value.setLength(0); } @@ -212,40 +212,40 @@ public abstract class AbstractJspParser { // we don't log this exception because it is used // as one way to exit the scanning loop } - + if (name.length() > 0) { if (ix == 0) startTag(false, name.toString(), startName+pos); - else + else tagAttribute(name.toString(), hasValue ? value.toString() : null, startName+pos, startValue+pos); } - + endTag(false); } - + protected void startTag(boolean endTag, String name, int startName) { // empty implementation } - + protected void tagAttribute(String attrName, String value, int startName, int startValue) { // empty implementation } - + protected void endTag(boolean end) { // empty implementation } - + protected void text(String t, int line) { // empty implementation } - + void parse(Reader reader) throws IOException { int c; StringBuilder buffer= new StringBuilder(); fPos= 0; fLines= 1; int line= fLines; - fReader= reader; + fReader= reader; while (true) { c= getc(); @@ -273,7 +273,7 @@ public abstract class AbstractJspParser { } else { ungetc(c); continue; - } + } break; case '@': parseDirective(); diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JavaFamilyExamplePreferencePage.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JavaFamilyExamplePreferencePage.java index a3db923886..afc8cb093b 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JavaFamilyExamplePreferencePage.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JavaFamilyExamplePreferencePage.java @@ -30,7 +30,7 @@ public class JavaFamilyExamplePreferencePage extends PreferencePage implements I protected Control createContents(Composite parent) { Composite c= new Composite(parent, SWT.NULL); //c.setLayout(new FillLayout()); - + final Button b= new Button(c, SWT.NULL); b.setText(getButtonLabel()); b.addSelectionListener(new SelectionAdapter() { @@ -41,16 +41,16 @@ public class JavaFamilyExamplePreferencePage extends PreferencePage implements I } }); b.pack(); - + return c; } - + private String getButtonLabel() { if (JspUIPlugin.getDefault().isJSPIndexingOn()) return "Stop JSP Indexing"; //$NON-NLS-1$ return "Start JSP Indexing"; //$NON-NLS-1$ } - + @Override public void init(IWorkbench workbench) { // empty implementation diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspIndexParser.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspIndexParser.java index 781afb60c5..ffc2781a38 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspIndexParser.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspIndexParser.java @@ -25,26 +25,26 @@ import org.eclipse.core.runtime.*; * @author weinand */ public class JspIndexParser extends AbstractJspParser implements IIndexer { - + public static final String JSP_TYPE_REF= "jsp_typeRef"; //$NON-NLS-1$ - + IFile fFile; String fFilePath; boolean fInUseBean; String fId; String fClass; IIndex fOutput; - + JspIndexParser(IFile resource) { fFile= resource; } - + @Override protected void startTag(boolean endTag, String name, int startName) { fInUseBean= "jsp:useBean".equals(name); //$NON-NLS-1$ } - + @Override protected void tagAttribute(String attrName, String value, int startName, int startValue) { if (fInUseBean) { @@ -54,7 +54,7 @@ public class JspIndexParser extends AbstractJspParser implements IIndexer { fClass= value; } } - + @Override protected void endTag(boolean end) { if (fInUseBean) { @@ -62,23 +62,23 @@ public class JspIndexParser extends AbstractJspParser implements IIndexer { String s= JSP_TYPE_REF + "/" + fClass; //$NON-NLS-1$ System.out.println(" " + s); //$NON-NLS-1$ - fOutput.addRef(s, fFilePath); + fOutput.addRef(s, fFilePath); fId= fClass= null; } fInUseBean= false; } } - + @Override public void index(IIndex indexerOutput) throws IOException { - + String type= fFile.getFileExtension(); if (type != null && JspUIPlugin.JSP_TYPE.equalsIgnoreCase(type)) { - + // Add the name of the file to the index String path= fFile.getFullPath().toString(); - + String encoding= null; try { encoding= fFile.getCharset(); @@ -86,18 +86,18 @@ public class JspIndexParser extends AbstractJspParser implements IIndexer { } if (encoding == null) encoding= ResourcesPlugin.getEncoding(); - + String s= null; IPath location= fFile.getLocation(); if (location == null) s= ""; //$NON-NLS-1$ else s= new String(Util.getFileCharContent(location.toFile(), encoding)); - + try { Reader reader= new StringReader(s); fOutput= indexerOutput; - fFilePath= path; + fFilePath= path; parse(reader); } catch (IOException e) { e.printStackTrace(); diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspMatchLocatorParser.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspMatchLocatorParser.java index 3d30e87c03..53830ec944 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspMatchLocatorParser.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspMatchLocatorParser.java @@ -53,18 +53,18 @@ public class JspMatchLocatorParser extends AbstractJspParser { } public void match(IFile resource, String matchString, ISearchResultCollector collector) { - + fResource= resource; fMatchString= matchString; fCollector= collector; Reader reader= null; - + try { reader= new InputStreamReader(fResource.getContents()); } catch (CoreException e1) { e1.printStackTrace(); } - + try { parse(reader); } catch (IOException e2) { diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspPluginImages.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspPluginImages.java index b88f7e8cfc..735833724a 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspPluginImages.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspPluginImages.java @@ -30,22 +30,22 @@ import org.eclipse.debug.core.DebugPlugin; */ public class JspPluginImages { - /** + /** * The image registry containing <code>Image</code>s. */ private static ImageRegistry imageRegistry; - + /** * A table of all the <code>ImageDescriptor</code>s. */ private static HashMap imageDescriptors; - + /* Declare Common paths */ private static URL ICON_BASE_URL= null; static { String pathSuffix = "icons/full/"; //$NON-NLS-1$ - + try { ICON_BASE_URL= new URL(JspUIPlugin.getDefault().getBundle().getEntry("/"), pathSuffix); //$NON-NLS-1$ } catch (MalformedURLException e) { @@ -62,10 +62,10 @@ public class JspPluginImages { //private final static String WIZBAN= "wizban/"; //basic colors - size 16x16 //$NON-NLS-1$ //private final static String OVR= "ovr16/"; //basic colors - size 7x8 //$NON-NLS-1$ //private final static String VIEW= "cview16/"; // views //$NON-NLS-1$ - + public final static String IMG_OBJ_TOMCAT = "IMG_TOMCAT"; //$NON-NLS-1$ public final static String IMG_OBJ_JSP = "IMG_OBJ_JSP"; //$NON-NLS-1$ - + /** * Declare all images */ @@ -91,7 +91,7 @@ public class JspPluginImages { imageRegistry.put(key, desc); imageDescriptors.put(key, desc); } - + /** * Returns the ImageRegistry. */ @@ -144,7 +144,7 @@ public class JspPluginImages { public static Image getImage(String key) { return getImageRegistry().get(key); } - + /** * Returns the <code>ImageDescriptor<code> identified by the given key, * or <code>null</code> if it does not exist. @@ -155,12 +155,12 @@ public class JspPluginImages { } return (ImageDescriptor)imageDescriptors.get(key); } - + private static URL makeIconFileURL(String iconPath) throws MalformedURLException { if (ICON_BASE_URL == null) { throw new MalformedURLException(); } - + return new URL(ICON_BASE_URL, iconPath); } } diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspSearchEngine.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspSearchEngine.java index 67a0db503d..e246515abd 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspSearchEngine.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspSearchEngine.java @@ -24,9 +24,9 @@ import org.eclipse.jdt.core.search.IJavaSearchResultCollector; public class JspSearchEngine { public static void search(final IJavaSearchResultCollector collector, final IIndexQuery query, IProgressMonitor pm) { - + System.out.println("JspSearchEngine.search: " + query); //$NON-NLS-1$ - + JspUIPlugin.getDefault().search( query, new ISearchResultCollector() { diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspTranslator.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspTranslator.java index 8660355a24..4bfe4fa130 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspTranslator.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspTranslator.java @@ -25,41 +25,41 @@ import org.eclipse.jdt.internal.ui.examples.jspeditor.JspTranslatorResultCollect public class JspTranslator extends AbstractJspParser implements ITranslator { - + private StringBuffer fDeclarations= new StringBuffer(); private StringBuffer fContent= new StringBuffer(); private StringBuffer fLocalDeclarations= new StringBuffer(); - + private ArrayList fContentLines= new ArrayList(); private ArrayList fDeclarationLines= new ArrayList(); private ArrayList fLocalDeclarationLines= new ArrayList(); private int[] fSmap; - + private ITagHandlerFactory fTagHandlerFactor; private ITagHandler fCurrentTagHandler; private JspTranslatorResultCollector fResultCollector; - - + + public JspTranslator() { - - // Links for passing parameters to the tag handlers + + // Links for passing parameters to the tag handlers fResultCollector= new JspTranslatorResultCollector(fDeclarations, fLocalDeclarations, fContent, fDeclarationLines, fLocalDeclarationLines, fContentLines); } - + @Override protected void startTag(boolean endTag, String name, int startName) { fCurrentTagHandler= fTagHandlerFactor.getHandler(name); } - + @Override protected void tagAttribute(String attrName, String value, int startName, int startValue) { if (fCurrentTagHandler != null) fCurrentTagHandler.addAttribute(attrName, value, fLines); } - + @Override protected void endTag(boolean end) { @@ -70,7 +70,7 @@ public class JspTranslator extends AbstractJspParser implements ITranslator { ex.printStackTrace(); } } - + @Override protected void java(char ch, String java, int line) { @@ -91,7 +91,7 @@ public class JspTranslator extends AbstractJspParser implements ITranslator { e.printStackTrace(); } } - + @Override protected void text(String t, int line) { int i= 0; @@ -103,7 +103,7 @@ public class JspTranslator extends AbstractJspParser implements ITranslator { fContentLines.add(Integer.valueOf(line++)); out.setLength(0); } else { - out.append(c); + out.append(c); } } if (out.length() > 0) { @@ -111,23 +111,23 @@ public class JspTranslator extends AbstractJspParser implements ITranslator { fContentLines.add(Integer.valueOf(line)); } } - + private void resetTranslator() { fDeclarations.setLength(0); fContent.setLength(0); fLocalDeclarations.setLength(0); - + fLocalDeclarationLines.clear(); fContentLines.clear(); fDeclarationLines.clear(); - + } @Override public String translate(Reader reader, String name) throws IOException { StringBuilder buffer= new StringBuilder(); - + resetTranslator(); parse(reader); @@ -152,7 +152,7 @@ public class JspTranslator extends AbstractJspParser implements ITranslator { buffer.append(" public void out() {\n"); //$NON-NLS-1$ fSmap[line]= fSmap[line - 1] + 1; line++; - + if (fLocalDeclarations.length() > 0) { buffer.append(fLocalDeclarations.toString()); System.out.println(fLocalDeclarations); @@ -161,7 +161,7 @@ public class JspTranslator extends AbstractJspParser implements ITranslator { fSmap[line++]= ((Integer)fLocalDeclarationLines.get(i)).intValue(); } } - + buffer.append(fContent.toString()); System.out.println(fContent); for (int i= 0; i < fContentLines.size(); i++) { @@ -173,18 +173,18 @@ public class JspTranslator extends AbstractJspParser implements ITranslator { fSmap[line]= fSmap[line - 1]; line++; - + buffer.append("}\n"); //$NON-NLS-1$ fSmap[line]= fSmap[line - 2]; - + for (int i= 0; i < fSmap.length; i++) System.out.println("" + i + " -> " + fSmap[i]); //$NON-NLS-1$ //$NON-NLS-2$ - + System.out.println(buffer.toString()); - + return buffer.toString(); } - + @Override public int[] getLineMapping() { return fSmap; diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspTypeQuery.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspTypeQuery.java index aaa83cc139..4b68375b64 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspTypeQuery.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspTypeQuery.java @@ -36,11 +36,11 @@ public class JspTypeQuery implements IIndexQuery { private IType fType; private JspMatchLocatorParser fParser; - + public JspTypeQuery(IType type) { fType= type; } - + @Override public void computePathsKeyingIndexFiles(ArrayList requiredIndexKeys) { IWorkspace workspace= ResourcesPlugin.getWorkspace(); diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspUIPlugin.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspUIPlugin.java index 0ca2351ede..8e03f2afa5 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspUIPlugin.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/JspUIPlugin.java @@ -48,26 +48,26 @@ import org.eclipse.ui.editors.text.TextEditorPreferenceConstants; /** */ public class JspUIPlugin extends AbstractUIPlugin implements IResourceChangeListener { - + /** * The id of the JavaFamilyExample plugin (value <code>"org.eclipse.jdt.ui.examples.javafamily"</code>). - */ + */ public static final String ID_PLUGIN= "org.eclipse.jdt.ui.examples.javafamily"; //$NON-NLS-1$ public static final String JSP_TYPE= "jsp"; //$NON-NLS-1$ - + private static final boolean DEBUG= false; private static JspUIPlugin fgDefault; private static boolean fgJSPIndexingIsEnabled= false; - + private SearchEngine fSearchEngine; - + public JspUIPlugin() { super(); fgDefault= this; fSearchEngine= SearchEngine.getSearchEngine(); } - + public static JspUIPlugin getDefault() { return fgDefault; } @@ -77,7 +77,7 @@ public class JspUIPlugin extends AbstractUIPlugin implements IResourceChangeList fgJSPIndexingIsEnabled= enable; IWorkspace workspace= ResourcesPlugin.getWorkspace(); if (enable) { - + IResourceProxyVisitor visitor= new IResourceProxyVisitor() { @Override @@ -100,24 +100,24 @@ public class JspUIPlugin extends AbstractUIPlugin implements IResourceChangeList } catch (CoreException e) { log("visiting jsp files", e); //$NON-NLS-1$ } - + workspace.addResourceChangeListener(this, // IResourceChangeEvent.PRE_AUTO_BUILD | // IResourceChangeEvent.POST_AUTO_BUILD | IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE - ); + ); } else { - workspace.removeResourceChangeListener(this); + workspace.removeResourceChangeListener(this); } } } - + boolean isJSPIndexingOn() { return fgJSPIndexingIsEnabled; } - + @Override public void resourceChanged(IResourceChangeEvent event) { if ( !fgJSPIndexingIsEnabled || event == null) @@ -148,7 +148,7 @@ public class JspUIPlugin extends AbstractUIPlugin implements IResourceChangeList if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) jspAdded(file); break; - } + } } } } @@ -160,32 +160,32 @@ public class JspUIPlugin extends AbstractUIPlugin implements IResourceChangeList log("processing resource delta", e); //$NON-NLS-1$ } } - + public static void log(String message, Throwable e) { getDefault().getLog().log(new Status(IStatus.ERROR, ID_PLUGIN, IStatus.ERROR, message, e)); } - + void jspAdded(IFile jspFile) { - if (DEBUG) System.out.println("Added: " + jspFile); //$NON-NLS-1$ + if (DEBUG) System.out.println("Added: " + jspFile); //$NON-NLS-1$ JspIndexParser indexer= new JspIndexParser(jspFile); fSearchEngine.add(jspFile.getProject().getFullPath(), indexer); } - + void jspRemoved(IFile jspFile) { if (DEBUG) System.out.println("Removed: " + jspFile); //$NON-NLS-1$ fSearchEngine.remove(jspFile.getFullPath().toString(), jspFile.getProject().getFullPath()); } - + public void search(IIndexQuery query, ISearchResultCollector resultCollector, IProgressMonitor pm) { fSearchEngine.search(query, resultCollector, pm, SearchEngine.WAIT_UNTIL_READY_TO_SEARCH); } - + @Override public void start(BundleContext context) throws Exception { super.start(context); initializeDefaultPreferences(); } - + @Override public void stop(BundleContext context) throws Exception { try { @@ -194,12 +194,12 @@ public class JspUIPlugin extends AbstractUIPlugin implements IResourceChangeList super.stop(context); } } - + private void initializeDefaultPreferences() { IPreferenceStore prefs= getPreferenceStore(); TextEditorPreferenceConstants.initializeDefaultValues(prefs); } - + /** * Returns the standard display to be used. The method first checks, if * the thread calling this method has an associated display. If so, this @@ -210,12 +210,12 @@ public class JspUIPlugin extends AbstractUIPlugin implements IResourceChangeList if (display == null) { display= Display.getDefault(); } - return display; + return display; } - + @Override protected ImageRegistry createImageRegistry() { return JspPluginImages.initializeImageRegistry(); - } - + } + } diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/RenameTypeParticipant.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/RenameTypeParticipant.java index fe639b849d..2bf258351a 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/RenameTypeParticipant.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/RenameTypeParticipant.java @@ -50,9 +50,9 @@ public class RenameTypeParticipant extends RenameParticipant { @Override public String getName() { - return JspMessages.RenameTypeParticipant_name; + return JspMessages.RenameTypeParticipant_name; } - + @Override public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) { return new RefactoringStatus(); @@ -74,7 +74,7 @@ public class RenameTypeParticipant extends RenameParticipant { } }; JspUIPlugin.getDefault().search(new JspTypeQuery(fType), collector, pm); - + if (changes.isEmpty()) return null; CompositeChange result= new CompositeChange("JSP updates"); //$NON-NLS-1$ @@ -83,7 +83,7 @@ public class RenameTypeParticipant extends RenameParticipant { } return result; } - + private String computeNewName() { String newName= getArguments().getNewName(); String currentName= fType.getFullyQualifiedName(); diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/Util.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/Util.java index 08c5902c5e..0023bca449 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/Util.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/Util.java @@ -17,7 +17,7 @@ import java.io.*; import java.io.File; public class Util { - + static char[] getChars(String s) { int l= s.length(); char[] cc= new char[l]; @@ -25,7 +25,7 @@ public class Util { s.getChars(0, l, cc, 0); return cc; } - + static char[] getFileCharContent(File file, String encoding) throws IOException { System.out.println("****jdt.internal.compiler.util.Util.getFileCharContent: " + file + " " + encoding); //$NON-NLS-1$ //$NON-NLS-2$ InputStream stream = null; diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/ToggleJspBreakpointAction.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/ToggleJspBreakpointAction.java index ef9f227700..83efb98227 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/ToggleJspBreakpointAction.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/ToggleJspBreakpointAction.java @@ -37,10 +37,10 @@ import org.eclipse.debug.core.model.IBreakpoint; * ToggleJspBreakpointAction */ public class ToggleJspBreakpointAction extends Action { - + private ITextEditor fEditor; private IVerticalRulerInfo fRulerInfo; - + @Override public void run() { IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); @@ -64,7 +64,7 @@ public class ToggleJspBreakpointAction extends Action { } createBreakpoint(); } - + protected void createBreakpoint() { IResource resource = getResource(); int lineNumber = fRulerInfo.getLineOfLastMouseButtonActivity() + 1; diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatClasspathProvider.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatClasspathProvider.java index 7aeba73b5f..33cdb8714f 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatClasspathProvider.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatClasspathProvider.java @@ -36,7 +36,7 @@ public class TomcatClasspathProvider extends StandardClasspathProvider { /** * Tomcat requires <code>tools.jar</code> and <code>bootstrap.jar</code> on its * classpath. - * + * * @see org.eclipse.jdt.launching.IRuntimeClasspathProvider#computeUnresolvedClasspath(org.eclipse.debug.core.ILaunchConfiguration) */ @Override @@ -53,8 +53,8 @@ public class TomcatClasspathProvider extends StandardClasspathProvider { IRuntimeClasspathEntry r = JavaRuntime.newArchiveRuntimeClasspathEntry(path); r.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); rtes.add(r); - // add class libraries to bootpath - boolean tools = false; // keeps track of whether a tools.jar was found + // add class libraries to bootpath + boolean tools = false; // keeps track of whether a tools.jar was found for (LibraryLocation lib : JavaRuntime.getLibraryLocations(vm)) { if (lib.getSystemLibraryPath().toString().endsWith("tools.jar")) { //$NON-NLS-1$ tools = true; diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatLaunchDelegate.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatLaunchDelegate.java index db08dddfc3..3772cb5330 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatLaunchDelegate.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatLaunchDelegate.java @@ -36,18 +36,18 @@ public class TomcatLaunchDelegate extends JavaLaunchDelegate { * Identifier for Tomcat launch configurations. */ public static final String ID_TOMCAT_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.jsp.TomcatConfigurationType"; //$NON-NLS-1$ - + /** * Identifier for Tomcat classpath provider. */ public static final String ID_TOMCAT_CLASSPATH_PROVIDER = "org.eclipse.jsp.tomcatClasspathProvider"; //$NON-NLS-1$ - + /** * Launch configuration attribute - value is path to local installation of Tomcat. * The path may be encoded in a launch variable. */ public static final String ATTR_CATALINA_HOME = "org.eclipse.jsp.CATALINA_HOME"; //$NON-NLS-1$ - + /** * Constructs a new launch delegate */ @@ -57,7 +57,7 @@ public class TomcatLaunchDelegate extends JavaLaunchDelegate { /** * Returns the value of the <code>${catalina_home}</code> launch variable. - * + * * @return the value of the <code>${catalina_home}</code> launch variable * @exception CoreException if the variable or value is undefined */ @@ -65,18 +65,18 @@ public class TomcatLaunchDelegate extends JavaLaunchDelegate { IValueVariable variable = VariablesPlugin.getDefault().getStringVariableManager().getValueVariable("catalina_home"); //$NON-NLS-1$ IStatus err = null; if (variable == null) { - err = new Status(IStatus.ERROR, JspUIPlugin.getDefault().getBundle().getSymbolicName(), 0, LaunchingMessages.TomcatLaunchDelegate_9, null); + err = new Status(IStatus.ERROR, JspUIPlugin.getDefault().getBundle().getSymbolicName(), 0, LaunchingMessages.TomcatLaunchDelegate_9, null); } else { - String home = variable.getValue(); + String home = variable.getValue(); if (home != null && home.length() > 0) { File file = new File(home); if (file.exists() && file.isDirectory()) { return home; } else { - err = new Status(IStatus.ERROR, JspUIPlugin.getDefault().getBundle().getSymbolicName(), 0, MessageFormat.format(LaunchingMessages.TomcatLaunchDelegate_7, new String[]{home}), null); + err = new Status(IStatus.ERROR, JspUIPlugin.getDefault().getBundle().getSymbolicName(), 0, MessageFormat.format(LaunchingMessages.TomcatLaunchDelegate_7, new String[]{home}), null); } } else { - err = new Status(IStatus.ERROR, JspUIPlugin.getDefault().getBundle().getSymbolicName(), 0, LaunchingMessages.TomcatLaunchDelegate_8, null); + err = new Status(IStatus.ERROR, JspUIPlugin.getDefault().getBundle().getSymbolicName(), 0, LaunchingMessages.TomcatLaunchDelegate_8, null); } } throw new CoreException(err); diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatTab.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatTab.java index 07b5569721..cdf82c321c 100644 --- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatTab.java +++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jsp/launching/TomcatTab.java @@ -13,7 +13,7 @@ *******************************************************************************/ package org.eclipse.jsp.launching; - + import java.io.File; import org.eclipse.jsp.JspPluginImages; @@ -61,31 +61,31 @@ import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; * Specifies the install location of Tomcat. */ public class TomcatTab extends AbstractLaunchConfigurationTab { - - + + // Tomcat location private Button fBrowseButton; private Text fTomcatDir; - + // WebApp location private Button fProjectButton; private Text fProjectText; - + /** * Constructs a new Tomcat tab */ public TomcatTab() { super(); } - + /** * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(Composite) */ @Override public void createControl(Composite parent) { - + Font font = parent.getFont(); - + Composite composite = new Composite(parent, SWT.NONE); GridLayout workingDirLayout = new GridLayout(); workingDirLayout.numColumns = 3; @@ -96,16 +96,16 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { composite.setLayoutData(gd); composite.setFont(font); setControl(composite); - + createVerticalSpacer(composite, 3); - + Label label = new Label(composite, SWT.NONE); label.setText(LaunchingMessages.TomcatTab_3); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalSpan = 3; label.setLayoutData(gd); label.setFont(font); - + fTomcatDir = new Text(composite, SWT.SINGLE | SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; @@ -117,7 +117,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { updateLaunchConfigurationDialog(); } }); - + fBrowseButton = createPushButton(composite, LaunchingMessages.TomcatTab_21, null); fBrowseButton.addSelectionListener(new SelectionAdapter() { @Override @@ -125,16 +125,16 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { handleTomcatBrowseButtonSelected(); } }); - + createVerticalSpacer(composite, 3); - + label = new Label(composite, SWT.NONE); label.setText(LaunchingMessages.TomcatTab_22); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalSpan = 3; label.setLayoutData(gd); label.setFont(font); - + fProjectText = new Text(composite, SWT.SINGLE | SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; @@ -146,7 +146,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { updateLaunchConfigurationDialog(); } }); - + fProjectButton = createPushButton(composite, LaunchingMessages.TomcatTab_23, null); fProjectButton.addSelectionListener(new SelectionAdapter() { @Override @@ -155,7 +155,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { } }); } - + /** * Show a dialog that lets the user select a project * from the workspace @@ -173,7 +173,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { fProjectText.setText(((IResource)elements[0]).getName()); } } - + } /** @@ -189,13 +189,13 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { dialog.setFilterPath(currentWorkingDir); } } - + String selectedDirectory = dialog.open(); if (selectedDirectory != null) { fTomcatDir.setText(selectedDirectory); } } - + /** * @see org.eclipse.debug.ui.ILaunchConfigurationTab#dispose() */ @@ -203,7 +203,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { public void dispose() { // empty implementation } - + /** * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(ILaunchConfiguration) */ @@ -211,7 +211,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { public boolean isValid(ILaunchConfiguration config) { setErrorMessage(null); setMessage(null); - + String workingDirPath = fTomcatDir.getText().trim(); // resolve variables (if any) String expansion; @@ -232,7 +232,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { return false; } } - + String projectName = fProjectText.getText().trim(); if (projectName.length() > 0) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); @@ -241,7 +241,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { return false; } } - + return true; } @@ -303,7 +303,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { /** * Returns the string in the text widget, or <code>null</code> if empty. - * + * * @param text the text field * @return text or <code>null</code> */ @@ -314,7 +314,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { } return null; } - + /** * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName() */ @@ -322,7 +322,7 @@ public class TomcatTab extends AbstractLaunchConfigurationTab { public String getName() { return LaunchingMessages.TomcatTab_7; } - + /** * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage() */ diff --git a/org.eclipse.jdt.ui.examples.projects/.classpath b/org.eclipse.jdt.ui.examples.projects/.classpath index d3daf0a5b1..35175ddfb3 100644 --- a/org.eclipse.jdt.ui.examples.projects/.classpath +++ b/org.eclipse.jdt.ui.examples.projects/.classpath @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="examples"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/org.eclipse.jdt.ui.examples.projects/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.ui.examples.projects/.settings/org.eclipse.jdt.core.prefs index 1306974315..d4507da71c 100644 --- a/org.eclipse.jdt.ui.examples.projects/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.jdt.ui.examples.projects/.settings/org.eclipse.jdt.core.prefs @@ -15,9 +15,9 @@ org.eclipse.jdt.core.codeComplete.localSuffixes= org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=fg org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -109,7 +109,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 diff --git a/org.eclipse.jdt.ui.examples.projects/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.ui.examples.projects/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.ui.examples.projects/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.ui.examples.projects/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.ui.examples.projects/META-INF/MANIFEST.MF b/org.eclipse.jdt.ui.examples.projects/META-INF/MANIFEST.MF index f8976937ce..161463cec9 100644 --- a/org.eclipse.jdt.ui.examples.projects/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.ui.examples.projects/META-INF/MANIFEST.MF @@ -15,4 +15,4 @@ Require-Bundle: org.eclipse.core.resources, org.eclipse.ui.workbench, org.eclipse.jface Export-Package: org.eclipse.jdt.internal.ui.exampleprojects;x-internal:=true -Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationOperation.java b/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationOperation.java index a6c585d2e2..3956d6e734 100644 --- a/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationOperation.java +++ b/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationOperation.java @@ -60,9 +60,7 @@ public class ExampleProjectCreationOperation implements IRunnableWithProgress { fOverwriteQuery= overwriteQuery; } - /* - * @see IRunnableWithProgress#run(IProgressMonitor) - */ + @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (monitor == null) { monitor= new NullProgressMonitor(); diff --git a/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationWizard.java b/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationWizard.java index 48fe3674b8..df8e3ad58f 100644 --- a/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationWizard.java +++ b/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationWizard.java @@ -69,9 +69,7 @@ public class ExampleProjectCreationWizard extends Wizard implements INewWizard, } } - /* - * @see Wizard#addPages - */ + @Override public void addPages() { super.addPages(); if (fPage != null) { @@ -79,9 +77,7 @@ public class ExampleProjectCreationWizard extends Wizard implements INewWizard, } } - /* - * @see Wizard#performFinish - */ + @Override public boolean performFinish() { if (fPage != null) { ExampleProjectCreationOperation runnable= new ExampleProjectCreationOperation(fPage, new ImportOverwriteQuery()); @@ -128,13 +124,11 @@ public class ExampleProjectCreationWizard extends Wizard implements INewWizard, final IWorkbenchPage activePage= window.getActivePage(); if (activePage != null) { final Display display= getShell().getDisplay(); - display.asyncExec(new Runnable() { - public void run() { - try { - IDE.openEditor(activePage, (IFile)resource, true); - } catch (PartInitException e) { - ExampleProjectsPlugin.log(e); - } + display.asyncExec(() -> { + try { + IDE.openEditor(activePage, (IFile)resource, true); + } catch (PartInitException e) { + ExampleProjectsPlugin.log(e); } }); BasicNewResourceWizard.selectAndReveal(resource, activePage.getWorkbenchWindow()); @@ -145,6 +139,7 @@ public class ExampleProjectCreationWizard extends Wizard implements INewWizard, * Stores the configuration element for the wizard. The config element will be used * in <code>performFinish</code> to set the result perspective. */ + @Override public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) { fConfigElement= cfig; IConfigurationElement[] children= cfig.getChildren("projectsetup"); //$NON-NLS-1$ @@ -160,6 +155,7 @@ public class ExampleProjectCreationWizard extends Wizard implements INewWizard, // overwrite dialog private class ImportOverwriteQuery implements IOverwriteQuery { + @Override public String queryOverwrite(String file) { String[] returnCodes= { YES, NO, ALL, CANCEL}; int returnVal= openDialog(file); @@ -168,19 +164,18 @@ public class ExampleProjectCreationWizard extends Wizard implements INewWizard, private int openDialog(final String file) { final int[] result= { IDialogConstants.CANCEL_ID }; - getShell().getDisplay().syncExec(new Runnable() { - public void run() { - String title= ExampleProjectMessages.ExampleProjectCreationWizard_overwritequery_title; - String msg= MessageFormat.format(ExampleProjectMessages.ExampleProjectCreationWizard_overwritequery_message, new Object[] {file}); - String[] options= {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL}; - MessageDialog dialog= new MessageDialog(getShell(), title, null, msg, MessageDialog.QUESTION, options, 0); - result[0]= dialog.open(); - } + getShell().getDisplay().syncExec(() -> { + String title= ExampleProjectMessages.ExampleProjectCreationWizard_overwritequery_title; + String msg= MessageFormat.format(ExampleProjectMessages.ExampleProjectCreationWizard_overwritequery_message, new Object[] {file}); + String[] options= {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL}; + MessageDialog dialog= new MessageDialog(getShell(), title, null, msg, MessageDialog.QUESTION, options, 0); + result[0]= dialog.open(); }); return result[0]; } } + @Override public void init(IWorkbench workbench, IStructuredSelection selection) { } diff --git a/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationWizardPage.java b/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationWizardPage.java index 71985b4d0e..648f1a1bc2 100644 --- a/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationWizardPage.java +++ b/org.eclipse.jdt.ui.examples.projects/examples/org/eclipse/jdt/internal/ui/exampleprojects/ExampleProjectCreationWizardPage.java @@ -14,8 +14,6 @@ package org.eclipse.jdt.internal.ui.exampleprojects; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -69,9 +67,7 @@ public class ExampleProjectCreationWizardPage extends WizardPage { return res; } - /* - * @see IDialogPage#createControl(Composite) - */ + @Override public void createControl(Composite parent) { Composite composite= new Composite(parent, SWT.NONE); GridLayout gd= new GridLayout(); @@ -85,11 +81,9 @@ public class ExampleProjectCreationWizardPage extends WizardPage { fTextControl= new Text(composite, SWT.SINGLE | SWT.BORDER); fTextControl.setText(fProjectName); fTextControl.setSelection(fProjectName.length()); - fTextControl.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if (!fTextControl.isDisposed()) { - validateText(fTextControl.getText()); - } + fTextControl.addModifyListener(e -> { + if (!fTextControl.isDisposed()) { + validateText(fTextControl.getText()); } }); fTextControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -119,6 +113,7 @@ public class ExampleProjectCreationWizardPage extends WizardPage { /* * @see WizardPage#becomesVisible */ + @Override public void setVisible(boolean visible) { super.setVisible(visible); fPageVisible= visible; @@ -167,6 +162,7 @@ public class ExampleProjectCreationWizardPage extends WizardPage { /** * @return Returns the name entered by the user */ + @Override public String getName() { return fProjectName; } diff --git a/org.eclipse.jdt.ui.tests.refactoring/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.ui.tests.refactoring/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.ui.tests.refactoring/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ChangeTypeRefactoring/positive/A_testParameterParametricType_in.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ChangeTypeRefactoring/positive/A_testParameterParametricType_in.java new file mode 100644 index 0000000000..e88767fb3a --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ChangeTypeRefactoring/positive/A_testParameterParametricType_in.java @@ -0,0 +1,7 @@ +import java.util.*; + +class A_testParameterParametricType_in { + public void foo(ArrayList<String> list){ + list.toArray(new String[0]); + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ChangeTypeRefactoring/positive/A_testParameterParametricType_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ChangeTypeRefactoring/positive/A_testParameterParametricType_out.java new file mode 100644 index 0000000000..72ee31e826 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ChangeTypeRefactoring/positive/A_testParameterParametricType_out.java @@ -0,0 +1,7 @@ +import java.util.*; + +class A_testParameterParametricType_in { + public void foo(List<String> list){ + list.toArray(new String[0]); + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline/test43/in/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline/test43/in/A.java new file mode 100644 index 0000000000..7792f0676c --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline/test43/in/A.java @@ -0,0 +1,14 @@ +package p; + +class A { + private static final CharSequence n = null; + void f(CharSequence s) { + System.out.println("CharSequence"); + } + void f(String s) { + System.out.println("String"); + } + void g() { + f(n); + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline/test43/out/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline/test43/out/A.java new file mode 100644 index 0000000000..32351e35b8 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline/test43/out/A.java @@ -0,0 +1,13 @@ +package p; + +class A { + void f(CharSequence s) { + System.out.println("CharSequence"); + } + void f(String s) { + System.out.println("String"); + } + void g() { + f((CharSequence) null); + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/cannotInline/A_testFail15.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test51_in.java index ca3cd836a8..2bd3999f9d 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/cannotInline/A_testFail15.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test51_in.java @@ -1,4 +1,3 @@ -//inlining would introduce compile error (overloaded method ambiguity) package p; class A{ void m(){ diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test51_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test51_out.java new file mode 100644 index 0000000000..71021c2688 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test51_out.java @@ -0,0 +1,6 @@ +package p; +class A{ + void m(){ + System.out.println((String) null); + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test52_in.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test52_in.java new file mode 100644 index 0000000000..33bf9c3c39 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test52_in.java @@ -0,0 +1,7 @@ +package p; +class A{ + void m(){ + char x= 5; + System.out.println(x); + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test52_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test52_out.java new file mode 100644 index 0000000000..e56c50d173 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test52_out.java @@ -0,0 +1,6 @@ +package p; +class A{ + void m(){ + System.out.println((char) 5); + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestExceptionFilter1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestExceptionFilter1.java new file mode 100644 index 0000000000..40cc73ad01 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestExceptionFilter1.java @@ -0,0 +1,19 @@ +package tryresources18_in; + +public class TestExceptionFilter1 { + public static class Exception_1 extends Exception { + } + public static class Exception_2 extends Exception_1 { + } + + public void throw1() throws Exception_1 { + } + + public void throw2() throws Exception_2 { + } + + public void foo() { + /*[*/throw1(); + throw2();/*]*/ + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidParent1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidParent1.java new file mode 100644 index 0000000000..b6681d3633 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidParent1.java @@ -0,0 +1,11 @@ +package tryresources18_in; + +import java.io.File; + +public class TestInvalidParent1 { + public void foo() { + File file= null; + if (/*]*/file.toURL() == null/*[*/) + return; + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidParent2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidParent2.java new file mode 100644 index 0000000000..bbde00b98e --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidParent2.java @@ -0,0 +1,11 @@ +package tryresources18_in; + +import java.io.File; +import java.net.URL; + +public class TestInvalidParent2 { + public void foo() { + File file= null; + URL url= /*]*/file.toURL();/*[*/ + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidStatement1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidStatement1.java new file mode 100644 index 0000000000..6ae64c89fd --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidStatement1.java @@ -0,0 +1,9 @@ +package trycatch18_in; + +import java.net.Socket; + +class TestInvalidStatement1 { + void foo(int a) { + /*[*/Socket s=/*]*/new Socket(); + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidTryResources1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidTryResources1.java new file mode 100644 index 0000000000..3d7037d2c0 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestInvalidTryResources1.java @@ -0,0 +1,10 @@ +package trycatch18_in; + +import java.net.Socket; + +class TestSimple1 { + void foo(int a) { + /*[*/String s=new String("abc"); + s=s.concat("def");/*]*/ + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda1.java new file mode 100644 index 0000000000..c3267fbf85 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda1.java @@ -0,0 +1,12 @@ +package tryresources18_in; + +public class TestLambda1 { + private TestLambda1 log; + void test() { + Runnable r = () -> /*[*/log.info("Processing rule #{} {}", "")/*]*/; + } + + private void info(String string, Object object) throws GridException1 {} +} +@SuppressWarnings("serial") +class GridException1 extends Exception {}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda2.java new file mode 100644 index 0000000000..0307638401 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda2.java @@ -0,0 +1,12 @@ +package tryresources18_in; + +public class TestLambda2 { + private TestLambda2 log; + void test() { + Runnable r = () -> /*[*/log/*]*/.info("Processing rule #{} {}", ""); + } + + private void info(String string, Object object) throws GridException1 {} +} +@SuppressWarnings("serial") +class GridException1 extends Exception {}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda3.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda3.java new file mode 100644 index 0000000000..40b973b9bd --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda3.java @@ -0,0 +1,15 @@ +package tryresources18_in; + +import java.io.FileNotFoundException; + +interface TestLambda3 { + int foo(int i); + + default TestLambda3 method1() { + return x -> { + if (x == 0) + /*[*/throw new FileNotFoundException();/*]*/ + return x; + }; + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda4.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda4.java new file mode 100644 index 0000000000..df8b50bc5a --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestLambda4.java @@ -0,0 +1,15 @@ +package tryresources18_in; + +import java.io.FileNotFoundException; + +interface TestLambda4 { + int foo(int i); + + default TestLambda4 method1() { + /*[*/return x -> { + if (x == 0) + throw new FileNotFoundException(); + return x; + };/*]*/ + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestMethodReference1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestMethodReference1.java new file mode 100644 index 0000000000..a7c66a0d32 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestMethodReference1.java @@ -0,0 +1,22 @@ +package tryresources18_out; + +import java.io.FileNotFoundException; +import java.util.Optional; + + +public class TestMethodReference1 { + private static Transformer2 TRANSFORMER = new Transformer2(); + + public void test() { + try { + /*[*/Optional.ofNullable("10").map(TRANSFORMER::transform).ifPresent(System.out::print);/*]*/ + } catch (Exception e) { + } + } +} + +class Transformer2 { + Long transform(String number) throws FileNotFoundException { + return null; + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestMethodThrowsException1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestMethodThrowsException1.java new file mode 100644 index 0000000000..f7f2e9d98c --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestMethodThrowsException1.java @@ -0,0 +1,13 @@ +package tryresources18_in; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.sql.SQLException; + +public class TestMethodThrowsException1 { + private void thrower() throws SQLException, FileNotFoundException { + } + public void test() throws IOException { + /*[*/thrower();/*]*/ + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestMethodThrowsException2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestMethodThrowsException2.java new file mode 100644 index 0000000000..ec0fa23e90 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestMethodThrowsException2.java @@ -0,0 +1,21 @@ +package tryresources18_in; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Socket; + +public class TryTest2 { + + @SuppressWarnings("unused") + + public void read() throws IOException { + // create socket + /*[*//* 1 */ Socket s = new Socket();/*]*/ + // create reader + BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); + // use reader + int data = br.read(); + } + +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestNonClosableInserted1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestNonClosableInserted1.java new file mode 100644 index 0000000000..fbe3937a96 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestNonClosableInserted1.java @@ -0,0 +1,13 @@ +package trycatch18_in; + +import java.net.Socket; + +class TestSimple1 { + void foo(int a) { + /*[*/Socket s=new Socket(); + int i=0; + Socket s2=new Socket(); + s.getInetAddress(); + s2.getInetAddress();/*]*/ + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple1.java new file mode 100644 index 0000000000..4af0ccab3f --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple1.java @@ -0,0 +1,10 @@ +package trycatch18_in; + +import java.net.Socket; + +class TestSimple1 { + void foo(int a) { + /*[*/Socket s=new Socket(); + s.getInetAddress();/*]*/ + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple2.java new file mode 100644 index 0000000000..cf8c95f23b --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple2.java @@ -0,0 +1,11 @@ +package trycatch18_in; + +import java.net.Socket; + +class TestSimple1 { + void foo(int a) { + /*[*/Socket s=new Socket(), s2=new Socket(); + s.getInetAddress(); + s2.getInetAddress();/*]*/ + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple3.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple3.java new file mode 100644 index 0000000000..efd8161b2c --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple3.java @@ -0,0 +1,16 @@ +package tryresources18_in; + +import java.io.InputStream; +import java.net.Socket; + +class TestSimple3 { + void foo(int a) { + /*[*//*1*/Socket s=new Socket(), s2=new Socket(); + /*2*/InputStream is = s.getInputStream(); + s.getInetAddress();/*]*/ + s2.getInetAddress(); + System.out.println(s.getInetAddress().toString()); + /*3*/int i = 0; + System.out.println(is.markSupported());/*0*/ + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple4.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple4.java new file mode 100644 index 0000000000..ecbb893b64 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestSimple4.java @@ -0,0 +1,9 @@ +package trycatch18_in; + +import java.net.Socket; + +class TestSimple4 { + void foo(int a) { + /*[*/Socket s=new Socket();/*]*/ + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestWithException1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestWithException1.java new file mode 100644 index 0000000000..02a3ed4c2f --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestWithException1.java @@ -0,0 +1,13 @@ +package trycatch18_in; + +import java.net.Socket; +import java.io.InputStream; + +class TestWithException1 { + void foo(int a) { + /*[*/Socket s=new Socket(); + InputStream is=s.getInputStream(); + s.getInetAddress();/*]*/ + is.available(); + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestWithException2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestWithException2.java new file mode 100644 index 0000000000..bc91fa5b7e --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestWithException2.java @@ -0,0 +1,14 @@ +package trycatch18_in; + +import java.net.Socket; +import java.io.InputStream; + +class TestWithException1 { + void foo(int a) { + /*[*/Socket s=new Socket(); + InputStream is=s.getInputStream(); + Integer x= Integer.valueOf("123"); + s.getInetAddress();/*]*/ + is.available(); + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestWithThrows1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestWithThrows1.java new file mode 100644 index 0000000000..67f160cc55 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_in/TestWithThrows1.java @@ -0,0 +1,16 @@ +package trycatch18_in; + +import java.net.Socket; +import java.io.InputStream; +import java.util.zip.DataFormatException; + +class TestWithThrows1 { + void foo(int a) { + /*[*/Socket s=new Socket(); + InputStream is=s.getInputStream(); + s.getInetAddress();/*]*/ + if (s.getTcpNoDelay()) + throw new DataFormatException(); + is.available(); + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestExceptionFilter1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestExceptionFilter1.java new file mode 100644 index 0000000000..36637ce272 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestExceptionFilter1.java @@ -0,0 +1,22 @@ +package tryresources18_out; + +public class TestExceptionFilter1 { + public static class Exception_1 extends Exception { + } + public static class Exception_2 extends Exception_1 { + } + + public void throw1() throws Exception_1 { + } + + public void throw2() throws Exception_2 { + } + + public void foo() { + try { + /*[*/throw1(); + throw2();/*]*/ + } catch (Exception_1 e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestLambda1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestLambda1.java new file mode 100644 index 0000000000..0ba709b794 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestLambda1.java @@ -0,0 +1,17 @@ +package tryresources18_out; + +public class TestLambda1 { + private TestLambda1 log; + void test() { + Runnable r = () -> { + try { + /*[*/log.info("Processing rule #{} {}", "")/*]*/; + } catch (GridException1 e) { + } + }; + } + + private void info(String string, Object object) throws GridException1 {} +} +@SuppressWarnings("serial") +class GridException1 extends Exception {}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestLambda3.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestLambda3.java new file mode 100644 index 0000000000..8b257024d8 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestLambda3.java @@ -0,0 +1,18 @@ +package tryresources18_out; + +import java.io.FileNotFoundException; + +interface TestLambda3 { + int foo(int i); + + default TestLambda3 method1() { + return x -> { + if (x == 0) + try { + /*[*/throw new FileNotFoundException();/*]*/ + } catch (FileNotFoundException e) { + } + return x; + }; + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestMethodReference1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestMethodReference1.java new file mode 100644 index 0000000000..a7c66a0d32 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestMethodReference1.java @@ -0,0 +1,22 @@ +package tryresources18_out; + +import java.io.FileNotFoundException; +import java.util.Optional; + + +public class TestMethodReference1 { + private static Transformer2 TRANSFORMER = new Transformer2(); + + public void test() { + try { + /*[*/Optional.ofNullable("10").map(TRANSFORMER::transform).ifPresent(System.out::print);/*]*/ + } catch (Exception e) { + } + } +} + +class Transformer2 { + Long transform(String number) throws FileNotFoundException { + return null; + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestMethodThrowsException1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestMethodThrowsException1.java new file mode 100644 index 0000000000..05205aaafe --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestMethodThrowsException1.java @@ -0,0 +1,16 @@ +package tryresources18_out; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.sql.SQLException; + +public class TestMethodThrowsException1 { + private void thrower() throws SQLException, FileNotFoundException { + } + public void test() throws IOException { + try { + /*[*/thrower();/*]*/ + } catch (SQLException e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestMethodThrowsException2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestMethodThrowsException2.java new file mode 100644 index 0000000000..774fa2ff5b --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestMethodThrowsException2.java @@ -0,0 +1,22 @@ +package tryresources18_out; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.Socket; + +public class TryTest2 { + + @SuppressWarnings("unused") + + public void read() throws IOException { + try (// create socket + /*[*//* 1 */ Socket s = new Socket()) { + // create reader + BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); + // use reader + int data = br.read(); + } + } + +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestNonClosableInserted1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestNonClosableInserted1.java new file mode 100644 index 0000000000..a54816b313 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestNonClosableInserted1.java @@ -0,0 +1,16 @@ +package trycatch18_out; + +import java.io.IOException; +import java.net.Socket; + +class TestSimple1 { + void foo(int a) { + try (/*[*/ Socket s = new Socket()) { + int i=0; + Socket s2=new Socket(); + s.getInetAddress(); + s2.getInetAddress();/*]*/ + } catch (IOException e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple1.java new file mode 100644 index 0000000000..72ee205384 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple1.java @@ -0,0 +1,13 @@ +package trycatch18_out; + +import java.io.IOException; +import java.net.Socket; + +class TestSimple1 { + void foo(int a) { + try (/*[*/ Socket s = new Socket()) { + s.getInetAddress();/*]*/ + } catch (IOException e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple2.java new file mode 100644 index 0000000000..a8de0e06d8 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple2.java @@ -0,0 +1,15 @@ +package trycatch18_out; + +import java.io.IOException; +import java.net.Socket; + +class TestSimple1 { + void foo(int a) { + try (/*[*/ Socket s = new Socket(); + Socket s2 = new Socket()) { + s.getInetAddress(); + s2.getInetAddress();/*]*/ + } catch (IOException e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple3.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple3.java new file mode 100644 index 0000000000..cf1b6b780a --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple3.java @@ -0,0 +1,20 @@ +package tryresources18_out; + +import java.io.IOException; +import java.io.InputStream; +import java.net.Socket; + +class TestSimple3 { + void foo(int a) { + try (/*[*//*1*/ Socket s = new Socket(); + Socket s2 = new Socket(); + /*2*/ InputStream is = s.getInputStream()) { + s.getInetAddress();/*]*/ + s2.getInetAddress(); + System.out.println(s.getInetAddress().toString()); + /*3*/int i = 0; + System.out.println(is.markSupported());/*0*/ + } catch (IOException e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple4.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple4.java new file mode 100644 index 0000000000..cdf4640454 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestSimple4.java @@ -0,0 +1,12 @@ +package trycatch18_out; + +import java.io.IOException; +import java.net.Socket; + +class TestSimple4 { + void foo(int a) { + try (/*[*/ Socket s = new Socket()) { + } catch (IOException e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestWithException1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestWithException1.java new file mode 100644 index 0000000000..d8f2ac74fe --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestWithException1.java @@ -0,0 +1,16 @@ +package trycatch18_out; + +import java.net.Socket; +import java.io.IOException; +import java.io.InputStream; + +class TestWithException1 { + void foo(int a) { + try (/*[*/ Socket s = new Socket(); + InputStream is = s.getInputStream()) { + s.getInetAddress();/*]*/ + is.available(); + } catch (IOException e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestWithException2.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestWithException2.java new file mode 100644 index 0000000000..8391d9154d --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestWithException2.java @@ -0,0 +1,17 @@ +package trycatch18_out; + +import java.net.Socket; +import java.io.IOException; +import java.io.InputStream; + +class TestWithException1 { + void foo(int a) { + try (/*[*/ Socket s = new Socket(); + InputStream is = s.getInputStream()) { + Integer x= Integer.valueOf("123"); + s.getInetAddress();/*]*/ + is.available(); + } catch (NumberFormatException | IOException e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestWithThrows1.java b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestWithThrows1.java new file mode 100644 index 0000000000..10e05e3cc4 --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/SurroundWithWorkSpace/SurroundWithTests/tryresources18_out/TestWithThrows1.java @@ -0,0 +1,19 @@ +package trycatch18_in; + +import java.net.Socket; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.DataFormatException; + +class TestWithThrows1 { + void foo(int a) { + try (/*[*/ Socket s = new Socket(); + InputStream is = s.getInputStream()) { + s.getInetAddress();/*]*/ + if (s.getTcpNoDelay()) + throw new DataFormatException(); + is.available(); + } catch (IOException | DataFormatException e) { + } + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeSignatureTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeSignatureTests.java index d588d422d4..dba009df3d 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeSignatureTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeSignatureTests.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -1614,14 +1614,14 @@ public class ChangeSignatureTests extends RefactoringTest { int[] deletedIndices= null; int newVisibility= Modifier.PUBLIC; String newReturnTypeName= "void"; - + ICompilationUnit cu= createCUfromTestFile(getPackageP(), true, true); int aStart= cu.getSource().lastIndexOf("a("); IMethod method= (IMethod) cu.getElementAt(aStart); assertTrue(method.exists()); helperDoAll(method, newParamInfo, newIndices, oldParamNames, newParamNames, newParamTypeNames, permutation, newVisibility, deletedIndices, newReturnTypeName, false); } - + public void testAddSyntaxError01()throws Exception{ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=191349 String refNameIn= "A_testAddSyntaxError01_Ref_in.java"; String refNameOut= "A_testAddSyntaxError01_Ref_out.java"; @@ -2212,7 +2212,7 @@ public class ChangeSignatureTests extends RefactoringTest { String newReturnTypeName= null; helperDoAll("C", "foo", signature, newParamInfo, newIndices, oldParamNames, newParamNames, newParameterTypeNames, permutation, newVisibility, deletedIndices, newReturnTypeName); } - + public void testDelegate01() throws Exception { // simple reordering with delegate helper1(new String[]{"j", "i"}, new String[]{"I", "QString;"}, null, null, true); @@ -2263,6 +2263,6 @@ public class ChangeSignatureTests extends RefactoringTest { String[] signature= {}; helperRenameMethod(signature, "renamed", true, false); } - + } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeTypeRefactoringTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeTypeRefactoringTests.java index f8dc46d228..61c8a5706c 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeTypeRefactoringTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ChangeTypeRefactoringTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -95,7 +95,7 @@ public class ChangeTypeRefactoringTests extends RefactoringTest { String fullName= TEST_PATH_PREFIX + getRefactoringPath() + "positive/" + fileName + ".java"; return createCU(pack, fileName + ".java", getFileContents(fullName)); } - + private ICompilationUnit createAdditionalCUForNegative(String fileName, IPackageFragment pack) throws Exception { String fullName= TEST_PATH_PREFIX + getRefactoringPath() + "negative/" + fileName + ".java"; return createCU(pack, fileName + ".java", getFileContents(fullName)); @@ -145,8 +145,8 @@ public class ChangeTypeRefactoringTests extends RefactoringTest { assertEqualLines(getFileContents(canonAfterSrcName), cu.getSource()); } - - protected ChangeTypeRefactoring failHelper2(int startLine, int startColumn, int endLine, int endColumn, + + protected ChangeTypeRefactoring failHelper2(int startLine, int startColumn, int endLine, int endColumn, String selectedTypeName, IPackageFragment pack) throws Exception { ICompilationUnit cu= createCUfromTestFile(pack, false, true); ISourceRange selection= TextRangeUtil.getSelection(cu, startLine, startColumn, endLine, endColumn); @@ -154,7 +154,7 @@ public class ChangeTypeRefactoringTests extends RefactoringTest { performRefactoring(ref); return ref; } - + //--- TESTS public void testLocalVarName() throws Exception { @@ -534,6 +534,19 @@ public class ChangeTypeRefactoringTests extends RefactoringTest { }; StringAsserts.assertEqualStringsIgnoreOrder(actual, expected); } + + public void testParameterParametricType() throws Exception { + Collection<String> types= helper1(4, 21, 4, 38, "java.util.List<java.lang.String>").getValidTypeNames(); + String[] actual= types.toArray(new String[types.size()]); + String[] expected= { + "java.util.List<java.lang.String>", + "java.util.AbstractList<java.lang.String>", + "java.util.Collection<java.lang.String>", + "java.util.AbstractCollection<java.lang.String>" + }; + StringAsserts.assertEqualStringsIgnoreOrder(actual, expected); + } + public void testParametricLocalVar() throws Exception { Collection<String> types= helper1(14, 9, 14, 20, "java.lang.Iterable<java.lang.String>").getValidTypeNames(); String[] actual= types.toArray(new String[types.size()]); @@ -606,7 +619,7 @@ public class ChangeTypeRefactoringTests extends RefactoringTest { }; StringAsserts.assertEqualStringsIgnoreOrder(actual, expected); } - + // tests that are supposed to fail public void testInvalidSelection() throws Exception { diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java index 241f519230..e742a9627c 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ConvertAnonymousToNestedTests.java @@ -385,7 +385,7 @@ public class ConvertAnonymousToNestedTests extends RefactoringTest { public void testGenerics7() throws Exception{ // test for bug 124978 helper1(6, 18, 6, 18, true, true, "Inner", Modifier.PRIVATE); } - + public void test31() throws Exception{ // for bug 181054 helper1(10, 24, 10, 30, true, false, "Inner1Extension", Modifier.PRIVATE); } @@ -393,11 +393,11 @@ public class ConvertAnonymousToNestedTests extends RefactoringTest { public void test32() throws Exception{ // for bug 158028 helper1(10, 30, 10, 36, true, false, "Inner1Extension", Modifier.PRIVATE); } - + public void test33() throws Exception { // for bug 124978 helper1(9, 21, 12, 7, true, true, "AImpl", Modifier.PRIVATE); } - + public void test34() throws Exception { // for bug 159917 helper1(16, 27, 22, 9, false, false, "Nested", Modifier.PRIVATE); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/DocumentChangeTest.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/DocumentChangeTest.java index abd1094ff2..d151b95afa 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/DocumentChangeTest.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/DocumentChangeTest.java @@ -67,7 +67,7 @@ import org.eclipse.jdt.internal.ui.JavaPlugin; * @since 3.6 */ public class DocumentChangeTest extends RefactoringTest { - + public static Test suite() { return setUpTest(new TestSuite(DocumentChangeTest.class)); } @@ -78,7 +78,7 @@ public class DocumentChangeTest extends RefactoringTest { protected void setUp() throws Exception { PlatformUI.getWorkbench().showPerspective(JavaUI.ID_PERSPECTIVE, JavaPlugin.getActiveWorkbenchWindow()); } - + @Override protected void tearDown() throws Exception { IWorkbenchPage activePage= JavaPlugin.getActivePage(); @@ -88,7 +88,7 @@ public class DocumentChangeTest extends RefactoringTest { } }; } - + public static Test setUpTest(Test test) { return new RefactoringTestSetup(test) { @Override @@ -102,7 +102,7 @@ public class DocumentChangeTest extends RefactoringTest { public DocumentChangeTest(String name) { super(name); } - + public void testDocumentChange() throws Exception { IProject project= RefactoringTestSetup.getProject().getProject(); IFile file= project.getFile("file.txt"); @@ -110,32 +110,32 @@ public class DocumentChangeTest extends RefactoringTest { final String insertion= "modified "; final String epilog= "text"; file.create(getStream(prolog + epilog), IResource.NONE, null); - + IEditorPart editor= IDE.openEditor(JavaPlugin.getActivePage(), file); ITextFileBuffer textFileBuffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE); final IDocument document= textFileBuffer.getDocument(); - + final Refactoring ref= new Refactoring() { @Override public String getName() { return getClass().getName(); } - + @Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { return new RefactoringStatus(); } - + @Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { return new RefactoringStatus(); } - + @Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { DocumentChange change= new DocumentChange("DocumentChangeTest change", document); change.setEdit(new InsertEdit(prolog.length(), insertion)); - + // need to provide a non-null affectedObjects from the undo change, otherwise the NonLocalUndoUserApprover shows a dialog. CompositeChange compositeChange= new CompositeChange("DocumentChangeTest composite change") { @Override @@ -152,9 +152,9 @@ public class DocumentChangeTest extends RefactoringTest { return compositeChange; } }; - + final MultiStatus statusCollector= new MultiStatus(JavaTestPlugin.getPluginId(), 0, "", null); - + ILogListener logListener= new ILogListener() { @Override public void logging(IStatus status, String plugin) { @@ -174,14 +174,14 @@ public class DocumentChangeTest extends RefactoringTest { } }; JavaPlugin.getActiveWorkbenchWindow().run(true, true, runnable); - + editor.doSave(new NullProgressMonitor()); - + String contents= getContents(file); assertEquals(prolog + insertion + epilog, contents); - + // undo: - + runnable= new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { @@ -193,17 +193,17 @@ public class DocumentChangeTest extends RefactoringTest { } }; JavaPlugin.getActiveWorkbenchWindow().run(true, true, runnable); - + editor.doSave(new NullProgressMonitor()); - + contents= getContents(file); assertEquals(prolog + epilog, contents); - - + + // redo after closing file: - + JavaPlugin.getActivePage().closeEditor(editor, true); - + runnable= new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { @@ -215,24 +215,24 @@ public class DocumentChangeTest extends RefactoringTest { } }; JavaPlugin.getActiveWorkbenchWindow().run(true, true, runnable); - + editor.doSave(new NullProgressMonitor()); - + contents= document.get(); assertEquals(prolog + insertion + epilog, contents); - + // Only document content has changed, but file content hasn't // (since closing the editor has disconnected the file buffer): contents= getContents(file); assertEquals(prolog + epilog, contents); - - + + } finally { Platform.removeLogListener(logListener); } if (statusCollector.getChildren().length != 0) { throw new CoreException(statusCollector); } - + } } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests.java index e0b72a470c..f415d12425 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests.java @@ -411,7 +411,7 @@ public class ExtractClassTests extends RefactoringTest { fDescriptor.setCreateTopLevel(false); runRefactoring(false); } - + // see bug 394547 public void testNested1() throws Exception { IType outer= setupType(); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests18.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests18.java index 6b651324f2..16252464a9 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests18.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractClassTests18.java @@ -48,7 +48,7 @@ public class ExtractClassTests18 extends ExtractClassTests { return REFACTORING_PATH; } - /* Test that @NonNull annotations ARE created if no @NonNullByDefault is in effect for the target location */ + /* Test that @NonNull annotations ARE created if no @NonNullByDefault is in effect for the target location */ public void testNoRedundantNonNull1() throws Exception { IJavaProject javaProject= getRoot().getJavaProject(); Map<String, String> originalOptions= javaProject.getOptions(false); @@ -69,7 +69,7 @@ public class ExtractClassTests18 extends ExtractClassTests { } } - /* Test that @NonNull annotations ARE NOT created if @NonNullByDefault is in effect for the target location */ + /* Test that @NonNull annotations ARE NOT created if @NonNullByDefault is in effect for the target location */ public void testNoRedundantNonNull2() throws Exception { IJavaProject javaProject= getRoot().getJavaProject(); Map<String, String> originalOptions= javaProject.getOptions(false); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractConstantTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractConstantTests.java index 00d8955eec..9e2d4560f6 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractConstantTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractConstantTests.java @@ -330,7 +330,7 @@ public class ExtractConstantTests extends RefactoringTest { public void test37() throws Exception { // bug 307758 helper1(6, 17, 6, 24, true, false, "INT", "INT"); } - + public void test38() throws Exception { // bug 317224 helper1(3, 19, 3, 24, true, false, "S_ALL", "ALL"); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractInterfaceTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractInterfaceTests.java index 40e785722a..3622281f8e 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractInterfaceTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractInterfaceTests.java @@ -767,26 +767,26 @@ public class ExtractInterfaceTests extends RefactoringTest { fGenerateAnnotations= true; // should not generate because project is 1.5 standardPassingTest(); } - + public void test109() throws Exception{ // Generate @Override in 1.6 project fGenerateAnnotations= true; RefactoringTestSetup refactoringTestSetup= new RefactoringTestSetup(null); try { JavaProjectHelper.addRTJar16(getRoot().getJavaProject()); - + standardPassingTest(); - + refactoringTestSetup.tearDown(); } finally { refactoringTestSetup.setUp(); } } - + public void test110() throws Exception{ validatePassingTest("A", "I", true, true); } - + public void testPaperExample0() throws Exception{ String[] names= new String[]{"add", "addAll", "iterator"}; String[][] signatures= new String[][]{new String[]{"QComparable;"}, new String[]{"QA;"}, new String[0]}; diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractInterfaceTests18.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractInterfaceTests18.java index 794a6609fc..f5e465a7bd 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractInterfaceTests18.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractInterfaceTests18.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -66,7 +66,7 @@ public class ExtractInterfaceTests18 extends ExtractInterfaceTests { String className= "A"; String extendingInterfaceName= "I1"; String newInterfaceName= "B"; - + IType clas= getType(createCUfromTestFile(getPackageP(), getTopLevelTypeName(className)), className); ICompilationUnit cu= clas.getCompilationUnit(); IPackageFragment pack= (IPackageFragment)cu.getParent(); @@ -125,14 +125,14 @@ public class ExtractInterfaceTests18 extends ExtractInterfaceTests { } public void testLambda1() throws Exception { - // bug 488420 + // bug 488420 String[] names= new String[] { "m1" }; String[][] signatures= new String[][] { new String[0] }; validatePassingTest("X", new String[] { "X", "Util" }, "I", true, names, signatures, null); } public void testLambda2() throws Exception { - // bug 488420 + // bug 488420 String[] names= new String[] { "m1" }; String[][] signatures= new String[][] { new String[0] }; validatePassingTest("X", new String[] { "X", "Util" }, "I", true, names, signatures, null); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java index 8432497020..22239d8322 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests.java @@ -43,9 +43,9 @@ import junit.framework.Test; import junit.framework.TestSuite; public class ExtractMethodTests extends AbstractSelectionTestCase { - + private static final boolean BUG_405778= true; //XXX: [1.8][dom ast] method body recovery broken (empty body) - + private static ExtractMethodTestSetup fgTestSetup; public ExtractMethodTests(String name) { @@ -676,9 +676,9 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test196() throws Exception { invalidSelectionTest(); } - + //---- continue not possible - + public void test197() throws Exception { invalidSelectionTest(); } @@ -986,7 +986,7 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test374() throws Exception { validSelectionTestChecked(); } - + //==================================================================================== // Testing Extracted result //==================================================================================== @@ -1634,7 +1634,7 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test728() throws Exception { returnTest(); } - + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=213519 public void test729() throws Exception { returnTest(); @@ -1644,7 +1644,7 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test730() throws Exception { returnTest(); } - + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=213519 public void test731() throws Exception { returnTest(); @@ -1659,12 +1659,12 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test733() throws Exception { returnTest(); } - + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=97413 public void test734() throws Exception { returnTest(); } - + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=285554 public void test735() throws Exception { returnTest(); @@ -1707,51 +1707,51 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test758() throws Exception { branchTest(); } - + public void test759() throws Exception { branchTest(); } - + public void test760() throws Exception { branchTest(); } - + public void test761() throws Exception { branchTest(); } - + public void test762() throws Exception { branchTest(); } - + public void test763() throws Exception { branchTest(); } - + public void test764() throws Exception { branchTest(); } - + public void test765() throws Exception { branchTest(); } - + public void test766() throws Exception { branchTest(); } - + public void test767() throws Exception { branchTest(); } - + public void test768() throws Exception { branchTest(); } - + public void test769() throws Exception { branchTest(); } - + //---- Test for CUs with compiler errors public void test800() throws Exception { @@ -1911,19 +1911,19 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test980() throws Exception { duplicatesTest(); // for https://bugs.eclipse.org/bugs/show_bug.cgi?id=264606 } - + public void test981() throws Exception { duplicatesTest(); // for https://bugs.eclipse.org/bugs/show_bug.cgi?id=264606 } - + public void test982() throws Exception { duplicatesTest(); // for https://bugs.eclipse.org/bugs/show_bug.cgi?id=264606 } - + public void test983() throws Exception { duplicatesTest(); // for https://bugs.eclipse.org/bugs/show_bug.cgi?id=264606 } - + public void test984() throws Exception { duplicatesTest(); // for https://bugs.eclipse.org/bugs/show_bug.cgi?id=264606 } @@ -1939,11 +1939,11 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test987() throws Exception { duplicatesTest(); // for https://bugs.eclipse.org/bugs/show_bug.cgi?id=264606 } - + public void test988() throws Exception{ duplicatesTest(); } - + public void test989() throws Exception{ duplicatesTest(); } @@ -1997,7 +1997,7 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test1053() throws Exception { destinationTest(1); } - + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=318127 public void test1054() throws Exception { destinationTest(1); @@ -2022,23 +2022,23 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test1058() throws Exception { destinationTest(2); } - + public void test1059() throws Exception { destinationTest(0); } - + public void test1060() throws Exception { destinationTest(1); } - + public void test1061() throws Exception { destinationTest(1); } - + public void test1062() throws Exception { destinationTest(2); } - + //---- Test Generics -------------------------------------------------- public void test1100() throws Exception { @@ -2124,11 +2124,11 @@ public class ExtractMethodTests extends AbstractSelectionTestCase { public void test1120() throws Exception { genericTest(); //https://bugs.eclipse.org/bugs/show_bug.cgi?id=369295 } - + public void test1121() throws Exception { genericTest(); } - + public void test1122() throws Exception { genericTest(); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests10.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests10.java index 4fe3f455c0..5e3f0dec55 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests10.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractMethodTests10.java @@ -37,7 +37,7 @@ public class ExtractMethodTests10 extends ExtractMethodTests { } //==================================================================================== - // Testing var type + // Testing var type //==================================================================================== public void testVar1() throws Exception { diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests.java index 34874b62a5..9dc87e1473 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests.java @@ -653,7 +653,7 @@ public class ExtractTempTests extends RefactoringTest { public void test102() throws Exception { helper1(9, 24, 9, 29, true, false, "temp", "j"); } - + public void test103() throws Exception { //test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=243101 helper1(7, 21, 7, 33, true, false, "temp", "valueOf"); @@ -688,12 +688,12 @@ public class ExtractTempTests extends RefactoringTest { //test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173 helper1(5, 20, 5, 29, true, false, "temp", "i"); } - + public void test110() throws Exception { //test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=65875 helper1(6, 9, 6, 25, true, false, "temp", "calculateCount"); } - + public void test111() throws Exception { //test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=65875 helper1(11, 9, 11, 25, true, false, "temp", "calculateCount"); @@ -713,7 +713,7 @@ public class ExtractTempTests extends RefactoringTest { //test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=406347 helper1(7, 17, 7, 22, true, false, "temp", "i"); } - + public void testZeroLengthSelection0() throws Exception { // printTestDisabledMessage("test for bug 30146"); helper1(4, 18, 4, 18, true, false, "temp", "j"); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests17.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests17.java index 8975329099..53db3f7f92 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests17.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractTempTests17.java @@ -46,16 +46,16 @@ public class ExtractTempTests17 extends ExtractTempTests { public void test110() throws Exception { helper1(14, 13, 14, 15, true, false, "temp", "ex2"); } - + @Override public void test111() throws Exception { helper1(8, 16, 8, 33, true, false, "arrayList", "arrayList"); } - + public void test112() throws Exception { helper1(8, 20, 8, 37, true, false, "arrayList", "arrayList"); } - + @Override public void test113() throws Exception { helper1(12, 16, 12, 33, true, false, "arrayList2", "arrayList2"); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InferTypeArgumentsTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InferTypeArgumentsTests.java index af0ea5e168..9a1b91c714 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InferTypeArgumentsTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InferTypeArgumentsTests.java @@ -463,5 +463,5 @@ public class InferTypeArgumentsTests extends RefactoringTest { // regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=216627 performCuOK(); } - + } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineConstantTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineConstantTests.java index 407d7425ba..e8a7a7af17 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineConstantTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineConstantTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -12,12 +12,10 @@ * IBM Corporation - initial API and implementation * Nikolay Metchev <nikolaymetchev@gmail.com> - [inline] problem with fields from generic types - https://bugs.eclipse.org/218431 * Nikolay Metchev <nikolaymetchev@gmail.com> - [inline] Inline local variable with initializer generates assignment where left-hand side is not a variable - https://bugs.eclipse.org/394721 + * Pierre-Yves B. <pyvesdev@gmail.com> - [inline] Inlining a local variable leads to ambiguity with overloaded methods - https://bugs.eclipse.org/434747 *******************************************************************************/ package org.eclipse.jdt.ui.tests.refactoring; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.NullProgressMonitor; @@ -26,13 +24,15 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.ISourceRange; +import org.eclipse.jdt.internal.corext.dom.IASTSharedValues; import org.eclipse.jdt.internal.corext.refactoring.base.RefactoringStatusCodes; import org.eclipse.jdt.internal.corext.refactoring.code.InlineConstantRefactoring; import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser; import org.eclipse.jdt.ui.tests.refactoring.infra.TextRangeUtil; -import org.eclipse.jdt.internal.corext.dom.IASTSharedValues; +import junit.framework.Test; +import junit.framework.TestSuite; public class InlineConstantTests extends RefactoringTest { private static final Class<InlineConstantTests> clazz = InlineConstantTests.class; @@ -294,19 +294,19 @@ public class InlineConstantTests extends RefactoringTest { public void test31() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=265448 helper1("p.A", 4, 23, 4, 28, true, true); } - + public void test32() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=265448 helper1("p.A", 4, 23, 4, 28, true, true); } - + public void test33() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=279715 helper1("p.A", 5, 29, 5, 30, true, true); } - + public void test34() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=297760 helper1("p.A", 4, 24, 4, 25, true, true); } - + public void test35() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173 helper1("p.A", 4, 22, 4, 23, true, true); } @@ -341,6 +341,10 @@ public class InlineConstantTests extends RefactoringTest { helper1("p.A", 4, 32, 4, 33, true, true); } + public void test43() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=434747 + helper1("p.A", 4, 39, 4, 40, true, true); + } + // -- testing failing preconditions public void testFail0() throws Exception { diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java index 9805674f4b..338e99ff12 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineMethodTests.java @@ -356,7 +356,7 @@ public class InlineMethodTests extends AbstractSelectionTestCase { public void test_287378() throws Exception { performBugTest(); } - + public void test_267386() throws Exception { performBugTest(); } @@ -506,7 +506,7 @@ public class InlineMethodTests extends AbstractSelectionTestCase { public void test91470() throws Exception { performArgumentTest(); } - + //see bug 269401 public void testFinalParameter1() throws Exception { performArgumentTest(); @@ -521,7 +521,7 @@ public class InlineMethodTests extends AbstractSelectionTestCase { public void testFinalParameter3() throws Exception { performArgumentTest(); } - + /* *********************** Name Conflict Tests ******************************* */ private void performNameConflictTest() throws Exception { @@ -847,7 +847,7 @@ public class InlineMethodTests extends AbstractSelectionTestCase { public void testHierarchyOverloadedMultiLevel() throws Exception { performCastTest(); } - + public void testHierarchyOverloadedPrivate() throws Exception { performCastTest(); } @@ -967,7 +967,7 @@ public class InlineMethodTests extends AbstractSelectionTestCase { public void testParameterizedType6() throws Exception { performGenericTest(); } - + public void testParameterizedMethod() throws Exception { performGenericTest(); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java index ff415176a1..a9eb791425 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -11,7 +11,8 @@ * Contributors: * IBM Corporation - initial API and implementation * Nikolay Metchev <nikolaymetchev@gmail.com> - [inline] Inline local variable with initializer generates assignment where left-hand side is not a variable - https://bugs.eclipse.org/394721 - * Pierre-Yves B. <pyvesdev@gmail.com> - [inline] Allow inlining of local variable initialized to null. - https://bugs.eclipse.org/93850 + * Pierre-Yves B. <pyvesdev@gmail.com> - [inline] Allow inlining of local variable initialized to null. - https://bugs.eclipse.org/93850 + * Pierre-Yves B. <pyvesdev@gmail.com> - [inline] Inlining a local variable leads to ambiguity with overloaded methods - https://bugs.eclipse.org/434747 *******************************************************************************/ package org.eclipse.jdt.ui.tests.refactoring; @@ -270,42 +271,42 @@ public class InlineTempTests extends RefactoringTest { // add explicit cast for primitive types: https://bugs.eclipse.org/bugs/show_bug.cgi?id=46216 helper1(5, 14, 5, 15); } - + public void test34() throws Exception{ // add explicit cast for boxing: https://bugs.eclipse.org/bugs/show_bug.cgi?id=201434#c4 helper1(5, 17, 5, 17); } - + public void test35() throws Exception{ // add explicit cast for unchecked conversion: https://bugs.eclipse.org/bugs/show_bug.cgi?id=201434#c0 helper1(7, 32, 7, 36); } - + public void test36() throws Exception{ // parenthesize complex cast expression helper1(6, 21, 6, 24); } - + public void test37() throws Exception{ // parameterized method invocation needs class expression: https://bugs.eclipse.org/bugs/show_bug.cgi?id=277968 helper1(5, 16, 5, 17); } - + public void test38() throws Exception{ // parameterized method invocation needs this expression: https://bugs.eclipse.org/bugs/show_bug.cgi?id=277968 helper1(5, 16, 5, 17); } - + public void test39() throws Exception{ // parameterized method invocation needs to keep super expression: https://bugs.eclipse.org/bugs/show_bug.cgi?id=277968 helper1(5, 16, 5, 17); } - + public void test40() throws Exception{ // better cast for unboxing: https://bugs.eclipse.org/bugs/show_bug.cgi?id=297868 helper1(5, 43, 5, 46); } - + public void test41() throws Exception { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173 helper1(5, 13, 5, 14); @@ -325,7 +326,7 @@ public class InlineTempTests extends RefactoringTest { // don't add unnecessary cast to wildcard-parameterized type https://bugs.eclipse.org/bugs/show_bug.cgi?id=338271 helper1(7, 35, 7, 41); } - + public void test45() throws Exception { // don't delete comment right before the local variable declaration (bug 295200) helper1(5, 18, 5, 22); @@ -356,6 +357,16 @@ public class InlineTempTests extends RefactoringTest { helper1(4, 17, 4, 18); } + public void test51() throws Exception { + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=434747 + helper1(4, 16, 4, 17); + } + + public void test52() throws Exception { + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=434747 + helper1(4, 14, 4, 15); + } + //------ public void testFail0() throws Exception{ @@ -428,10 +439,4 @@ public class InlineTempTests extends RefactoringTest { helper2(5, 17, 5, 18); } - public void testFail15() throws Exception { - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93850 - //https://bugs.eclipse.org/bugs/show_bug.cgi?id=434747 - helper2(5, 16, 5, 17); - } - } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests18.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests18.java index 255e187c82..6fd678547d 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests18.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/InlineTempTests18.java @@ -54,7 +54,7 @@ public class InlineTempTests18 extends InlineTempTests { public void test2() throws Exception { helper1(5, 20, 5, 25); } - + @Override public void test3() throws Exception { helper1(9, 29, 9, 36); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceFactoryTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceFactoryTests.java index 1d4443de9a..1b05ca089b 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceFactoryTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceFactoryTests.java @@ -219,7 +219,7 @@ public class IntroduceFactoryTests extends RefactoringTest { assertEqualLines(getName() + ": ", getFileContents(outputFileName), newSource); } - + private void doSingleUnitTestWithWarning(boolean protectConstructor, ICompilationUnit cu, String outputFileName) throws Exception, JavaModelException, IOException { ISourceRange selection= findSelectionInSource(cu.getSource()); IntroduceFactoryRefactoring ref= new IntroduceFactoryRefactoring(cu, selection.getOffset(), selection.getLength()); @@ -274,7 +274,7 @@ public class IntroduceFactoryTests extends RefactoringTest { doSingleUnitTest(protectConstructor, cu, getBugTestFileName(null, getPackageP(), baseFileName, false)); } - + protected void singleUnitBugHelperWithWarning(String baseFileName, boolean protectConstructor) throws Exception { @@ -751,23 +751,23 @@ public class IntroduceFactoryTests extends RefactoringTest { public void test250660() throws Exception { singleUnitBugHelper("HasAnonymous", true); } - + public void test74759() throws Exception { singleUnitBugHelper("Test", true); } - + public void test298281() throws Exception { singleUnitBugHelper("Thing", true); } - + public void test395016_1() throws Exception { singleUnitBugHelperWithWarning("AbstractClass", true); } - + public void test395016_2() throws Exception { singleUnitBugHelperWithWarning("AbstractMethod", true); } - + public void testFactoryClash() throws Exception { failHelper(RefactoringStatus.ERROR); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceIndirectionTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceIndirectionTests.java index cf5c2f20c1..8845c5520a 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceIndirectionTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceIndirectionTests.java @@ -242,7 +242,7 @@ public class IntroduceIndirectionTests extends RefactoringTest { } finally { getRoot().getJavaProject().setOption(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_METHOD_TYPE_PARAMETERS, JavaCore.DISABLED); } - + } public void test19() throws Exception { diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceIndirectionTests17.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceIndirectionTests17.java index 7940b60490..4c81c21876 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceIndirectionTests17.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceIndirectionTests17.java @@ -32,19 +32,19 @@ public class IntroduceIndirectionTests17 extends IntroduceIndirectionTests{ } // --- - + public void test17_32() throws Exception { // test for bug 349405 helperPass(new String[] { "p.Foo" }, "foo", "p.Foo", 10, 17, 10, 20); } - + public void test17_33() throws Exception { // test for bug 349405 helperPass(new String[] { "p.Foo" }, "getX", "p.Foo", 14, 17, 14, 21); } - + public void test17_34() throws Exception { - // test for bug + // test for bug helperFail(new String[] { "p.Foo" }, "m2", "p.Foo", 7, 18, 7, 18); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterObjectTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterObjectTests.java index e59c98623e..070bcfd6c2 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterObjectTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterObjectTests.java @@ -310,13 +310,13 @@ public class IntroduceParameterObjectTests extends RefactoringTest { fDescriptor.setParameters(parameters); runRefactoring(false, true); } - + public void testSubclassInCU() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=259095 fDescriptor.setMethod(setupMethod()); fDescriptor.setTopLevel(true); fDescriptor.setClassName("FooParameter"); - + runRefactoring(false, true); } @@ -412,14 +412,14 @@ public class IntroduceParameterObjectTests extends RefactoringTest { fDescriptor.setParameters(parameters); runRefactoring(false, true); } - + public void testMethodTypeParamArgs() throws Exception { fDescriptor.setMethod(setupMethod()); fDescriptor.setTopLevel(false); fDescriptor.setClassName("FooParameter"); runRefactoring(false, true); } - + public void testMethodTypeParamArgsTopLevel() throws Exception { fDescriptor.setMethod(setupMethod()); fDescriptor.setTopLevel(true); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterObjectTests18.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterObjectTests18.java index 1a2da4373b..822224ea22 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterObjectTests18.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterObjectTests18.java @@ -50,7 +50,7 @@ public class IntroduceParameterObjectTests18 extends IntroduceParameterObjectTes return REFACTORING_PATH; } - /* Test that @NonNull annotations ARE created if no @NonNullByDefault is in effect for the target location */ + /* Test that @NonNull annotations ARE created if no @NonNullByDefault is in effect for the target location */ public void testNoRedundantNonNull1() throws Exception { IJavaProject javaProject= getRoot().getJavaProject(); Map<String, String> originalOptions= javaProject.getOptions(false); @@ -69,7 +69,7 @@ public class IntroduceParameterObjectTests18 extends IntroduceParameterObjectTes javaProject.setOptions(originalOptions); } } - /* Test that @NonNull annotations ARE NOT created if @NonNullByDefault is in effect for the target location */ + /* Test that @NonNull annotations ARE NOT created if @NonNullByDefault is in effect for the target location */ public void testNoRedundantNonNull2() throws Exception { IJavaProject javaProject= getRoot().getJavaProject(); Map<String, String> originalOptions= javaProject.getOptions(false); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterTests17.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterTests17.java index 156fcb45ad..3d441ed3a6 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterTests17.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/IntroduceParameterTests17.java @@ -41,17 +41,17 @@ public class IntroduceParameterTests17 extends IntroduceParameterTests { public void testSimple17_Catch2() throws Exception { performOK(); } - + public void testSimple17_NewInstance2() throws Exception { performOK(); } - + public void testSimple17_NewInstance3() throws Exception { performOK(); } - + public void testSimple17_NewInstance4() throws Exception { performOK(); } - + } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveInnerToTopLevelTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveInnerToTopLevelTests.java index 229ba56407..5514ff2e68 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveInnerToTopLevelTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveInnerToTopLevelTests.java @@ -44,7 +44,7 @@ import junit.framework.TestSuite; public class MoveInnerToTopLevelTests extends RefactoringTest { private static final boolean BUG_304827= true; // too many imports, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=304827 - + private static final String FIELD_COMMENT= "/** Comment */"; private static final Class<MoveInnerToTopLevelTests> clazz= MoveInnerToTopLevelTests.class; private static final String REFACTORING_PATH= "MoveInnerToTopLevel/"; @@ -368,35 +368,35 @@ public class MoveInnerToTopLevelTests extends RefactoringTest { public void test39() throws Exception { validatePassingTest("A", "B", "p", new String[] { "A"}, new String[] { "p"}, null, false, true, false, false); } - + // change visibility: https://bugs.eclipse.org/319069 public void test40() throws Exception { validatePassingTest("A", "B", "p", new String[] { "A"}, new String[] { "p"}, null, false, true, false, false); } - + // change visibility: https://bugs.eclipse.org/319069 public void test41() throws Exception { validatePassingTest("A", "B", "p", new String[] { "A"}, new String[] { "p"}, null, false, true, false, false); } - + // change visibility: https://bugs.eclipse.org/319069 public void test42() throws Exception { validatePassingTest("A", "B", "p", new String[] { "A"}, new String[] { "p"}, null, false, true, false, false); } - + public void test43() throws Exception { validatePassingTest("A", "B", "p", new String[] { "A"}, new String[] { "p"}, "", false, true, false, false); } - + public void test44() throws Exception { validatePassingTest("A", "B", "p", new String[] { "A"}, new String[] { "p"}, "a", true, true, true, true); } - + // static context: https://bugs.eclipse.org/bugs/show_bug.cgi?id=385237 public void test_static_context_0() throws Exception{ validatePassingTest("A", "Inner", new String[]{"A"}, new String[]{"p"}, null, false, false); } - + // --- Non static public void test_nonstatic_0() throws Exception{ @@ -588,7 +588,7 @@ public class MoveInnerToTopLevelTests extends RefactoringTest { StubUtility.setCodeTemplate(CodeTemplateContextType.FILECOMMENT_ID, fileCommentTemplate, null); String newFileTemplate= "${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}"; StubUtility.setCodeTemplate(CodeTemplateContextType.NEWTYPE_ID, newFileTemplate, null); - + try { validatePassingTest("A", "B", "p", new String[] { "A" }, new String[] { "p" }, null, false, true, false, false); } finally { @@ -596,7 +596,7 @@ public class MoveInnerToTopLevelTests extends RefactoringTest { StubUtility.setCodeTemplate(CodeTemplateContextType.FILECOMMENT_ID, fileCommentTemplate, null); } } - + public void test_nonstatic_49() throws Exception { validatePassingTest("A", "B", "p", new String[] { "A" }, new String[] { "p" }, "a", false, true, true, true); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveInstanceMethodTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveInstanceMethodTests.java index 0539469b06..8ca9d3b4f1 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveInstanceMethodTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveInstanceMethodTests.java @@ -446,12 +446,12 @@ public class MoveInstanceMethodTests extends RefactoringTest { public void test41() throws Exception { helper1(new String[] { "p.A" }, "p.A", 4, 10, 4, 10, PARAMETER, "b", true, true); } - + // Test problem with parameterized nested class (bug 342074) public void test42() throws Exception { helper1(new String[] { "p.A", "p.B", "p.Outer" }, "p.A", 6, 17, 6, 20, PARAMETER, "b", true, true); } - + // Test problem with enum (bug 339980) public void test43() throws Exception { helper1(new String[] { "p.A" }, "p.A", 10, 10, 10, 20, PARAMETER, "fooBar", true, true); @@ -471,7 +471,7 @@ public class MoveInstanceMethodTests extends RefactoringTest { public void test46() throws Exception { helper1(new String[] { "p.A", "p.B" }, "p.A", 6, 10, 6, 13, PARAMETER, "b", true, true); } - + // bug 385550 public void test47() throws Exception { helper1(new String[] { "p.A" }, "p.A", 8, 17, 8, 17, PARAMETER, "target", true, true); @@ -481,12 +481,12 @@ public class MoveInstanceMethodTests extends RefactoringTest { public void test48() throws Exception { helper1(new String[] { "p.A", "p.B", "q.C" }, "p.B", 3, 17, 3, 17, PARAMETER, "c", true, true); } - + //bug 356687 public void test49() throws Exception { helper1(new String[] {"p.A"}, "p.A", 5, 10, 5, 11, FIELD, "b", true, true); } - + //bug 356687 public void test50() throws Exception { helper1(new String[] {"p.A"}, "p.A", 4, 10, 4, 11, PARAMETER, "b", true, true); @@ -501,27 +501,27 @@ public class MoveInstanceMethodTests extends RefactoringTest { public void test52() throws Exception { helper1(new String[] {"p.A"}, "p.A", 5, 10, 5, 11, FIELD, "b", true, true); } - + //bug 356687 public void test53() throws Exception { helper1(new String[] {"p.A"}, "p.A", 4, 10, 4, 11, PARAMETER, "b", true, true); } - + //bug 356687 public void test54() throws Exception { helper1(new String[] {"p.A"}, "p.A", 4, 15, 4, 16, PARAMETER, "b", false, false); } - + //bug 356687 public void test55() throws Exception { helper1(new String[] {"p.A"}, "p.A", 4, 17, 4, 18, FIELD, "b", true, true); } - + //bug 356687 public void test56() throws Exception { helper1(new String[] {"p.A"}, "p.A", 3, 17, 3, 18, PARAMETER, "b", true, true); } - + //bug 356687 public void test57() throws Exception { helper1(new String[] { "p.A" }, "p.A", 5, 17, 5, 18, PARAMETER, "b", true, true); @@ -576,7 +576,7 @@ public class MoveInstanceMethodTests extends RefactoringTest { public void test67() throws Exception { helper1(new String[] { "A" }, "A", 6, 14, 6, 15, FIELD, "b", true, true); } - + // bug 441217 public void test68() throws Exception { helper1(new String[] { "A" }, "A", 6, 16, 6, 17, PARAMETER, "d", true, true); @@ -659,12 +659,12 @@ public class MoveInstanceMethodTests extends RefactoringTest { public void testFail15() throws Exception { failHelper1(new String[] { "A" }, "A", 3, 17, 3, 18, FIELD, "fB", true, true); } - + // bug 436997 - references enclosing instance public void testFail16() throws Exception { failHelper1(new String[] { "p1.A", "p1.B"}, "p1.A", 8, 14, 8, 15, PARAMETER, "b", true, true); } - + // Cannot move static method public void testFail2() throws Exception { failHelper1(new String[] { "p1.A", "p2.B"}, "p1.A", 6, 23, 6, 24, PARAMETER, "b", true, true); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/NoSuperTestsSuite.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/NoSuperTestsSuite.java index ce9a7fb38f..1f622e3bae 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/NoSuperTestsSuite.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/NoSuperTestsSuite.java @@ -20,7 +20,7 @@ import junit.framework.TestSuite; /** * Test suite that only includes tests from the given test class, but not * tests from super classes. - * + * * @since 3.7 */ public class NoSuperTestsSuite extends TestSuite { @@ -29,13 +29,13 @@ public class NoSuperTestsSuite extends TestSuite { * (in {@link junit.framework.TestSuite#addTestMethod}). * Alternative would have been to copy most of the implementation of TestSuite. */ - + private static final Class<? extends Test> WARNING_TEST_CLASS= warning(null).getClass(); public NoSuperTestsSuite(Class<? extends Test> theClass) { super(theClass); } - + /** * Adds the given test to this suite, but only if the test was declared in * the test object's class (and not in a superclass). @@ -54,7 +54,7 @@ public class NoSuperTestsSuite extends TestSuite { super.addTest(test); } } - + @Override public void addTestSuite(Class<? extends TestCase> testClass) { super.addTest(new NoSuperTestsSuite(testClass)); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameNonPrivateFieldTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameNonPrivateFieldTests.java index 8625b7cfcf..5c758a087f 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameNonPrivateFieldTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameNonPrivateFieldTests.java @@ -118,9 +118,9 @@ public class RenameNonPrivateFieldTests extends RefactoringTest { /** * Configure options by setting instance fields to non-default values. - * @param fieldName - * @param newFieldName - * @throws Exception + * @param fieldName + * @param newFieldName + * @throws Exception */ private void helper2(String fieldName, String newFieldName) throws Exception { helper2(fieldName, newFieldName, false); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTempTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTempTests.java index df5e426e07..c8a0d921f6 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTempTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTempTests.java @@ -446,7 +446,7 @@ public class RenameTempTests extends RefactoringTest{ // regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=144426 helper1("xxx"); } - + // ----- public void testFail0() throws Exception{ if (BUG_checkDeclInNestedClass) { diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTests.java index 331e9cc25b..edca4eb161 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTests.java @@ -39,7 +39,7 @@ public class RenameTests { suite.addTest(RenameNonPrivateFieldTests.suite()); suite.addTest(RenameJavaProjectTests.suite()); suite.addTest(RenameTests18.suite()); - + //XXX: NOT part of AllRefactoringTests. Also add suites there! return suite; diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTests18.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTests18.java index 701b77ae2a..8e74c1cda6 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTests18.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTests18.java @@ -168,10 +168,10 @@ public class RenameTests18 extends RefactoringTest { * cu.getBuffer() is a jdt.internal.core.Buffer and not a DocumentAdapter. * The cu is NOT in working copy mode. * Somehow, the BecomeWorkingCopyOperation failed. - * + * * Observation: The A.java files contain secondary types. Maybe a threading problem * with the indexer? - * + * * A failing test execution order of RenameTests18 with jdk7: * - green: testMethodReference0 * - fails: testLambda0 @@ -210,7 +210,7 @@ public class RenameTests18 extends RefactoringTest { public void testLambda2() throws Exception { renameLocalVariable("renamedIi", true); } - + public void testLambda3() throws Exception { renameLocalVariable("x_renamed", true); } @@ -265,12 +265,12 @@ public class RenameTests18 extends RefactoringTest { private void renameMethodInInterface() throws Exception{ renameMethod("m", "k", new String[0], true, true, false); } - + // method with a lambda method as reference public void testMethod0() throws Exception{ renameMethodInInterface(); } - + // method with method references as reference public void testMethod1() throws Exception{ renameMethodInInterface(); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTypeParameterTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTypeParameterTests.java index cefc324029..05684ae5c7 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTypeParameterTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTypeParameterTests.java @@ -191,7 +191,7 @@ public class RenameTypeParameterTests extends RefactoringTest { public void test15() throws Exception { helper2("T", "S", "A", true); } - + // ------------------------------------------------ public void testFail0() throws Exception { diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTypeTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTypeTests.java index 6c0e92d313..9f1283e9c5 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTypeTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/RenameTypeTests.java @@ -781,11 +781,11 @@ public class RenameTypeTests extends RefactoringTest { // https://bugs.eclipse.org/356677 IPackageFragment packageP1= getRoot().createPackageFragment("p1", true, null); IPackageFragment packageP2= getRoot().createPackageFragment("p2", true, null); - + IType classA= getClassFromTestFile(packageP1, "A"); getClassFromTestFile(packageP1, "B"); getClassFromTestFile(packageP2, "C"); - + RefactoringStatus result= performRefactoring(createRefactoringDescriptor(classA, "C")); assertNotNull("precondition was supposed to fail", result); } @@ -1156,11 +1156,11 @@ public class RenameTypeTests extends RefactoringTest { // https://bugs.eclipse.org/356677 IPackageFragment packageP1= getRoot().createPackageFragment("p1", true, null); IPackageFragment packageP2= getRoot().createPackageFragment("p2", true, null); - + IType classA= getClassFromTestFile(packageP1, "A"); IType classB= getClassFromTestFile(packageP1, "B"); IType classC= getClassFromTestFile(packageP2, "C"); - + RefactoringStatus result= performRefactoring(createRefactoringDescriptor(classA, "C")); assertEquals("was supposed to pass", null, result); @@ -1168,7 +1168,7 @@ public class RenameTypeTests extends RefactoringTest { assertEqualLines("invalid renaming in B", getFileContents(getOutputTestFileName("B")), classB.getCompilationUnit().getSource()); assertEqualLines("invalid renaming in C", getFileContents(getOutputTestFileName("C")), classC.getCompilationUnit().getSource()); } - + public void test66() throws Exception { //https://bugs.eclipse.org/bugs/show_bug.cgi?id=365380 helperWithTextual("B", "A", "B", "B", true, true); diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithResourcesTestSetup18.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithResourcesTestSetup18.java new file mode 100644 index 0000000000..2e379201df --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithResourcesTestSetup18.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial implementation based on SurroundWithTestSetup18 + *******************************************************************************/ +package org.eclipse.jdt.ui.tests.refactoring; + +import java.util.Hashtable; + +import junit.extensions.TestSetup; +import junit.framework.Test; + +import org.eclipse.jdt.testplugin.JavaProjectHelper; +import org.eclipse.jdt.testplugin.TestOptions; + +import org.eclipse.ltk.core.refactoring.RefactoringCore; + +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; + +import org.eclipse.jdt.internal.core.manipulation.CodeTemplateContextType; +import org.eclipse.jdt.internal.core.manipulation.StubUtility; + +import org.eclipse.jdt.internal.ui.JavaPlugin; +import org.eclipse.jdt.internal.ui.util.CoreUtility; + + +public class SurroundWithResourcesTestSetup18 extends TestSetup { + + private IJavaProject fJavaProject; + + private IPackageFragmentRoot fRoot; + + private static final String CONTAINER= "src"; + + private IPackageFragment fTryResourcesPackage; + + public SurroundWithResourcesTestSetup18(Test test) { + super(test); + } + + public IPackageFragmentRoot getRoot() { + return fRoot; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + Hashtable<String, String> options= TestOptions.getDefaultOptions(); + options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.TAB); + options.put(DefaultCodeFormatterConstants.FORMATTER_NUMBER_OF_EMPTY_LINES_TO_PRESERVE, "0"); + options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); + JavaCore.setOptions(options); + TestOptions.initializeCodeGenerationOptions(); + JavaPlugin.getDefault().getCodeTemplateStore().load(); + + fJavaProject= JavaProjectHelper.createJavaProject("TestProject18", "bin"); + JavaProjectHelper.addRTJar18(fJavaProject); + fRoot= JavaProjectHelper.addSourceContainer(fJavaProject, CONTAINER); + + RefactoringCore.getUndoManager().flush(); + CoreUtility.setAutoBuilding(false); + + fTryResourcesPackage= getRoot().createPackageFragment("tryresources18_in", true, null); + StubUtility.setCodeTemplate(CodeTemplateContextType.CATCHBLOCK_ID, "", null); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + JavaProjectHelper.delete(fJavaProject); + } + + public IPackageFragment getTryCatchPackage() { + return fTryResourcesPackage; + } +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithResourcesTests18.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithResourcesTests18.java new file mode 100644 index 0000000000..e06bd839de --- /dev/null +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithResourcesTests18.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial implementation based on SurroundWithTests18 + *******************************************************************************/ +package org.eclipse.jdt.ui.tests.refactoring; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; + +import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryWithResourcesRefactoring; + +import junit.framework.Test; + +public class SurroundWithResourcesTests18 extends AbstractSelectionTestCase { + + private static SurroundWithResourcesTestSetup18 fgTestSetup; + + public SurroundWithResourcesTests18(String name) { + super(name); + } + + public static Test suite() { + fgTestSetup= new SurroundWithResourcesTestSetup18(new NoSuperTestsSuite(SurroundWithResourcesTests18.class)); + return fgTestSetup; + } + + public static Test setUpTest(Test someTest) { + fgTestSetup= new SurroundWithResourcesTestSetup18(someTest); + return fgTestSetup; + } + + protected IPackageFragmentRoot getRoot() { + return fgTestSetup.getRoot(); + } + + @Override + protected String getResourceLocation() { + return "SurroundWithWorkSpace/SurroundWithTests/"; + } + + @Override + protected String adaptName(String name) { + return Character.toUpperCase(name.charAt(0)) + name.substring(1) + ".java"; + } + + protected void performTest(IPackageFragment packageFragment, String name, String outputFolder, int mode) throws Exception { + ICompilationUnit unit= createCU(packageFragment, name); + SurroundWithTryWithResourcesRefactoring refactoring= createRefactoring(unit); + String out= null; + if (mode == COMPARE_WITH_OUTPUT) + out= getProofedContent(outputFolder, name); + performTest(unit, refactoring, mode, out, true); + } + + protected SurroundWithTryWithResourcesRefactoring createRefactoring(ICompilationUnit unit) { + return SurroundWithTryWithResourcesRefactoring.create(unit, getTextSelection()); + } + + protected void tryResourcesInvalidTest() throws Exception { + performTest(fgTestSetup.getTryCatchPackage(), getName(), "tryresources18_out", INVALID_SELECTION); + } + + protected void tryResourcesTest() throws Exception { + performTest(fgTestSetup.getTryCatchPackage(), getName(), "tryresources18_out", COMPARE_WITH_OUTPUT); + } + + public void testSimple1() throws Exception { + tryResourcesTest(); + } + + public void testSimple2() throws Exception { + tryResourcesTest(); + } + + public void testSimple3() throws Exception { + tryResourcesTest(); + } + + public void testSimple4() throws Exception { + tryResourcesTest(); + } + + public void testNonClosableInserted1() throws Exception { + tryResourcesTest(); + } + + public void testWithException1() throws Exception { + tryResourcesTest(); + } + + public void testWithException2() throws Exception { + tryResourcesTest(); + } + + public void testWithThrows1() throws Exception { + tryResourcesTest(); + } + + public void testInvalidStatement1() throws Exception { + tryResourcesInvalidTest(); + } + + public void testInvalidParent1() throws Exception { + tryResourcesInvalidTest(); + } + + public void testInvalidParent2() throws Exception { + tryResourcesInvalidTest(); + } + + public void testMethodThrowsException1() throws Exception { + tryResourcesTest(); + } + + public void testMethodThrowsException2() throws Exception { + tryResourcesTest(); + } + + public void testInvalidTryResources1() throws Exception { + tryResourcesInvalidTest(); + } + + public void testExceptionFilter1() throws Exception { + tryResourcesTest(); + } + + public void testLambda1() throws Exception { + tryResourcesTest(); + } + + public void testLambda2() throws Exception { + tryResourcesInvalidTest(); + } + + public void testLambda3() throws Exception { + tryResourcesTest(); + } + + public void testLambda4() throws Exception { + tryResourcesInvalidTest(); + } + + public void testMethodReference1() throws Exception { + tryResourcesInvalidTest(); + } + +} diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithTests17.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithTests17.java index 47cca53e75..d6de131686 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithTests17.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/SurroundWithTests17.java @@ -66,7 +66,7 @@ public class SurroundWithTests17 extends SurroundWithTests { public void testSimple2() throws Exception { tryCatchTest(); } - + public void testMultiTryCatch() throws Exception { tryCatchTest(); } diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/NLSScannerTester.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/NLSScannerTester.java index eb56d2e5c0..1cc73fb993 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/NLSScannerTester.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/NLSScannerTester.java @@ -378,27 +378,27 @@ public class NLSScannerTester extends TestCase { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=xxx public void test26() throws Exception { String text= - "@interface Ann {\n" + - " String[] strings() default {\"a\", \"2\"};\n" + - " String string() default \"s\";\n" + - " String string2() default ((true) ? \"t\" : \"f\");\n" + - "}\n" + - "\n" + - "public interface Intf {\n" + - " default void foo() {\n" + - " System.out.println(\"Hello\");\n" + - " }\n" + + "@interface Ann {\n" + + " String[] strings() default {\"a\", \"2\"};\n" + + " String string() default \"s\";\n" + + " String string2() default ((true) ? \"t\" : \"f\");\n" + + "}\n" + + "\n" + + "public interface Intf {\n" + + " default void foo() {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + "}"; NLSLine[] l= NLSScanner.scan(text); - + assertEquals(1, l.length); - + NLSLine line= l[0]; assertEquals(1, line.size()); assertEquals(8, line.getLineNumber()); assertEquals("\"Hello\"", line.get(0).getValue()); } - + //regression test for bug 12600 public void test54() throws Exception{ String text= diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/NlsRefactoringCreateChangeTest.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/NlsRefactoringCreateChangeTest.java index f24ac8d919..f910c869de 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/NlsRefactoringCreateChangeTest.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/NlsRefactoringCreateChangeTest.java @@ -254,7 +254,7 @@ public class NlsRefactoringCreateChangeTest extends TestCase { buf.append("}"); checkContentOfCu("manipulated class", //$NON-NLS-1$ cu, buf.toString()); - + buf=new StringBuffer(); buf.append("test0=helloworld\n"); checkContentOfFile("properties", fHelper.getFile("/TestSetupProject/src2/p/test.properties"), buf.toString()); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/PropertyFileDocumentModellTest.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/PropertyFileDocumentModellTest.java index a9d75337b4..67c4e68c6f 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/PropertyFileDocumentModellTest.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/nls/PropertyFileDocumentModellTest.java @@ -288,13 +288,13 @@ public class PropertyFileDocumentModellTest extends TestCase { public void testRemovingOfKey2() throws Exception { Document props= new Document("org.eclipse.1=value1\n" + " org.eclipse.2 = value2 \n" + "org.eclipse.3=value3\n"); PropertyFileDocumentModel modell= new PropertyFileDocumentModel(props); - + DeleteEdit deleteEdit= modell.remove("org.eclipse.2"); deleteEdit.apply(props); - + assertEquals("org.eclipse.1=value1\n" + "org.eclipse.3=value3\n", props.get()); } - + public void testRemovingOfLastKey() throws Exception { Document props= new Document("org.eclipse.1=value1\n" + "org.eclipse.2=value2\n" + "org.eclipse.3=value3\n"); PropertyFileDocumentModel modell= new PropertyFileDocumentModel(props); diff --git a/org.eclipse.jdt.ui.tests/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.ui.tests/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.ui.tests/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.ui.tests/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/ChkpiiTests.java b/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/ChkpiiTests.java index 397f05aacf..36cdd6a49a 100644 --- a/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/ChkpiiTests.java +++ b/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/ChkpiiTests.java @@ -117,7 +117,7 @@ public class ChkpiiTests extends TestCase { public static Test suite() { return new TestSuite(ChkpiiTests.class); } - + public void testHTMLFiles() { assertChkpii(HTML); } @@ -349,7 +349,7 @@ public class ChkpiiTests extends TestCase { /** * Constructor for EmptyDirectoriesTest. - * + * * @param name the test name */ public ChkpiiTests(String name) { diff --git a/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/HTMLTidyTest.java b/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/HTMLTidyTest.java index 53c4bc4467..3ec3f7d5cc 100644 --- a/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/HTMLTidyTest.java +++ b/org.eclipse.jdt.ui.tests/chkpii/org/eclipse/jdt/ui/tests/chkpii/HTMLTidyTest.java @@ -60,7 +60,7 @@ public class HTMLTidyTest extends TestCase { * a Java launch configuration with program argument<br> * <code>"${resource_loc}"</code><br> * (including double quotes!). - * + * * @param args 1 argument: Absolute path to a file or folder * @throws Exception if checking fails */ diff --git a/org.eclipse.jdt.ui.tests/examples/org/eclipse/jdt/ui/examples/MultiElementListSelectorExample.java b/org.eclipse.jdt.ui.tests/examples/org/eclipse/jdt/ui/examples/MultiElementListSelectorExample.java index e7e36f1463..856918b4d9 100644 --- a/org.eclipse.jdt.ui.tests/examples/org/eclipse/jdt/ui/examples/MultiElementListSelectorExample.java +++ b/org.eclipse.jdt.ui.tests/examples/org/eclipse/jdt/ui/examples/MultiElementListSelectorExample.java @@ -73,7 +73,7 @@ public class MultiElementListSelectorExample { elements[i][k]= "elem-" + i + "-" + k; } } - + Display display= new Display(); MultiElementListSelectionDialog d= new MultiElementListSelectionDialog(new Shell(display), elementRenderer); d.setTitle("Title"); diff --git a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/leaktest/LeakTestCase.java b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/leaktest/LeakTestCase.java index 13ee13f4ea..5fc95b9481 100644 --- a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/leaktest/LeakTestCase.java +++ b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/leaktest/LeakTestCase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,10 @@ *******************************************************************************/ package org.eclipse.jdt.ui.leaktest; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; + import org.eclipse.jdt.testplugin.util.DisplayHelper; import org.eclipse.swt.widgets.Display; @@ -24,13 +28,11 @@ import org.eclipse.jdt.ui.leaktest.reftracker.ReferenceTracker; import org.eclipse.jdt.ui.leaktest.reftracker.ReferenceVisitor; import org.eclipse.jdt.ui.leaktest.reftracker.ReferencedObject; -import junit.framework.TestCase; - /** * Base class for leak test cases. */ -public class LeakTestCase extends TestCase { +public class LeakTestCase { public class MulipleCollectorVisitor extends ReferenceVisitor { private ReferenceVisitor[] fVisitors; @@ -51,10 +53,6 @@ public class LeakTestCase extends TestCase { } - public LeakTestCase(String name) { - super(name); - } - private InstancesOfTypeCollector collect(String requestedTypeName) { InstancesOfTypeCollector requestor= new InstancesOfTypeCollector(requestedTypeName, false); calmDown(); @@ -86,9 +84,8 @@ public class LeakTestCase extends TestCase { * @see junit.framework.TestCase#setUp() * @since 3.4 */ - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { // Ensure active page to allow test being run IWorkbenchWindow activeWindow= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWindow.getActivePage() == null) { @@ -185,7 +182,7 @@ public class LeakTestCase extends TestCase { /** * Assert that two counts are different. The method does not fail if the profile connection has * not established (e.g. because profiling is not supported on the given platform). - * + * * @param startCount the start count * @param endCount the end count */ @@ -196,9 +193,9 @@ public class LeakTestCase extends TestCase { /** * Assert that two counts are different. The method does not fail if the profile connection has * not established (e.g. because profiling is not supported on the given platform) - * + * * @param message Message to be printed if the test fails. - * + * * @param startCount the start count * @param endCount the end count */ @@ -212,7 +209,7 @@ public class LeakTestCase extends TestCase { /** * Assert that two counts are equal. The method does not fail if the profile connection has not * established (e.g. because profiling is not supported on the given platform). - * + * * @param startCount the start count * @param endCount the end count */ @@ -223,7 +220,7 @@ public class LeakTestCase extends TestCase { /** * Assert that two counts are equal. The method does not fail if the profile connection has not * established (e.g. because profiling is not supported on the given platform). - * + * * @param message Message to be printed if the test fails. * @param startCount the start count * @param endCount the end count diff --git a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/leaktest/example/LeakTestExample.java b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/leaktest/example/LeakTestExample.java index a6c3b2eabd..cea475d65d 100644 --- a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/leaktest/example/LeakTestExample.java +++ b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/leaktest/example/LeakTestExample.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,33 +15,28 @@ package org.eclipse.jdt.ui.leaktest.example; import java.util.ArrayList; -import org.eclipse.jdt.ui.leaktest.LeakTestCase; -import org.eclipse.jdt.ui.leaktest.LeakTestSetup; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.eclipse.jdt.ui.leaktest.LeakTestCase; +import org.eclipse.jdt.ui.tests.core.rules.LeakTestSetup; +@RunWith(JUnit4.class) public class LeakTestExample extends LeakTestCase { - private static final Class<LeakTestExample> THIS= LeakTestExample.class; + @Rule + public LeakTestSetup projectsetup = new LeakTestSetup(); private static class MyClass { } - - public static Test suite() { - return new LeakTestSetup(new TestSuite(THIS)); - } - private Object fGlobalReference; private ArrayList<Object> fGlobalList= new ArrayList<>(); - public LeakTestExample(String name) { - super(name); - } - + @Test public void testLeakGlobalReference() throws Exception { fGlobalList.clear(); @@ -65,6 +60,7 @@ public class LeakTestExample extends LeakTestCase { assertEqualCount("after clear: ", count1, count3); } + @Test public void testNoLeakGlobalReference() throws Exception { fGlobalList.clear(); Class<MyClass> cl= MyClass.class; diff --git a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/JavaLeakTest.java b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/JavaLeakTest.java index 4e473ffdf0..f9bdfd2d6a 100644 --- a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/JavaLeakTest.java +++ b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/JavaLeakTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,8 +13,19 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.leaks; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.jdt.testplugin.util.DisplayHelper; @@ -56,7 +67,7 @@ import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.ui.leaktest.LeakTestCase; -import org.eclipse.jdt.ui.leaktest.LeakTestSetup; +import org.eclipse.jdt.ui.tests.core.rules.LeakTestSetup; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; @@ -68,32 +79,21 @@ import org.eclipse.jdt.internal.ui.wizards.JavaProjectWizard; import org.eclipse.jdt.internal.ui.wizards.NewClassCreationWizard; import org.eclipse.jdt.internal.ui.wizards.NewInterfaceCreationWizard; -import junit.framework.Test; -import junit.framework.TestSuite; - +@RunWith(JUnit4.class) public class JavaLeakTest extends LeakTestCase { - private IJavaProject fJProject; - - private static final Class<JavaLeakTest> THIS= JavaLeakTest.class; - - public JavaLeakTest(String name) { - super(name); - } - - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } + @Rule + public LeakTestSetup projectsetup = new LeakTestSetup(); - public static Test setUpTest(Test test) { - return new LeakTestSetup(test); - } + private IJavaProject fJProject; + @Test public void testTextEditorClose() throws Exception { IFile file= createTestFile("Test.txt"); internalTestEditorClose(file, TextEditor.class, false); } + @Test public void testTextEditorCloseOneOfTwo() throws Exception { IFile file1= createTestFile("Test1.txt"); IEditorPart editor1= EditorUtility.openInEditor(file1); @@ -112,20 +112,23 @@ public class JavaLeakTest extends LeakTestCase { assertTrue("Could not close editor", JavaPlugin.getActivePage().closeEditor(editor1, false)); editor1= null; - + assertInstanceCount(TextEditor.class, 0); } + @Test public void testTextEditorCloseAll() throws Exception { IFile file= createTestFile("Test.txt"); internalTestEditorClose(file, TextEditor.class, true); } + @Test public void testPropertiesEditorClose() throws Exception { IFile file= createTestFile("Test.properties"); internalTestEditorClose(file, PropertiesFileEditor.class, false); } + @Test public void testPropertiesEditorCloseOneOfTwo() throws Exception { IFile file1= createTestFile("Test1.properties"); IEditorPart editor1= EditorUtility.openInEditor(file1); @@ -148,16 +151,19 @@ public class JavaLeakTest extends LeakTestCase { assertInstanceCount(PropertiesFileEditor.class, 0); } + @Test public void testPropertiesEditorCloseAll() throws Exception { IFile file= createTestFile("Test.properties"); internalTestEditorClose(file, PropertiesFileEditor.class, true); } + @Test public void testJavaEditorClose() throws Exception { ICompilationUnit cu= createTestCU("Test"); internalTestEditorClose(cu, CompilationUnitEditor.class, false); } + @Test public void testJavaEditorCloseOneOfTwo() throws Exception { ICompilationUnit cu1= createTestCU("Test1"); IEditorPart editor1= EditorUtility.openInEditor(cu1); @@ -180,11 +186,13 @@ public class JavaLeakTest extends LeakTestCase { assertInstanceCount(CompilationUnitEditor.class, 0); } + @Test public void testJavaEditorCloseAll() throws Exception { ICompilationUnit cu= createTestCU("Test"); internalTestEditorClose(cu, CompilationUnitEditor.class, true); } + @Test public void testJavaEditorBreadcrumbCloseAll() throws Exception { try { JavaPlugin.getDefault().getPreferenceStore().setValue(getBreadcrumbPreferenceKey(), true); @@ -195,6 +203,7 @@ public class JavaLeakTest extends LeakTestCase { } } + @Test public void testJavaEditorBreadcrumbClose() throws Exception { try { JavaPlugin.getDefault().getPreferenceStore().setValue(getBreadcrumbPreferenceKey(), true); @@ -205,6 +214,7 @@ public class JavaLeakTest extends LeakTestCase { } } + @Test public void testJavaEditorBreadcrumbCloseOneOfTwo1() throws Exception { try { JavaPlugin.getDefault().getPreferenceStore().setValue(getBreadcrumbPreferenceKey(), true); @@ -234,6 +244,7 @@ public class JavaLeakTest extends LeakTestCase { } } + @Test public void testJavaEditorBreadcrumbCloseOneOfTwo2() throws Exception { try { JavaPlugin.getDefault().getPreferenceStore().setValue(getBreadcrumbPreferenceKey(), true); @@ -264,16 +275,16 @@ public class JavaLeakTest extends LeakTestCase { } @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { super.setUp(); fJProject= JavaProjectHelper.createJavaProject("TestProject1", "bin"); assertTrue("RT not found", JavaProjectHelper.addRTJar(fJProject) != null); assertTrue(JavaPlugin.getActivePage().closeAllEditors(false)); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { JavaProjectHelper.delete(fJProject); } @@ -380,18 +391,21 @@ public class JavaLeakTest extends LeakTestCase { return part; } + @Test public void testNewClassWizard() throws Exception { assertInstanceCount(NewClassCreationWizard.class, 0); doWizardLeakTest(new NewClassCreationWizard()); assertInstanceCount(NewClassCreationWizard.class, 0); } + @Test public void testNewInterfaceWizard() throws Exception { assertInstanceCount(NewInterfaceCreationWizard.class, 0); doWizardLeakTest(new NewInterfaceCreationWizard()); assertInstanceCount(NewInterfaceCreationWizard.class, 0); } + @Test public void testNewJavaProjectWizard() throws Exception { assertInstanceCount(JavaProjectWizard.class, 0); doWizardLeakTest(new JavaProjectWizard()); @@ -412,6 +426,7 @@ public class JavaLeakTest extends LeakTestCase { dialog= null; } + @Test public void testJavaEditorContextMenu() throws Exception { //regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=166761 @@ -450,6 +465,7 @@ public class JavaLeakTest extends LeakTestCase { } } + @Test public void testJavaEditorActionDelegate() throws Exception { //regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=166761 @@ -461,7 +477,7 @@ public class JavaLeakTest extends LeakTestCase { shell.forceActive(); // run display loop, such that GTK can send shell activate events, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=286244 DisplayHelper.sleep(shell.getDisplay(), 5000); - + IWorkbench workbench= workbenchWindow.getWorkbench(); part.getEditorSite().getPage().activate(part); IHandlerService handlerService= workbench.getService(IHandlerService.class); diff --git a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/TextViewerUndoManagerLeakTest.java b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/TextViewerUndoManagerLeakTest.java index f7f7f973c1..e7ce9a0fe2 100644 --- a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/TextViewerUndoManagerLeakTest.java +++ b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/TextViewerUndoManagerLeakTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2015 IBM Corporation and others. + * Copyright (c) 2006, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,16 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.leaks; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; @@ -28,18 +38,19 @@ import org.eclipse.jface.text.TextViewer; import org.eclipse.jface.text.TextViewerUndoManager; import org.eclipse.jdt.ui.leaktest.LeakTestCase; -import org.eclipse.jdt.ui.leaktest.LeakTestSetup; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.eclipse.jdt.ui.tests.core.rules.LeakTestSetup; /** * Tests for leaks in TextViewerUndoManager. * * @since 3.2 */ +@RunWith(JUnit4.class) public class TextViewerUndoManagerLeakTest extends LeakTestCase { + @Rule + public LeakTestSetup projectsetup = new LeakTestSetup(); + /** The maximum undo level. */ private static final int MAX_UNDO_LEVEL= 256; @@ -50,22 +61,12 @@ public class TextViewerUndoManagerLeakTest extends LeakTestCase { /** The undo manager. */ private IUndoManager fUndoManager; - public static Test suite() { - return new LeakTestSetup(new TestSuite(TextViewerUndoManagerLeakTest.class)); - } - - /* - * @see TestCase#TestCase(String) - */ - public TextViewerUndoManagerLeakTest(final String name) { - super(name); - } - /* * @see TestCase#setUp() */ @Override - protected void setUp() { + @Before + public void setUp() { fShell= new Shell(); fUndoManager= new TextViewerUndoManager(MAX_UNDO_LEVEL); fTextViewer= new TextViewer(fShell, SWT.NONE); @@ -73,6 +74,7 @@ public class TextViewerUndoManagerLeakTest extends LeakTestCase { fUndoManager.connect(fTextViewer); } + @Test public void testTextViewerUndoManager() throws Exception{ // There is always a document instance around, hence a DocumentUndoManager. // So count instances first. diff --git a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/UndoManagerLeakTest.java b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/UndoManagerLeakTest.java index c1a6c50af4..2c33c97be3 100644 --- a/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/UndoManagerLeakTest.java +++ b/org.eclipse.jdt.ui.tests/leaks/org/eclipse/jdt/ui/tests/leaks/UndoManagerLeakTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,16 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.leaks; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; @@ -26,18 +36,19 @@ import org.eclipse.jface.text.Position; import org.eclipse.jface.text.TextViewer; import org.eclipse.jdt.ui.leaktest.LeakTestCase; -import org.eclipse.jdt.ui.leaktest.LeakTestSetup; - -import junit.framework.Test; -import junit.framework.TestSuite; +import org.eclipse.jdt.ui.tests.core.rules.LeakTestSetup; /** * Test for leaks in DefaultUndoManager. * * @since 3.1 */ +@RunWith(JUnit4.class) public class UndoManagerLeakTest extends LeakTestCase { + @Rule + public LeakTestSetup projectsetup = new LeakTestSetup(); + /** The maximum undo level. */ private static final int MAX_UNDO_LEVEL= 256; @@ -48,22 +59,12 @@ public class UndoManagerLeakTest extends LeakTestCase { /** The undo manager. */ private IUndoManager fUndoManager; - public static Test suite() { - return new LeakTestSetup(new TestSuite(UndoManagerLeakTest.class)); - } - - /* - * @see TestCase#TestCase(String) - */ - public UndoManagerLeakTest(final String name) { - super(name); - } - /* * @see TestCase#setUp() */ @Override - protected void setUp() { + @Before + public void setUp() { fShell= new Shell(); fUndoManager= new DefaultUndoManager(MAX_UNDO_LEVEL); fTextViewer= new TextViewer(fShell, SWT.NONE); @@ -71,6 +72,7 @@ public class UndoManagerLeakTest extends LeakTestCase { fUndoManager.connect(fTextViewer); } + @Test public void testUndoManagerLeak() { internalTestConvertLineDelimiters(); internalTestRandomAccess(); diff --git a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/SWTTestProject.java b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/SWTTestProject.java index fc40023744..08f8dd3d2c 100644 --- a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/SWTTestProject.java +++ b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/SWTTestProject.java @@ -67,7 +67,7 @@ public class SWTTestProject { IProject project= createExistingProject(PROJECT); fProject= JavaCore.create(project); - + /* Can't use the default system JRE: * - some classes in the archive are not 1.4 compliant, e.g. GridData uses 'enum' as identifier * - search engine reports wrong inaccurate matches, see bug 443411 @@ -75,7 +75,7 @@ public class SWTTestProject { */ JavaProjectHelper.removeFromClasspath(fProject, new Path(JavaRuntime.JRE_CONTAINER)); JavaProjectHelper.addRTJar13(fProject); - + Assert.assertTrue(fProject.exists()); } diff --git a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/Accessor.java b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/Accessor.java index fd552eb3d9..225fae458e 100644 --- a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/Accessor.java +++ b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/Accessor.java @@ -27,8 +27,8 @@ import org.eclipse.core.runtime.Assert; * <p> * <strong>Note:</strong> Copied from org.eclipse.text.tests. * </p> - * @param <E> The - * + * @param <E> The + * * @since 3.5 */ class Accessor<E> { diff --git a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/OrganizeImportsPerfTest.java b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/OrganizeImportsPerfTest.java index 247fff0e21..85246f8024 100644 --- a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/OrganizeImportsPerfTest.java +++ b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/OrganizeImportsPerfTest.java @@ -101,10 +101,10 @@ public class OrganizeImportsPerfTest extends JdtPerformanceTestCase { public void testOrganizeImport() throws Exception { measure(Performance.getDefault().getNullPerformanceMeter(), 10); measure(fPerformanceMeter, 10); - - // test is too short and hence the relative numbers spread too far (but still in an acceptable absolute band) + + // test is too short and hence the relative numbers spread too far (but still in an acceptable absolute band) // tagAsSummary("Organize Imports", Dimension.ELAPSED_PROCESS); - + commitMeasurements(); Performance.getDefault().assertPerformance(fPerformanceMeter); } @@ -117,7 +117,7 @@ public class OrganizeImportsPerfTest extends JdtPerformanceTestCase { CompilationUnit[] roots= createASTs(cus); joinBackgroudActivities(); - + performanceMeter.start(); for (int i= 0; i < roots.length; i++) { OrganizeImportsOperation op= new OrganizeImportsOperation(cus[i], roots[i], true, true, true, null); @@ -125,7 +125,7 @@ public class OrganizeImportsPerfTest extends JdtPerformanceTestCase { } performanceMeter.stop(); } - + } } diff --git a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/PackageExplorerPerfTest.java b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/PackageExplorerPerfTest.java index f463e170d0..e80e273747 100644 --- a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/PackageExplorerPerfTest.java +++ b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/PackageExplorerPerfTest.java @@ -128,7 +128,7 @@ public class PackageExplorerPerfTest extends JdtPerformanceTestCase { File jreArchive= JavaTestPlugin.getDefault().getFileInPlugin(JavaProjectHelper.RT_STUBS_15); IPackageFragmentRoot classFolder= JavaProjectHelper.addClassFolderWithImport(javaProject, "classes", null, null, jreArchive); ((IFolder) classFolder.getResource()).getFolder("META-INF").delete(true, null); - + try (ZipFile zipFile= new ZipFile(jreArchive)) { for (int i= 1; i <= 5; i++) { String packName= "copy" + i; @@ -138,7 +138,7 @@ public class PackageExplorerPerfTest extends JdtPerformanceTestCase { folder.getFolder("META-INF").delete(true, null); } } - + javaProject.getProject().getWorkspace().run(new IWorkspaceRunnable() { @Override public void run(IProgressMonitor monitor) throws CoreException { @@ -146,20 +146,20 @@ public class PackageExplorerPerfTest extends JdtPerformanceTestCase { } }, null); getViewer().expandToLevel(classFolder, 1); - + PackageExplorerPart view= getView(); view.selectAndReveal(classFolder); // runs pending updates - + joinBackgroudActivities(); touchAllFilesOnDisk((IFolder) classFolder.getResource()); - - + + startMeasuring(); javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); view.selectAndReveal(classFolder); // runs pending updates finishMeasurements(); } - + private void touchAllFilesOnDisk(IFolder folder) throws CoreException { final long now= System.currentTimeMillis(); folder.accept(new IResourceVisitor() { diff --git a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/TypeHierarchyPerfTest.java b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/TypeHierarchyPerfTest.java index c49c1a9593..fe6e54d838 100644 --- a/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/TypeHierarchyPerfTest.java +++ b/org.eclipse.jdt.ui.tests/performance/org/eclipse/jdt/ui/tests/performance/views/TypeHierarchyPerfTest.java @@ -90,13 +90,13 @@ public class TypeHierarchyPerfTest extends JdtPerformanceTestCase { public void testOpenObjectHierarchy() throws Exception { //cold - - // make sure stuff like the Intro view gets closed and we start with a clean Java perspective: + + // make sure stuff like the Intro view gets closed and we start with a clean Java perspective: IWorkbenchWindow activeWorkbenchWindow= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page= activeWorkbenchWindow.getActivePage(); page.close(); page= activeWorkbenchWindow.openPage(JavaUI.ID_PERSPECTIVE, ResourcesPlugin.getWorkspace().getRoot()); - + measureOpenHierarchy(MyTestSetup.fJProject1.findType("java.lang.Object")); Performance.getDefault().assertPerformanceInAbsoluteBand(fPerformanceMeter, Dimension.ELAPSED_PROCESS, 0, 2000); } @@ -110,22 +110,22 @@ public class TypeHierarchyPerfTest extends JdtPerformanceTestCase { public void testOpenObjectHierarchy2() throws Exception { //warm tagAsSummary("Open type hierarchy on Object", Dimension.ELAPSED_PROCESS); - + IJavaElement element= MyTestSetup.fJProject1.findType("java.lang.Object"); IWorkbenchWindow workbenchWindow= JavaPlugin.getActiveWorkbenchWindow(); - + TypeHierarchyViewPart viewPart= OpenTypeHierarchyUtil.open(element, workbenchWindow); - + for (int i= 0; i < 10; i++) { viewPart.setInputElement(MyTestSetup.fJProject1.findType("java.lang.String")); viewPart.getSite().getPage().hideView(viewPart); - + joinBackgroudActivities(); startMeasuring(); viewPart= OpenTypeHierarchyUtil.open(element, workbenchWindow); stopMeasuring(); } - + commitMeasurements(); assertPerformanceInRelativeBand(Dimension.ELAPSED_PROCESS, -100, +10); } diff --git a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java index 0b5a3a93d9..3dcdbfe2d9 100644 --- a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java +++ b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/JavaProjectHelper.java @@ -83,7 +83,7 @@ public class JavaProjectHelper { * If external code increases this counter, then it MUST decrease it again (e.g. in TestSetup's setUp/tearDown). */ public static int PERFORM_DUMMY_SEARCH= 0; - + /** * @deprecated use {@link #RT_STUBS_15} */ @@ -206,7 +206,7 @@ public class JavaProjectHelper { /** * Sets the compiler options to 9 for the given project. - * + * * @param project the java project * @since 3.14 */ @@ -218,7 +218,7 @@ public class JavaProjectHelper { /** * Sets the compiler options to 10 for the given project. - * + * * @param project the java project * @since 3.14 */ @@ -227,10 +227,10 @@ public class JavaProjectHelper { set10CompilerOptions(options); project.setOptions(options); } - + /** * Sets the compiler options to 12 for the given project. - * + * * @param project the java project * @param enable_preview_feature sets enable-preview compliance project option based on the value specified. * @since 3.18 @@ -241,13 +241,13 @@ public class JavaProjectHelper { if (enable_preview_feature) { options.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); options.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE); - } + } project.setOptions(options); } - + /** * Sets the compiler options to 13 for the given project. - * + * * @param project the java project * @param enable_preview_feature sets enable-preview compliance project option based on the value specified. * @since 3.19 @@ -258,7 +258,7 @@ public class JavaProjectHelper { if (enable_preview_feature) { options.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); options.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE); - } + } project.setOptions(options); } @@ -282,7 +282,7 @@ public class JavaProjectHelper { /** * Sets the compiler options to 1.8 for the given project. - * + * * @param project the java project * @since 3.10 */ @@ -301,7 +301,7 @@ public class JavaProjectHelper { JavaProjectHelper.set17CompilerOptions(options); project.setOptions(options); } - + /** * Sets the compiler options to 1.6 for the given project. * @param project the java project @@ -311,7 +311,7 @@ public class JavaProjectHelper { JavaProjectHelper.set16CompilerOptions(options); project.setOptions(options); } - + /** * Sets the compiler options to 1.5 for the given project. * @param project the java project @@ -335,7 +335,7 @@ public class JavaProjectHelper { /** * Sets the compiler options to 9. - * + * * @param options the compiler options to configure */ public static void set9CompilerOptions(Map<String, String> options) { @@ -344,25 +344,25 @@ public class JavaProjectHelper { /** * Sets the compiler options to 10. - * + * * @param options the compiler options to configure */ public static void set10CompilerOptions(Map<String, String> options) { JavaCore.setComplianceOptions(JavaCore.VERSION_10, options); } - + /** * Sets the compiler options to 12. - * + * * @param options the compiler options to configure */ public static void set12CompilerOptions(Map<String, String> options) { JavaCore.setComplianceOptions(JavaCore.VERSION_12, options); } - + /** * Sets the compiler options to 13. - * + * * @param options the compiler options to configure */ public static void set13_CompilerOptions(Map<String, String> options) { @@ -380,7 +380,7 @@ public class JavaProjectHelper { /** * Sets the compiler options to 1.8 - * + * * @param options the compiler options to configure * @since 3.10 */ @@ -395,7 +395,7 @@ public class JavaProjectHelper { public static void set17CompilerOptions(Map<String, String> options) { JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options); } - + /** * Sets the compiler options to 1.6 * @param options The compiler options to configure @@ -458,7 +458,7 @@ public class JavaProjectHelper { /** * Removes a resource. Retries if deletion failed (e.g. because the indexer * still locks the file). - * + * * @param resource the resource to delete * @throws CoreException if operation failed */ @@ -480,11 +480,11 @@ public class JavaProjectHelper { } } } - + /** * Removes a package fragment. Retries if deletion failed (e.g. because the indexer * still locks a file). - * + * * @param pack the package to delete * @throws CoreException if operation failed */ @@ -540,7 +540,7 @@ public class JavaProjectHelper { public static void mustPerformDummySearch(IJavaElement element) throws JavaModelException { performDummySearch(SearchEngine.createJavaSearchScope(new IJavaElement[] { element }), true); } - + public static void performDummySearch() throws JavaModelException { performDummySearch(SearchEngine.createWorkspaceScope(), PERFORM_DUMMY_SEARCH > 0); } @@ -554,18 +554,18 @@ public class JavaProjectHelper { * Workaround for intermittent test failures. The problem is that the Java indexer * may still be reading a file that has just been created, but a test already tries to delete * the file again. - * + * * This can theoretically also happen in real life, but it's expected to be very rare, * and there's no good solution for the problem, since the Java indexer should not * take a workspace lock for these files. - * + * * performDummySearch() was found to be a performance bottleneck, so we've disabled it in most situations. * Use a mustPerformDummySearch() method if you really need it and you can't * use a delete(..) method that retries a few times before failing. */ if (!doIt) return; - + new SearchEngine().searchAllTypeNames( null, SearchPattern.R_EXACT_MATCH, @@ -883,13 +883,13 @@ public class JavaProjectHelper { set12CompilerOptions(jproject, enable_preview_feature); return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]); } - + public static IPackageFragmentRoot addRTJar_13(IJavaProject jproject, boolean enable_preview_feature) throws CoreException { IPath[] rtJarPath= findRtJar(RT_STUBS13); set13CompilerOptions(jproject, enable_preview_feature); return addLibrary(jproject, rtJarPath[0], rtJarPath[1], rtJarPath[2]); } - + /** * Adds a variable entry with source attachment to a IJavaProject. * Can return null if variable can not be resolved. diff --git a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/MixedLineDelimiterDetector.java b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/MixedLineDelimiterDetector.java index 3a0d223038..34e1e61476 100644 --- a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/MixedLineDelimiterDetector.java +++ b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/MixedLineDelimiterDetector.java @@ -174,7 +174,7 @@ public class MixedLineDelimiterDetector { /** * Finds files with mixed line delimiters. - * + * * @param resource the resource to search * @return the resources with mixed line delimiters */ diff --git a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/NullTestUtils.java b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/NullTestUtils.java index 5ef4c8f345..8b0a1a7b78 100644 --- a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/NullTestUtils.java +++ b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/NullTestUtils.java @@ -32,7 +32,7 @@ public class NullTestUtils { options.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annots.Nullable"); options.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annots.NonNullByDefault"); sourceFolder.getJavaProject().setOptions(options); - + IPackageFragment pack0= sourceFolder.createPackageFragment("annots", false, null); StringBuffer buf= new StringBuffer(); buf.append("package annots;\n"); @@ -40,14 +40,14 @@ public class NullTestUtils { buf.append("@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)\n"); buf.append("public @interface NonNull {}\n"); pack0.createCompilationUnit("NonNull.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package annots;\n"); buf.append("\n"); buf.append("@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)\n"); buf.append("public @interface Nullable {}\n"); pack0.createCompilationUnit("Nullable.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package annots;\n"); buf.append("\n"); @@ -55,7 +55,7 @@ public class NullTestUtils { buf.append("@Target({ ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR })\n"); buf.append("@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)\n"); buf.append("public @interface NonNullByDefault { boolean value() default true; }\n"); - pack0.createCompilationUnit("NonNullByDefault.java", buf.toString(), false, null); + pack0.createCompilationUnit("NonNullByDefault.java", buf.toString(), false, null); } // note: use disableAnnotationBasedNullAnalysis, if the project is reused between test cases @@ -67,7 +67,7 @@ public class NullTestUtils { options.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annots.Nullable"); options.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annots.NonNullByDefault"); project.setOptions(options); - + IPackageFragment pack0= sourceFolder.createPackageFragment("annots", false, null); StringBuffer buf= new StringBuffer(); buf.append("package annots;\n"); @@ -78,7 +78,7 @@ public class NullTestUtils { buf.append("@Target({ ElementType.TYPE_USE })\n"); buf.append("public @interface NonNull {}\n"); pack0.createCompilationUnit("NonNull.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package annots;\n"); buf.append("\n"); @@ -88,13 +88,13 @@ public class NullTestUtils { buf.append("@Target({ ElementType.TYPE_USE })\n"); buf.append("public @interface Nullable {}\n"); pack0.createCompilationUnit("Nullable.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package annots;\n"); buf.append("\n"); buf.append("public enum DefaultLocation { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS, TYPE_PARAMETER }\n"); pack0.createCompilationUnit("DefaultLocation.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package annots;\n"); buf.append("\n"); @@ -106,7 +106,7 @@ public class NullTestUtils { buf.append("public @interface NonNullByDefault { DefaultLocation[] value() default {PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT}; }\n"); pack0.createCompilationUnit("NonNullByDefault.java", buf.toString(), false, null); } - + // for test classes where the project is not deleted for each test case public static void disableAnnotationBasedNullAnalysis(IPackageFragmentRoot sourceFolder) { IJavaProject project= sourceFolder.getJavaProject(); diff --git a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/test/JavaTestCase.java b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/test/JavaTestCase.java index 536165e3b4..aaeedfd50d 100644 --- a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/test/JavaTestCase.java +++ b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/test/JavaTestCase.java @@ -45,7 +45,7 @@ public class JavaTestCase extends TestCase { /** * Creates a new test Java project. - * + * * @throws Exception in case of any problem */ @Override @@ -63,7 +63,7 @@ public class JavaTestCase extends TestCase { /** * Removes the test java project. - * + * * @throws Exception in case of any problem */ @Override diff --git a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/CreateStubsAction.java b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/CreateStubsAction.java index 77712fe7a6..094e835a42 100644 --- a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/CreateStubsAction.java +++ b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/CreateStubsAction.java @@ -134,7 +134,7 @@ public final class CreateStubsAction implements IObjectActionDelegate { final IStructuredSelection structuredSelection= (IStructuredSelection) selection; Shell shell= fTargetPart.getSite().getShell(); - String initialValue= JavaTestPlugin.getDefault().getDialogSettings().get(SETTINGS_ID_STUBS_PROJECT); + String initialValue= JavaTestPlugin.getDefault().getDialogSettings().get(SETTINGS_ID_STUBS_PROJECT); if (initialValue == null) initialValue = "stubs"; //$NON-NLS-1$ final InputDialog inputDialog= new InputDialog(shell, CREATE_STUBS_DIALOG_TITLE, "Target project name:", initialValue, new IInputValidator() { //$NON-NLS-1$ @@ -149,11 +149,11 @@ public final class CreateStubsAction implements IObjectActionDelegate { try { final String name= inputDialog.getValue(); - JavaTestPlugin.getDefault().getDialogSettings().put(SETTINGS_ID_STUBS_PROJECT, name); + JavaTestPlugin.getDefault().getDialogSettings().put(SETTINGS_ID_STUBS_PROJECT, name); long start= System.currentTimeMillis(); ArrayList<String> defaultPackages= new ArrayList<>(Arrays.asList(DEFAULT_PACKAGES)); - + ProgressMonitorDialog progressMonitorDialog= new ProgressMonitorDialog(shell); progressMonitorDialog.run(true, true, new IRunnableWithProgress() { @@ -163,7 +163,7 @@ public final class CreateStubsAction implements IObjectActionDelegate { createJavaProject(name); IFolder target = ResourcesPlugin.getWorkspace().getRoot().getProject(inputDialog.getValue()).getFolder("src"); //$NON-NLS-1$ List<IPackageFragment> packageFragments= new ArrayList<>(); - + boolean checkCompletionOfDefaultPackages= false; for (Object sel : structuredSelection.toList()) { if (sel instanceof IPackageFragment) { @@ -198,7 +198,7 @@ public final class CreateStubsAction implements IObjectActionDelegate { if (!defaultPackages.isEmpty() ) { message+= "\n\nNo stubs generated for packages: " + defaultPackages.toString(); } - MessageDialog.openInformation(fTargetPart.getSite().getShell(), CREATE_STUBS_DIALOG_TITLE, message); + MessageDialog.openInformation(fTargetPart.getSite().getShell(), CREATE_STUBS_DIALOG_TITLE, message); } catch (InterruptedException e) { // Do not log } catch (InvocationTargetException e) { diff --git a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/DisplayHelper.java b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/DisplayHelper.java index f64ad7f23f..a717a9637b 100644 --- a/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/DisplayHelper.java +++ b/org.eclipse.jdt.ui.tests/test plugin/org/eclipse/jdt/testplugin/util/DisplayHelper.java @@ -120,7 +120,7 @@ public abstract class DisplayHelper { /** * The condition which has to be met in order for {@link #waitForCondition(Display, long)} to * return before the timeout elapses. - * + * * @return <code>true</code> if the condition is met, <code>false</code> if the event loop * should be driven some more */ diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/AbstractTestRunListenerTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/AbstractTestRunListenerTest.java index 0a86a036f2..117abd16cd 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/AbstractTestRunListenerTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/AbstractTestRunListenerTest.java @@ -117,7 +117,7 @@ public class AbstractTestRunListenerTest extends TestCase { protected void launchJUnit(IJavaElement aTest, String testKindID) throws CoreException { launchJUnit(aTest, testKindID, (String)null); } - + protected void launchJUnit(IJavaElement aTest, String testKindID, String testName) throws CoreException { ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); IMarker[] markers= aTest.getJavaProject().getProject().findMarkers(null, true, IResource.DEPTH_INFINITE); @@ -201,11 +201,11 @@ public class AbstractTestRunListenerTest extends TestCase { protected String[] launchJUnit(IJavaElement aTest, final TestRunLog log) throws CoreException { return launchJUnit(aTest, null, log); } - + protected String[] launchJUnit(IJavaElement aTest, String testKindID, final TestRunLog log) throws CoreException { return launchJUnit(aTest, testKindID, null, log); } - + protected String[] launchJUnit(IJavaElement aTest, String testKindID, String testName, final TestRunLog log) throws CoreException { launchJUnit(aTest, testKindID, testName); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/AbstractTestRunSessionSerializationTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/AbstractTestRunSessionSerializationTests.java index 81302d8c8e..d9a9084de4 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/AbstractTestRunSessionSerializationTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/AbstractTestRunSessionSerializationTests.java @@ -122,7 +122,7 @@ public class AbstractTestRunSessionSerializationTests extends TestCase { private void assertEqualXML(String expected, String actual) { /* - * Strips and + * Strips and */ String regex0= "[03];"; /* diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/JUnit4TestFinderTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/JUnit4TestFinderTest.java index 3f44661948..fd23f3bc63 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/JUnit4TestFinderTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/JUnit4TestFinderTest.java @@ -327,17 +327,17 @@ public class JUnit4TestFinderTest extends TestCase { File lib= JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/stacktest.jar")); JavaProjectHelper.addLibrary(fProject, Path.fromOSString(lib.getPath())); - + assertTestFound(validTest4, new String[] { "Test7"}); assertTestFound(validTest4.getCompilationUnit(), new String[] { "Test7" }); - + String[] validTestsP= { "p.Test1", "p.Test2", "p.Test3", "p.Test5"}; assertTestFound(p, validTestsP); - + String[] validTests= new String[validTestsP.length + 1]; System.arraycopy(validTestsP, 0, validTests, 0, validTestsP.length); validTests[validTestsP.length]= "Test7"; - + assertTestFound(fRoot, validTests); assertTestFound(fProject, validTests); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/JUnitJUnitTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/JUnitJUnitTests.java index e97ea4b296..7c66675c00 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/JUnitJUnitTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/JUnitJUnitTests.java @@ -36,7 +36,7 @@ public class JUnitJUnitTests { suite.addTestSuite(TestRunListenerTest3.class); suite.addTestSuite(TestRunListenerTest4.class); suite.addTestSuite(TestRunListenerTest5.class); - + suite.addTestSuite(TestRunFilteredStandardRunnerTest4.class); suite.addTestSuite(TestRunFilteredParameterizedRunnerTest4.class); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestEnableAssertions.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestEnableAssertions.java index 2f54c74b96..1a956a014f 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestEnableAssertions.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestEnableAssertions.java @@ -69,11 +69,11 @@ public class TestEnableAssertions extends TestCase { ISelectionProvider selectionProvider= activePart.getSite().getSelectionProvider(); if (selectionProvider != null) { // make sure there's no active selection, otherwise JUnitLaunchConfigurationTab#setDefaults(ILaunchConfigurationWorkingCopy) - // can fail because it tries to initialize attributes on a selection + // can fail because it tries to initialize attributes on a selection selectionProvider.setSelection(new StructuredSelection()); } } - + JUnitTabGroup testSubject= new JUnitTabGroup(); tabGroupSetDefaultTester(testSubject); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunFilteredParameterizedRunnerTest4.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunFilteredParameterizedRunnerTest4.java index c2f6f16da2..6b391964d8 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunFilteredParameterizedRunnerTest4.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunFilteredParameterizedRunnerTest4.java @@ -39,7 +39,7 @@ public class TestRunFilteredParameterizedRunnerTest4 extends AbstractTestRunList JUnitCore.removeTestRunListener(testRunListener); } } - + @Override protected void setUp() throws Exception { fProject= JavaProjectHelper.createJavaProject("TestRunListenerTest", "bin"); @@ -95,7 +95,7 @@ public class TestRunFilteredParameterizedRunnerTest4 extends AbstractTestRunList String[] actual= runTreeTest(fATestCase, "pack.ATestCase", 10); assertEqualLog(expectedSequence, actual); } - + public void testMatchSubtree1ByName() throws Exception { String[] expectedSequence= new String[] { TestRunListeners.sessionAsString("ATestCase [0]", ProgressState.COMPLETED, Result.OK, 0), @@ -106,7 +106,7 @@ public class TestRunFilteredParameterizedRunnerTest4 extends AbstractTestRunList String[] actual= runTreeTest(fATestCase, "[0]", 6); assertEqualLog(expectedSequence, actual); } - + public void testMatchSubtree1Leaf1ByName() throws Exception { String[] expectedSequence= new String[] { TestRunListeners.sessionAsString("ATestCase testDiv[0]", ProgressState.COMPLETED, Result.OK, 0), @@ -115,7 +115,7 @@ public class TestRunFilteredParameterizedRunnerTest4 extends AbstractTestRunList String[] actual= runTreeTest(fATestCase, "testDiv[0]", 4); assertEqualLog(expectedSequence, actual); } - + public void testMatchSubtree1Leaf1ByNameAndClass() throws Exception { String[] expectedSequence= new String[] { TestRunListeners.sessionAsString("ATestCase testDiv[0]", ProgressState.COMPLETED, Result.OK, 0), @@ -124,7 +124,7 @@ public class TestRunFilteredParameterizedRunnerTest4 extends AbstractTestRunList String[] actual2= runTreeTest(fATestCase, "testDiv[0](pack.ATestCase)", 4); assertEqualLog(expectedSequence, actual2); } - + public void testMatchSubtree1Leaf2ByName() throws Exception { String[] expectedSequence= new String[] { TestRunListeners.sessionAsString("ATestCase testDiv[1]", ProgressState.COMPLETED, Result.OK, 0), @@ -133,7 +133,7 @@ public class TestRunFilteredParameterizedRunnerTest4 extends AbstractTestRunList String[] actual= runTreeTest(fATestCase, "testDiv[1]", 4); assertEqualLog(expectedSequence, actual); } - + public void testMatchSubtree2ByName() throws Exception { String[] expectedSequence= new String[] { TestRunListeners.sessionAsString("ATestCase [1]", ProgressState.COMPLETED, Result.OK, 0), @@ -144,7 +144,7 @@ public class TestRunFilteredParameterizedRunnerTest4 extends AbstractTestRunList String[] actual= runTreeTest(fATestCase, "[1]", 6); assertEqualLog(expectedSequence, actual); } - + public void testMatchAllFirstLeafs() throws Exception { String[] expectedSequence= new String[] { TestRunListeners.sessionAsString("ATestCase testDiv", ProgressState.COMPLETED, Result.OK, 0), @@ -157,5 +157,5 @@ public class TestRunFilteredParameterizedRunnerTest4 extends AbstractTestRunList String[] actual= runTreeTest(fATestCase, "testDiv", 6); assertEqualLog(expectedSequence, actual); } - + } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunFilteredStandardRunnerTest4.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunFilteredStandardRunnerTest4.java index cfb33b7dcf..6095b92dd9 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunFilteredStandardRunnerTest4.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunFilteredStandardRunnerTest4.java @@ -40,7 +40,7 @@ public class TestRunFilteredStandardRunnerTest4 extends AbstractTestRunListenerT JUnitCore.removeTestRunListener(testRunListener); } } - + @Override protected void setUp() throws Exception { fProject= JavaProjectHelper.createJavaProject("TestRunListenerTest", "bin"); @@ -69,7 +69,7 @@ public class TestRunFilteredStandardRunnerTest4 extends AbstractTestRunListenerT String[] actual= runTreeTest(fATestCase, "test1Succeed", 4); assertEqualLog(expectedSequence, actual); } - + public void testFilterToTest2Fail() throws Exception { String[] expectedSequence= new String[] { TestRunListeners.sessionAsString("ATestCase test2Fail", ProgressState.COMPLETED, Result.FAILURE, 0), @@ -78,7 +78,7 @@ public class TestRunFilteredStandardRunnerTest4 extends AbstractTestRunListenerT String[] actual= runTreeTest(fATestCase, "test2Fail", 4); assertEqualLog(expectedSequence, actual); } - + public void testFilterToNoTestsRemain() throws Exception { String[] expectedSequence= new String[] { TestRunListeners.sessionAsString("ATestCase thisdoesnotexist", ProgressState.COMPLETED, Result.ERROR, 0), @@ -88,5 +88,5 @@ public class TestRunFilteredStandardRunnerTest4 extends AbstractTestRunListenerT assertEqualLog(expectedSequence, actual); } - + } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest3.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest3.java index ce889a24b0..26ab4d99c1 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest3.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest3.java @@ -291,59 +291,59 @@ public class TestRunListenerTest3 extends AbstractTestRunListenerTest { String[] actual= runTreeTest(aTestCase, 6); assertEqualLog(expectedTree, actual); } - + public void testTreeJUnit4TestAdapter() throws Exception { // regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=397747 IClasspathEntry cpe= JavaCore.newContainerEntry(JUnitCore.JUNIT4_CONTAINER_PATH); JavaProjectHelper.clear(fProject, new IClasspathEntry[] { cpe }); JavaProjectHelper.addRTJar15(fProject); - + String source= - "package test;\n" + - "\n" + - "import junit.framework.JUnit4TestAdapter;\n" + - "import junit.framework.TestCase;\n" + - "import junit.framework.TestSuite;\n" + - "\n" + - "import org.junit.Test;\n" + - "import org.junit.runner.RunWith;\n" + - "import org.junit.runners.Suite;\n" + - "import org.junit.runners.Suite.SuiteClasses;\n" + - "\n" + - "public class MyTestSuite {\n" + - " public static junit.framework.Test suite() {\n" + - " TestSuite suite = new TestSuite();\n" + - " suite.addTest(new JUnit4TestAdapter(JUnit4TestSuite.class));\n" + - " suite.addTestSuite(JUnit3TestCase.class);\n" + - " return suite;\n" + - " }\n" + - " \n" + - " @RunWith(Suite.class)\n" + - " @SuiteClasses({JUnit4TestCase.class})\n" + - " public static class JUnit4TestSuite {}\n" + - " \n" + - " public static class JUnit4TestCase {\n" + - " @Test public void testA() {}\n" + - " @Test public void testB() {}\n" + - " }\n" + - " \n" + - " public static class JUnit3TestCase extends TestCase {\n" + - " public void testC() {}\n" + - " public void testD() {}\n" + - " public void testE() {}\n" + - " }\n" + + "package test;\n" + + "\n" + + "import junit.framework.JUnit4TestAdapter;\n" + + "import junit.framework.TestCase;\n" + + "import junit.framework.TestSuite;\n" + + "\n" + + "import org.junit.Test;\n" + + "import org.junit.runner.RunWith;\n" + + "import org.junit.runners.Suite;\n" + + "import org.junit.runners.Suite.SuiteClasses;\n" + + "\n" + + "public class MyTestSuite {\n" + + " public static junit.framework.Test suite() {\n" + + " TestSuite suite = new TestSuite();\n" + + " suite.addTest(new JUnit4TestAdapter(JUnit4TestSuite.class));\n" + + " suite.addTestSuite(JUnit3TestCase.class);\n" + + " return suite;\n" + + " }\n" + + " \n" + + " @RunWith(Suite.class)\n" + + " @SuiteClasses({JUnit4TestCase.class})\n" + + " public static class JUnit4TestSuite {}\n" + + " \n" + + " public static class JUnit4TestCase {\n" + + " @Test public void testA() {}\n" + + " @Test public void testB() {}\n" + + " }\n" + + " \n" + + " public static class JUnit3TestCase extends TestCase {\n" + + " public void testC() {}\n" + + " public void testD() {}\n" + + " public void testE() {}\n" + + " }\n" + "}\n"; IType aTestCase= createType(source, "test", "MyTestSuite.java"); - + String[] expectedTree= new String[] { TestRunListeners.sessionAsString("MyTestSuite", ProgressState.COMPLETED, Result.OK, 0), TestRunListeners.suiteAsString("junit.framework.TestSuite", ProgressState.COMPLETED, Result.OK, null, 1), - + TestRunListeners.suiteAsString("test.MyTestSuite.JUnit4TestSuite", ProgressState.COMPLETED, Result.OK, null, 2), TestRunListeners.suiteAsString("test.MyTestSuite.JUnit4TestCase", ProgressState.COMPLETED, Result.OK, null, 3), TestRunListeners.testCaseAsString("testA", "test.MyTestSuite.JUnit4TestCase", ProgressState.COMPLETED, Result.OK, null, 4), TestRunListeners.testCaseAsString("testB", "test.MyTestSuite.JUnit4TestCase", ProgressState.COMPLETED, Result.OK, null, 4), - + TestRunListeners.suiteAsString("test.MyTestSuite.JUnit3TestCase", ProgressState.COMPLETED, Result.OK, null, 2), TestRunListeners.testCaseAsString("testC", "test.MyTestSuite.JUnit3TestCase", ProgressState.COMPLETED, Result.OK, null, 3), TestRunListeners.testCaseAsString("testD", "test.MyTestSuite.JUnit3TestCase", ProgressState.COMPLETED, Result.OK, null, 3), diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest4.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest4.java index 9614e85a77..babb4d9c5f 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest4.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest4.java @@ -49,7 +49,7 @@ public class TestRunListenerTest4 extends AbstractTestRunListenerTest { JUnitCore.removeTestRunListener(testRunListener); } } - + @Override protected void setUp() throws Exception { fProject= JavaProjectHelper.createJavaProject("TestRunListenerTest", "bin"); @@ -75,7 +75,7 @@ public class TestRunListenerTest4 extends AbstractTestRunListenerTest { String[] actual= runSequenceTest(aTestCase); assertEqualLog(expectedSequence, actual); } - + public void testTreeOK() throws Exception { String source= "package pack;\n"+ @@ -106,7 +106,7 @@ public class TestRunListenerTest4 extends AbstractTestRunListenerTest { " }\n"+ "}\n"; IType aTestCase= createType(source, "pack", "ATestCase.java"); - + String[] expectedSequence= new String[] { TestRunListeners.sessionAsString("ATestCase", ProgressState.COMPLETED, Result.OK, 0), TestRunListeners.suiteAsString("pack.ATestCase", ProgressState.COMPLETED, Result.OK, null, 1), diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest5.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest5.java index 512e337799..8ab118a825 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest5.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunListenerTest5.java @@ -50,7 +50,7 @@ public class TestRunListenerTest5 extends AbstractTestRunListenerTest { JUnitCore.removeTestRunListener(testRunListener); } } - + @Override protected void setUp() throws Exception { fProject= JavaProjectHelper.createJavaProject("TestRunListenerTest", "bin"); @@ -76,7 +76,7 @@ public class TestRunListenerTest5 extends AbstractTestRunListenerTest { String[] actual= runSequenceTest(aTestCase); assertEqualLog(expectedSequence, actual); } - + public void testFail() throws Exception { String source= "package pack;\n" + diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunSessionSerializationTests4.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunSessionSerializationTests4.java index ce25866bef..eb5d6b4f67 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunSessionSerializationTests4.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/tests/TestRunSessionSerializationTests4.java @@ -76,7 +76,7 @@ public class TestRunSessionSerializationTests4 extends AbstractTestRunSessionSer public void testFailures() throws Exception { String test= "Failures"; - + TestRunLog log= new TestRunLog(); final TestRunListener testRunListener= new TestRunListeners.SequenceTest(log); JUnitCore.addTestRunListener(testRunListener); @@ -87,25 +87,25 @@ public class TestRunSessionSerializationTests4 extends AbstractTestRunSessionSer "testCaseStarted-" + TestRunListeners.testCaseAsString("testNasty", "pack.Failures", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("testNasty", "pack.Failures", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("java.lang.AssertionError", null, null), 0), - + "testCaseStarted-" + TestRunListeners.testCaseAsString("ignored", "pack.Failures", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("ignored", "pack.Failures", ProgressState.COMPLETED, Result.IGNORED, null, 0), - + "testCaseStarted-" + TestRunListeners.testCaseAsString("testError", "pack.Failures", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("testError", "pack.Failures", ProgressState.COMPLETED, Result.ERROR, new FailureTrace("java.lang.IllegalStateException", null, null), 0), - + "testCaseStarted-" + TestRunListeners.testCaseAsString("errorExpected", "pack.Failures", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("errorExpected", "pack.Failures", ProgressState.COMPLETED, Result.OK, null, 0), - + "testCaseStarted-" + TestRunListeners.testCaseAsString("errorExpectedOther", "pack.Failures", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("errorExpectedOther", "pack.Failures", ProgressState.COMPLETED, Result.ERROR, new FailureTrace("java.lang.Exception", null, null), 0), - + "testCaseStarted-" + TestRunListeners.testCaseAsString("compareTheStuff", "pack.Failures", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("compareTheStuff", "pack.Failures", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("org.junit.ComparisonFailure", "\nHello World.\n\n", "\n\nHello my friend."), 0), - + "testCaseStarted-" + TestRunListeners.testCaseAsString("testCompareNull", "pack.Failures", ProgressState.RUNNING, Result.UNDEFINED, null, 0), "testCaseFinished-" + TestRunListeners.testCaseAsString("testCompareNull", "pack.Failures", ProgressState.COMPLETED, Result.FAILURE, new FailureTrace("java.lang.AssertionError", null, null), 0), - + "sessionFinished-" + TestRunListeners.sessionAsString("Failures", ProgressState.COMPLETED, Result.ERROR, 0) }; String[] actual= log.getLog(); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/LeakTestSuite.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/LeakTestSuite.java index 14fa2987b9..11b8551992 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/LeakTestSuite.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/LeakTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,8 +13,8 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; import org.eclipse.jdt.ui.tests.leaks.JavaLeakTest; import org.eclipse.jdt.ui.tests.leaks.TextViewerUndoManagerLeakTest; @@ -25,25 +25,13 @@ import org.eclipse.jdt.ui.tests.search.SearchLeakTestWrapper; /** * Test for leaks */ -public class LeakTestSuite extends TestSuite { - - /** - * Returns the suite. This is required to - * use the JUnit Launcher. - * - * @return the test suite. - */ - public static Test suite() { - return new LeakTestSuite(); - } - - public LeakTestSuite() { - super(LeakTestSuite.class.getName()); - addTest(JavaLeakTest.suite()); - addTest(SearchLeakTestWrapper.suite()); - addTest(UndoManagerLeakTest.suite()); - addTest(TextViewerUndoManagerLeakTest.suite()); - } - +@RunWith(Suite.class) +@Suite.SuiteClasses({ + JavaLeakTest.class, + SearchLeakTestWrapper.class, + UndoManagerLeakTest.class, + TextViewerUndoManagerLeakTest.class, +}) +public class LeakTestSuite { } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/browsing/PackagesViewDeltaTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/browsing/PackagesViewDeltaTests.java index 1aff527401..08d3db19f7 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/browsing/PackagesViewDeltaTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/browsing/PackagesViewDeltaTests.java @@ -567,7 +567,7 @@ public class PackagesViewDeltaTests extends TestCase { /** * Method compareArrays. Both arrays must be of IPackageFragments or compare will fail. - * + * * @param children the children * @param expectedChildren the expected children * @return boolean returns true if the arrays contain the same elements diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/BuildpathProblemQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/BuildpathProblemQuickFixTest.java index bf3270d963..f4b6281573 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/BuildpathProblemQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/BuildpathProblemQuickFixTest.java @@ -171,7 +171,7 @@ public class BuildpathProblemQuickFixTest extends TestCase { fJavaProject1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); IMarker[] markers= fJavaProject1.getResource().findMarkers("org.eclipse.jdt.core.buildpath_problem", true, IResource.DEPTH_INFINITE); - assertEquals("One or more cycles were detected in the build path of project '2_CyclicA'. The paths towards the cycle and cycle are:\n" + + assertEquals("One or more cycles were detected in the build path of project '2_CyclicA'. The paths towards the cycle and cycle are:\n" + "->{2_CyclicA, 2_CyclicB}", (String) markers[0].getAttribute(IMarker.MESSAGE)); assertEquals(1, markers.length); IMarkerResolution[] resolutions= sortResolutions(IDE.getMarkerHelpRegistry().getResolutions(markers[0])); @@ -189,7 +189,7 @@ public class BuildpathProblemQuickFixTest extends TestCase { if (vm instanceof IVMInstall2) { String version= ((IVMInstall2) vm).getJavaVersion(); if (version == null || !version.startsWith(JavaCore.VERSION_1_7)) { - // higher version instead of JavaSE 1.7 not found: + // higher version instead of JavaSE 1.7 not found: // skip test as error against vm's class files would be reported return; } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/CPUserLibraryTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/CPUserLibraryTest.java index 9c992c54fe..fe4da87e19 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/CPUserLibraryTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/buildpath/CPUserLibraryTest.java @@ -46,7 +46,7 @@ public class CPUserLibraryTest extends TestCase { return super.getSortedChildren(parentElementOrTreePath); } } - /** Install our own {@link MyTreeViewer}. + /** Install our own {@link MyTreeViewer}. * @param <E> the type of the root elements. */ static class MyTreeListDialogField<E> extends TreeListDialogField<E> { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java index de06cf7567..ea1e67d641 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AbstractBindingLabelsTest.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * Stephan Herrmann - Contribution for Bug 403917 - [1.8] Render TYPE_USE annotations in Javadoc hover/view *******************************************************************************/ @@ -116,7 +116,7 @@ public abstract class AbstractBindingLabelsTest extends CoreTests { labelPos= end; } - + if (close != -1) { // matching a link "<a class='header' href='eclipse-javadoc:IGNORE' title='LINK_TITLE'>LINK_TEXT</a>" assertTrue("link found ("+fragmentCount+")", label.substring(labelPos).startsWith( "<a class='header' href='eclipse-javadoc:")); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AddImportTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AddImportTest.java index 3f4d6738a1..9d213a5b99 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AddImportTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/AddImportTest.java @@ -272,7 +272,7 @@ public class AddImportTest extends CoreTests { public void testRemoveImports3() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack= sourceFolder.createPackageFragment("pack", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack;\n"); @@ -282,7 +282,7 @@ public class AddImportTest extends CoreTests { buf.append(" }\n"); buf.append("}\n"); pack.createCompilationUnit("A.java", buf.toString(), false, null); - + IPackageFragment test1= sourceFolder.createPackageFragment("test1", false, null); buf= new StringBuffer(); buf.append("package test1;\n"); @@ -297,22 +297,22 @@ public class AddImportTest extends CoreTests { buf.append("public class T {\n"); buf.append("}\n"); ICompilationUnit cuT= test1.createCompilationUnit("T.java", buf.toString(), false, null); - + ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); parser.setSource(cuT); parser.setResolveBindings(true); CompilationUnit astRoot= (CompilationUnit) parser.createAST(null); - + ImportRewrite imports= newImportsRewrite(astRoot, new String[0], 99, 99, true); imports.setUseContextToFilterImplicitImports(true); - + imports.removeImport("pack.A.Inner"); imports.removeImport("pack.A.NotThere"); imports.removeImport("pack.B.Inner"); imports.removeImport("pack.B.NotThere"); - + apply(imports); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -323,8 +323,8 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); assertEqualString(cuT.getSource(), buf.toString()); } - - + + public void testAddImports_bug23078() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -940,7 +940,7 @@ public class AddImportTest extends CoreTests { public void testAddImportAction5() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -957,12 +957,12 @@ public class AddImportTest extends CoreTests { buf.append(" Serializable s;\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("ser=") - 2; - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -979,113 +979,113 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); assertEqualString(cu.getSource(), buf.toString()); } - + public void testAddImportActionBug_409594_test1() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("p", false, null); String input = - "package p;\n" + - "\n" + - "class A {\n" + - " static void foo() {\n" + - " A.bar();\n" + - " }\n" + - "\n" + - " private static void bar() {\n" + - " }\n" + + "package p;\n" + + "\n" + + "class A {\n" + + " static void foo() {\n" + + " A.bar();\n" + + " }\n" + + "\n" + + " private static void bar() {\n" + + " }\n" + "}"; ICompilationUnit cu= pack1.createCompilationUnit("A.java", input, false, null); - + int selOffset= input.indexOf("bar"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 3, null, true); op.run(null); - - String expected = - "package p;\n" + - "\n" + - "class A {\n" + - " static void foo() {\n" + - " bar();\n" + - " }\n" + - "\n" + - " private static void bar() {\n" + - " }\n" + + + String expected = + "package p;\n" + + "\n" + + "class A {\n" + + " static void foo() {\n" + + " bar();\n" + + " }\n" + + "\n" + + " private static void bar() {\n" + + " }\n" + "}"; assertEqualString(cu.getSource(), expected); } - + public void testAddImportActionBug_409594_test2() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("p", false, null); String input = - "package p;\n" + - "\n" + - "class A {\n" + - " static void foo() {\n" + - " A.bar();\n" + - " }\n" + - "\n" + - " public static void bar() {\n" + - " }\n" + + "package p;\n" + + "\n" + + "class A {\n" + + " static void foo() {\n" + + " A.bar();\n" + + " }\n" + + "\n" + + " public static void bar() {\n" + + " }\n" + "}"; ICompilationUnit cu= pack1.createCompilationUnit("A.java", input, false, null); - + int selOffset= input.indexOf("bar"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 3, null, true); op.run(null); - - String expected = - "package p;\n" + - "\n" + - "class A {\n" + - " static void foo() {\n" + - " bar();\n" + - " }\n" + - "\n" + - " public static void bar() {\n" + - " }\n" + + + String expected = + "package p;\n" + + "\n" + + "class A {\n" + + " static void foo() {\n" + + " bar();\n" + + " }\n" + + "\n" + + " public static void bar() {\n" + + " }\n" + "}"; assertEqualString(cu.getSource(), expected); } - + public void testAddImportActionBug_409594_test3() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("p", false, null); String input = - "package p;\n" + - "class SnippetX {\n" + - " private static class Test {\n" + - " class X {\n" + - " void foo() {\n" + - " Test.bar();\n" + - " }\n" + - " }\n" + - " public static void bar() {}\n" + - " }\n" + + "package p;\n" + + "class SnippetX {\n" + + " private static class Test {\n" + + " class X {\n" + + " void foo() {\n" + + " Test.bar();\n" + + " }\n" + + " }\n" + + " public static void bar() {}\n" + + " }\n" + "}"; ICompilationUnit cu= pack1.createCompilationUnit("A.java", input, false, null); - + int selOffset= input.indexOf("bar"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 3, null, true); op.run(null); - - String expected = - "package p;\n" + - "class SnippetX {\n" + - " private static class Test {\n" + - " class X {\n" + - " void foo() {\n" + - " bar();\n" + - " }\n" + - " }\n" + - " public static void bar() {}\n" + - " }\n" + + + String expected = + "package p;\n" + + "class SnippetX {\n" + + " private static class Test {\n" + + " class X {\n" + + " void foo() {\n" + + " bar();\n" + + " }\n" + + " }\n" + + " public static void bar() {}\n" + + " }\n" + "}"; assertEqualString(cu.getSource(), expected); } @@ -1129,7 +1129,7 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); assertEqualString(cu.getSource(), buf.toString()); } - + public void testAddImportActionBug_409594_test5() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -1155,7 +1155,7 @@ public class AddImportTest extends CoreTests { assertEqualString(cu.getSource(), cu.getSource()); } - + public void testAddImportActionBug_409594_test6() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -1199,7 +1199,7 @@ public class AddImportTest extends CoreTests { ""; assertEqualString(cuB.getSource(), expected); } - + public void testAddImportAction_bug107206() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -1296,7 +1296,7 @@ public class AddImportTest extends CoreTests { public void testAddImportActionNestedType1() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1305,12 +1305,12 @@ public class AddImportTest extends CoreTests { buf.append(" java.lang.Thread.State s;\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("Thread"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -1319,10 +1319,10 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); assertEqualString(cu.getSource(), buf.toString()); } - + public void testAddImportActionNestedType2() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1331,12 +1331,12 @@ public class AddImportTest extends CoreTests { buf.append(" java.lang.Thread.State s;\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("State"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -1347,10 +1347,10 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); assertEqualString(cu.getSource(), buf.toString()); } - + public void testAddImportActionParameterizedType1() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1359,12 +1359,12 @@ public class AddImportTest extends CoreTests { buf.append(" java.util.Map<String, Integer> m;\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("Map"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -1378,7 +1378,7 @@ public class AddImportTest extends CoreTests { public void testAddImportActionParameterizedType2() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1387,12 +1387,12 @@ public class AddImportTest extends CoreTests { buf.append(" java.util.Map.Entry e;\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("Entry"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -1403,10 +1403,10 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); assertEqualString(cu.getSource(), buf.toString()); } - + public void testAddImportActionParameterizedType3() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1415,12 +1415,12 @@ public class AddImportTest extends CoreTests { buf.append(" java.util.Map.Entry<String, Object> e;\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("Map"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -1431,10 +1431,10 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); assertEqualString(cu.getSource(), buf.toString()); } - + public void testAddImportActionParameterizedType4() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1443,12 +1443,12 @@ public class AddImportTest extends CoreTests { buf.append(" java.util.Map.Entry<String, Object> e;\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("Entry"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -1459,10 +1459,10 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); assertEqualString(cu.getSource(), buf.toString()); } - + public void testAddImportActionParameterizedType5() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack2= sourceFolder.createPackageFragment("pack2", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack2;\n"); @@ -1474,7 +1474,7 @@ public class AddImportTest extends CoreTests { buf.append(" }\n"); buf.append("}\n"); pack2.createCompilationUnit("Outer.java", buf.toString(), false, null); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1483,12 +1483,12 @@ public class AddImportTest extends CoreTests { buf.append(" pack2.Outer.Middle<String>.Inner<Integer> i;\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("Middle"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -1503,7 +1503,7 @@ public class AddImportTest extends CoreTests { // Don't touch nested type if outer is parameterized. public void testAddImportActionParameterizedType6() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack2= sourceFolder.createPackageFragment("pack2", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack2;\n"); @@ -1515,7 +1515,7 @@ public class AddImportTest extends CoreTests { buf.append(" }\n"); buf.append("}\n"); pack2.createCompilationUnit("Outer.java", buf.toString(), false, null); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1524,12 +1524,12 @@ public class AddImportTest extends CoreTests { buf.append(" pack2.Outer.Middle<String>.Inner<Integer> i;\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("Inner"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -1541,7 +1541,7 @@ public class AddImportTest extends CoreTests { public void testAddImportActionAnnotatedType1() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1554,12 +1554,12 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); buf.append("@Target(ElementType.TYPE_USE) @interface A {}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("Format"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); @@ -1577,7 +1577,7 @@ public class AddImportTest extends CoreTests { // Don't touch nested type if outer is annotated. public void testAddImportActionAnnotatedType2() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack1;\n"); @@ -1590,12 +1590,12 @@ public class AddImportTest extends CoreTests { buf.append("}\n"); buf.append("@Target(ElementType.TYPE_USE) @interface A {}\n"); ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null); - + int selOffset= buf.indexOf("Field"); - + AddImportsOperation op= new AddImportsOperation(cu, selOffset, 0, null, true); op.run(null); - + buf= new StringBuffer(); buf.append("package pack1;\n"); buf.append("\n"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabels18Test.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabels18Test.java index 9935461ecf..f1d2c4cf5f 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabels18Test.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabels18Test.java @@ -84,26 +84,26 @@ public class BindingLabels18Test extends AbstractBindingLabelsTest { IMethod invokeExact= methodHandle.getMethod("invokeExact", new String[] { Signature.createArraySignature(Signature.createTypeSignature("java.lang.Object", true), 1) }); - + String lab= getBindingLabel(invokeExact, JavaElementLabels.ALL_DEFAULT); assertLinkMatch(lab, "invokeExact({{java.lang|Object}}...)"); - + lab= getBindingLabel(invokeExact, JavaElementLabels.M_PARAMETER_NAMES); assertEqualString(lab, "invokeExact(arg0)"); - + lab= getBindingLabel(invokeExact, JavaElementLabels.M_PARAMETER_TYPES); assertLinkMatch(lab, "invokeExact({{java.lang|Object}}...)"); - + lab= getBindingLabel(invokeExact, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES); assertLinkMatch(lab, "invokeExact({{java.lang|Object}}... arg0)"); - + lab= getBindingLabel(invokeExact, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "invokeExact({{java.lang|Object}}...)"); } private IJavaElement createInvokeReference(String invocation) throws CoreException, JavaModelException { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); @@ -115,7 +115,7 @@ public class BindingLabels18Test extends AbstractBindingLabelsTest { buf.append("}\n"); String content= buf.toString(); ICompilationUnit cu= pack1.createCompilationUnit("Test.java", content, false, null); - + IJavaElement elem= cu.codeSelect(content.indexOf("invoke("), 0)[0]; return elem; } @@ -123,107 +123,107 @@ public class BindingLabels18Test extends AbstractBindingLabelsTest { private void assertInvokeUnresolved(IJavaElement elem) { String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT); assertLinkMatch(lab, "invoke({{java.lang|Object}}...)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_NAMES); assertEqualString(lab, "invoke(arg0)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES); assertLinkMatch(lab, "invoke({{java.lang|Object}}...)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PRE_RETURNTYPE); assertLinkMatch(lab, "{{java.lang|Object}} invoke({{java.lang|Object}}... arg0)"); } public void testMethodLabelPolymorphicSignatureReference0() throws Exception { IJavaElement elem= createInvokeReference("mh.invoke()"); - + assertInvokeUnresolved(elem); - + String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke()"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke()"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "void invoke()"); } public void testMethodLabelPolymorphicSignatureReference0Ret() throws Exception { IJavaElement elem= createInvokeReference("String s= (String) mh.invoke()"); - + assertInvokeUnresolved(elem); - + String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke()"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke()"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "{{java.lang|Object}} invoke()"); } - + public void testMethodLabelPolymorphicSignatureReference1() throws Exception { IJavaElement elem= createInvokeReference("mh.invoke(1)"); - + assertInvokeUnresolved(elem); - + String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(int)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(int)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "void invoke(int arg00)"); } - + public void testMethodLabelPolymorphicSignatureReference1Array() throws Exception { IJavaElement elem= createInvokeReference("mh.invoke(new Object[42])"); - + assertInvokeUnresolved(elem); - + String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "invoke({{java.lang|Object}}[])"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "invoke({{java.lang|Object}}[])"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "void invoke({{java.lang|Object}}[] arg00)"); } - + public void testMethodLabelPolymorphicSignatureReference2() throws Exception { IJavaElement elem= createInvokeReference("mh.invoke('a', new Integer[0][])"); - + assertInvokeUnresolved(elem); - + String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "invoke(char, {{java.lang|Integer}}[][])"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "invoke(char, {{java.lang|Integer}}[][])"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "void invoke(char arg00, {{java.lang|Integer}}[][] arg01)"); } - + public void testMethodLabelPolymorphicSignatureReference3Ret() throws Exception { IJavaElement elem= createInvokeReference("long l= (long) mh.invoke('a', new java.util.ArrayList<String>(), null)"); - + assertInvokeUnresolved(elem); - + String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "invoke(char, {{java.util|ArrayList}}<{{java.util.ArrayList|E}}>, {{java.lang|Void}})"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "invoke(char, {{java.util|ArrayList}}, {{java.lang|Void}})"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "{{java.lang|Object}} invoke(char arg00, {{java.util|ArrayList}} arg01, {{java.lang|Void}} arg02)"); } - + public void testTypeLabelLambda1() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -247,7 +247,7 @@ public class BindingLabels18Test extends AbstractBindingLabelsTest { lab= getBindingLabel(lambdaMethod, JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.M_POST_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES); assertLinkMatch(lab, "accept(int i) - {{org.test.C}}.{{org.test.C|c}}.() -> {...} {{java.util.function|IntConsumer}}"); - + IJavaElement lambdaType= lambdaMethod.getParent(); lab= getBindingLabel(lambdaType, JavaElementLabels.T_POST_QUALIFIED); // Bindings don't have the split identity of a lambda as expected from JavaElementLabelsTest18 @@ -281,7 +281,7 @@ public class BindingLabels18Test extends AbstractBindingLabelsTest { lab= getBindingLabel(lambdaMethod, JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.M_POST_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES); assertLinkMatch(lab, "accept({{java.util.function.Consumer|T}} arg0) - {{org.test.C}}.{{org.test.C|c}}.() -> {...} {{java.util.function|Consumer}}"); - + IJavaElement lambdaType= lambdaMethod.getParent(); lab= getBindingLabel(lambdaType, JavaElementLabels.T_POST_QUALIFIED); assertLinkMatch(lab, "accept(...) - {{org.test.C}}.{{org.test.C|c}}.() -> {...} {{java.util.function|Consumer}}"); @@ -332,11 +332,11 @@ public class BindingLabels18Test extends AbstractBindingLabelsTest { IJavaElement[] elems= cu.codeSelect(content.lastIndexOf("s)"), 1); IJavaElement thread= elems[0]; String lab= getBindingLabel(thread, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED); - assertLinkMatch(lab, "{{org.test.C}}.{{org.test.C|t}}.{{org.test.C.t|new Thread() {...}}}.{{org.test.C.t.new Thread() {...}|run}}()." + + assertLinkMatch(lab, "{{org.test.C}}.{{org.test.C|t}}.{{org.test.C.t|new Thread() {...}}}.{{org.test.C.t.new Thread() {...}|run}}()." + "() -> {...} {{java.util.function|Consumer}}.{{java.util.function.Consumer<java.lang.String>|accept}}({{java.lang|String}}).s"); lab= getBindingLabel(thread, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.F_PRE_TYPE_SIGNATURE | JavaElementLabels.F_POST_QUALIFIED); - assertLinkMatch(lab, "{{java.lang|String}} s - {{org.test.C}}.{{org.test.C|t}}.{{org.test.C.t|new Thread() {...}}}.{{org.test.C.t.new Thread() {...}|run}}()." + + assertLinkMatch(lab, "{{java.lang|String}} s - {{org.test.C}}.{{org.test.C|t}}.{{org.test.C.t|new Thread() {...}}}.{{org.test.C.t.new Thread() {...}|run}}()." + "() -> {...} {{java.util.function|Consumer}}.{{java.util.function.Consumer|accept}}({{java.util.function.Consumer|T}})"); } @@ -430,7 +430,7 @@ public class BindingLabels18Test extends AbstractBindingLabelsTest { JavaProjectHelper.addRTJar12(javaProject, false); JavaProjectHelper.set12CompilerOptions(javaProject, false); IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(javaProject, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("p", false, null); StringBuilder buf= new StringBuilder(); buf.append("package p;\n"); @@ -451,7 +451,7 @@ public class BindingLabels18Test extends AbstractBindingLabelsTest { String content= buf.toString(); ICompilationUnit cu= pack1.createCompilationUnit("Test.java", content, false, null); IJavaElement enclElement= cu.getTypes()[0].getMethods()[1]; - + class MyASTRequestor extends ASTRequestor { CompilationUnit ast; @Override @@ -465,7 +465,7 @@ public class BindingLabels18Test extends AbstractBindingLabelsTest { parser.setProject(javaProject); MyASTRequestor requestor= new MyASTRequestor(); parser.createASTs(new ICompilationUnit[] {cu}, new String[0], requestor, null); - + MethodDeclaration method= ((TypeDeclaration)requestor.ast.types().get(0)).getMethods()[1]; Assignment assignment= (Assignment) ((ExpressionStatement) method.getBody().statements().get(0)).getExpression(); Name name= (Name) assignment.getLeftHandSide(); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabels9Test.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabels9Test.java index fc28c59ef9..c8ead1230d 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabels9Test.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabels9Test.java @@ -53,7 +53,7 @@ public class BindingLabels9Test extends AbstractBindingLabelsTest { protected void tearDown() throws Exception { JavaProjectHelper.clear(fJProject1, Java9ProjectTestSetup.getDefaultClasspath()); } - + public void testModuleWithCategory1() throws Exception { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabelsTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabelsTest.java index 58d6561a30..5b566e85c7 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabelsTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/BindingLabelsTest.java @@ -212,8 +212,8 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { lab= JavaElementLabels.getTextLabel(e, JavaElementLabels.ALL_POST_QUALIFIED); assertEqualString(lab, "E - java.util.ArrayList"); */ - - + + lab= getBindingLabel(typeParams, 0); assertEqualString(lab, "TypeParams"); lab= getBindingLabel(typeParams, JavaElementLabels.ALL_DEFAULT); @@ -451,11 +451,11 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { IPackageFragment packOrg= sourceFolder.createPackageFragment("org", false, null); // IPackageFragment packOrgTest= sourceFolder.createPackageFragment("org.test", false, null); IPackageFragment packOrgTestLongname= sourceFolder.createPackageFragment("org.test.longname", false, null); - + // to obtain an IPackageBinding go via imported types to their #package: packOrg.createCompilationUnit("T1.java", "package org;\npublic class T1 {}\n", false, null); packOrgTestLongname.createCompilationUnit("T2.java", "package org.test.longname;\npublic class T2 {}\n", false, null); - + StringBuilder buf= new StringBuilder(); buf.append("import org.T1;\n"); buf.append("import org.test.longname.T2;\n"); @@ -472,7 +472,7 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { parser.setResolveBindings(true); parser.setProject(fJProject1); IBinding[] bindings= parser.createBindings(new IJavaElement[]{main, t1, t2}, null); - + String lab= JavaElementLinks.getBindingLabel(((ITypeBinding)bindings[0]).getPackage(), main.getAncestor(IJavaElement.PACKAGE_FRAGMENT), JavaElementLabels.ALL_DEFAULT, true); assertEqualString(lab, "(default package)"); lab= JavaElementLinks.getBindingLabel(((ITypeBinding)bindings[1]).getPackage(), t1.getAncestor(IJavaElement.PACKAGE_FRAGMENT), JavaElementLabels.ALL_DEFAULT, true); @@ -523,23 +523,23 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { store.setValue(PreferenceConstants.APPEARANCE_ABBREVIATE_PACKAGE_NAMES, true); - + assertExpectedLabel(packOrgTestLongname, "org.te*.longname", JavaElementLabels.P_COMPRESSED); - + store.setValue(PreferenceConstants.APPEARANCE_PKG_NAME_ABBREVIATION_PATTERN_FOR_PKG_VIEW, "#com=@C\norg=@O"); - + assertExpectedLabel(packDefault, "(default package)", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrg, "@O", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrgTest, "@O.test", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrgTestLongname, "@O.te*.longname", JavaElementLabels.P_COMPRESSED); - + store.setValue(PreferenceConstants.APPEARANCE_PKG_NAME_ABBREVIATION_PATTERN_FOR_PKG_VIEW, "org=@O\n\norg.test=@OT\n"); - + assertExpectedLabel(packDefault, "(default package)", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrg, "@O", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrgTest, "@OT", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrgTestLongname, "@OT.longname", JavaElementLabels.P_COMPRESSED); - + } finally { store.setToDefault(PreferenceConstants.APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW); store.setValue(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES, false); @@ -550,9 +550,9 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { } public void testMethodLabelVarargsDeclaration() throws Exception { - + IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); @@ -564,7 +564,7 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { ICompilationUnit cu= pack1.createCompilationUnit("Varargs.java", content, false, null); IJavaElement elem= cu.getElementAt(content.indexOf("foo")); - + String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT); assertLinkMatch(lab, "foo(int, {{java.lang|String}}...)"); @@ -573,17 +573,17 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES); assertLinkMatch(lab, "foo(int, {{java.lang|String}}...)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES); assertLinkMatch(lab, "foo(int i, {{java.lang|String}}... varargs)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "foo(int, {{java.lang|String}}...)"); } public void testMethodLabelVarargsReference0() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); @@ -595,24 +595,24 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { buf.append("}\n"); String content= buf.toString(); ICompilationUnit cu= pack1.createCompilationUnit("Varargs.java", content, false, null); - + IJavaElement elem= cu.codeSelect(content.indexOf("asList"), 0)[0]; - + String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT); assertLinkMatch(lab, "asList({{java.util.Arrays.asList(...)|T}}...) <{{java.util.Arrays.asList(...)|T}}>"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_NAMES); assertEqualString(lab, "asList(arg0)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES); assertLinkMatch(lab, "asList({{java.util.Arrays.asList(...)|T}}...)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES); assertLinkMatch(lab, "asList({{java.util.Arrays.asList(...)|T}}... arg0)"); - + lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "asList({{java.lang|Object}}...) <{{java.lang|Object}}>"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "asList({{java.lang|Object}}...)"); } @@ -620,15 +620,15 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { public void testMethodLabelVarargsReference1() throws Exception { assertMethodLabelVarargsReference("1"); } - + public void testMethodLabelVarargsReference2() throws Exception { assertMethodLabelVarargsReference("1, 2"); } - + public void testMethodLabelVarargsReference3() throws Exception { assertMethodLabelVarargsReference("1, 2, Integer.valueOf(3)"); } - + private void assertMethodLabelVarargsReference(String args) throws CoreException, JavaModelException { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -645,7 +645,7 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { ICompilationUnit cu= pack1.createCompilationUnit("Varargs.java", content, false, null); IJavaElement elem= cu.codeSelect(content.indexOf("asList"), 0)[0]; - + String lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT); assertLinkMatch(lab, "asList({{java.util.Arrays.asList(...)|T}}...) <{{java.util.Arrays.asList(...)|T}}>"); @@ -654,18 +654,18 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES); assertLinkMatch(lab, "asList({{java.util.Arrays.asList(...)|T}}...)"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES); assertLinkMatch(lab, "asList({{java.util.Arrays.asList(...)|T}}... arg0)"); - + lab= getBindingLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "asList({{java.lang|Integer}}...) <{{java.lang|Integer}}>"); - + lab= getBindingLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertLinkMatch(lab, "asList({{java.lang|Integer}}...)"); } - - + + public void testMethodLabelAnnotatedParameters() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); @@ -703,11 +703,11 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { lab= getBindingLabel(foo2, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.M_PARAMETER_ANNOTATIONS); assertLinkMatch(lab, "{{org.test.Annotations}}.foo2(@{{Ann}}({{value}}=\"\", {{cl}}={{Annotations}}.class, {{ints}}={1, 2, -19}, {{ch}}='\\u0000', {{sh}}=32767, {{r}}=@{{Retention}}({{value}}={{RetentionPolicy}}.{{SOURCE}})) {{String}})"); } - + // disabled, because we cannot retrieve a binding for the selected element: local variable inside instance initializer public void testLocalClassInInitializer() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); @@ -734,7 +734,7 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { IJavaElement foo2= cu.codeSelect(content.indexOf("toStringL"), 9)[0]; lab= getBindingLabel(foo2, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_POST_QUALIFIED | JavaElementLabels.F_PRE_TYPE_SIGNATURE); assertLinkMatch(lab, "{{org.test.LambdaTests.{...}|Local}} toStringL - {{org}}.{{test}}.{{LambdaTests}}.{...}"); - + // can't select the constructor, only the type (label computation works fine once we find the binding) // IJavaElement ctor= cu.codeSelect(content.indexOf("Local()"), 0)[0]; // lab= getBindingLabel(ctor, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_FULLY_QUALIFIED); @@ -743,7 +743,7 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { public void testLocalClassInStaticInitializer() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); @@ -774,7 +774,7 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { public void testRecursiveType() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); @@ -798,7 +798,7 @@ public class BindingLabelsTest extends AbstractBindingLabelsTest { public void testMultipleTypeVariables() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/CodeFormatterTest9.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/CodeFormatterTest9.java index c3f63d80a4..6266d39ddc 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/CodeFormatterTest9.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/CodeFormatterTest9.java @@ -67,8 +67,8 @@ public class CodeFormatterTest9 extends CodeFormatterTest { String formatted= format(cu, 0, 0); String expected= - "module pack {\n" + - " requires java.something;\n" + + "module pack {\n" + + " requires java.something;\n" + "}\n"; assertEqualString(formatted, expected); } @@ -77,9 +77,9 @@ public class CodeFormatterTest9 extends CodeFormatterTest { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String original= "module pack { requires java .something ; } \n "; ICompilationUnit cu= pack1.createCompilationUnit("SomeClass.java", original, false, null); - + String formatted= format(cu, 0, 0); - + String expected= "module pack { requires java .something ; }\n"; assertEqualString(formatted, expected); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest.java index 799a8d9585..e8d9da184d 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/ImportOrganizeTest.java @@ -647,7 +647,7 @@ public class ImportOrganizeTest extends CoreTests { buf.append("}\n"); assertEqualString(cu.getSource(), buf.toString()); } - + public void testImportToStarWithComments() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -2444,7 +2444,7 @@ public class ImportOrganizeTest extends CoreTests { assertEquals(2, op.getNumberOfImportsAdded()); assertEquals(1, op.getNumberOfImportsRemoved()); } - + public void testImportCountAddandRemoveWithComments() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -3184,10 +3184,10 @@ public class ImportOrganizeTest extends CoreTests { buf.append("}\n"); assertEqualString(cu.getSource(), buf.toString()); } - + public void testJavadocImports_bug319860() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack0= sourceFolder.createPackageFragment("p", false, null); StringBuffer buf= new StringBuffer(); buf.append("package p;\n"); @@ -3204,13 +3204,13 @@ public class ImportOrganizeTest extends CoreTests { buf.append(" public class C {}\n"); buf.append("}\n"); ICompilationUnit cu= pack0.createCompilationUnit("Main.java", buf.toString(), false, null); - + String[] order= new String[] {}; IChooseImportQuery query= createQuery("JavadocImports_bug319860", new String[] {}, new int[] {}); - + OrganizeImportsOperation op= createOperation(cu, order, 99, false, true, true, query); op.run(null); - + buf= new StringBuffer(); buf.append("package p;\n"); buf.append("\n"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java12ProjectTestSetup.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java12ProjectTestSetup.java index 19090c9126..673aa95798 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java12ProjectTestSetup.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java12ProjectTestSetup.java @@ -33,7 +33,7 @@ import junit.framework.Test; public class Java12ProjectTestSetup extends ProjectTestSetup { public static final String PROJECT_NAME12= "TestSetupProject12"; - + private boolean enable_preview_feature; public static IJavaProject getProject() { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java13ProjectTestSetup.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java13ProjectTestSetup.java index e5284e76a2..69643a50b2 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java13ProjectTestSetup.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/Java13ProjectTestSetup.java @@ -33,7 +33,7 @@ import junit.framework.Test; public class Java13ProjectTestSetup extends ProjectTestSetup { public static final String PROJECT_NAME13= "TestSetupProject13"; - + private boolean enable_preview_feature; public static IJavaProject getProject() { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaElementLabelsTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaElementLabelsTest.java index 82bdcfe5b4..418d2074b6 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaElementLabelsTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaElementLabelsTest.java @@ -216,8 +216,8 @@ public class JavaElementLabelsTest extends CoreTests { assertEqualString(lab, "E"); // no " extends java.lang.Object"! lab= JavaElementLabels.getTextLabel(e, JavaElementLabels.ALL_POST_QUALIFIED); assertEqualString(lab, "E - java.util.ArrayList"); - - + + lab= JavaElementLabels.getTextLabel(typeParams, 0); assertEqualString(lab, "TypeParams"); lab= JavaElementLabels.getTextLabel(typeParams, JavaElementLabels.ALL_DEFAULT); @@ -486,23 +486,23 @@ public class JavaElementLabelsTest extends CoreTests { store.setValue(PreferenceConstants.APPEARANCE_ABBREVIATE_PACKAGE_NAMES, true); - + assertExpectedLabel(packOrgTestLongname, "org.te*.longname", JavaElementLabels.P_COMPRESSED); - + store.setValue(PreferenceConstants.APPEARANCE_PKG_NAME_ABBREVIATION_PATTERN_FOR_PKG_VIEW, "#com=@C\norg=@O"); - + assertExpectedLabel(packDefault, "(default package)", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrg, "@O", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrgTest, "@O.test", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrgTestLongname, "@O.te*.longname", JavaElementLabels.P_COMPRESSED); - + store.setValue(PreferenceConstants.APPEARANCE_PKG_NAME_ABBREVIATION_PATTERN_FOR_PKG_VIEW, "org=@O\n\norg.test=@OT\n"); - + assertExpectedLabel(packDefault, "(default package)", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrg, "@O", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrgTest, "@OT", JavaElementLabels.P_COMPRESSED); assertExpectedLabel(packOrgTestLongname, "@OT.longname", JavaElementLabels.P_COMPRESSED); - + } finally { store.setToDefault(PreferenceConstants.APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW); store.setValue(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES, false); @@ -512,9 +512,9 @@ public class JavaElementLabelsTest extends CoreTests { } public void testMethodLabelVarargsDeclaration() throws Exception { - + IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); @@ -526,7 +526,7 @@ public class JavaElementLabelsTest extends CoreTests { ICompilationUnit cu= pack1.createCompilationUnit("Varargs.java", content, false, null); IJavaElement elem= cu.getElementAt(content.indexOf("foo")); - + String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT); assertEqualString(lab, "foo(int, String...)"); @@ -535,17 +535,17 @@ public class JavaElementLabelsTest extends CoreTests { lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES); assertEqualString(lab, "foo(int, String...)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES); assertEqualString(lab, "foo(int i, String... varargs)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "foo(int, String...)"); } public void testMethodLabelVarargsReference0() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); @@ -557,24 +557,24 @@ public class JavaElementLabelsTest extends CoreTests { buf.append("}\n"); String content= buf.toString(); ICompilationUnit cu= pack1.createCompilationUnit("Varargs.java", content, false, null); - + IJavaElement elem= cu.codeSelect(content.indexOf("asList"), 0)[0]; - + String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT); assertEqualString(lab, "asList(T...) <T>"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_NAMES); assertEqualString(lab, "asList(arg0)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES); assertEqualString(lab, "asList(T...)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES); assertEqualString(lab, "asList(T... arg0)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "asList(Object...) <Object>"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "asList(Object...)"); } @@ -582,15 +582,15 @@ public class JavaElementLabelsTest extends CoreTests { public void testMethodLabelVarargsReference1() throws Exception { assertMethodLabelVarargsReference("1"); } - + public void testMethodLabelVarargsReference2() throws Exception { assertMethodLabelVarargsReference("1, 2"); } - + public void testMethodLabelVarargsReference3() throws Exception { assertMethodLabelVarargsReference("1, 2, Integer.valueOf(3)"); } - + private void assertMethodLabelVarargsReference(String args) throws CoreException, JavaModelException { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -607,7 +607,7 @@ public class JavaElementLabelsTest extends CoreTests { ICompilationUnit cu= pack1.createCompilationUnit("Varargs.java", content, false, null); IJavaElement elem= cu.codeSelect(content.indexOf("asList"), 0)[0]; - + String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT); assertEqualString(lab, "asList(T...) <T>"); @@ -616,18 +616,18 @@ public class JavaElementLabelsTest extends CoreTests { lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES); assertEqualString(lab, "asList(T...)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES); assertEqualString(lab, "asList(T... arg0)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "asList(Integer...) <Integer>"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "asList(Integer...)"); } - - + + public void testMethodLabelAnnotatedParameters() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaElementLabelsTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaElementLabelsTest18.java index 41746037f4..6ff74bf8d0 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaElementLabelsTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaElementLabelsTest18.java @@ -73,26 +73,26 @@ public class JavaElementLabelsTest18 extends CoreTests { IMethod invokeExact= methodHandle.getMethod("invokeExact", new String[] { Signature.createArraySignature(Signature.createTypeSignature("java.lang.Object", true), 1) }); - + String lab= JavaElementLabels.getTextLabel(invokeExact, JavaElementLabels.ALL_DEFAULT); assertEqualString(lab, "invokeExact(Object...)"); - + lab= JavaElementLabels.getTextLabel(invokeExact, JavaElementLabels.M_PARAMETER_NAMES); assertEqualString(lab, "invokeExact(arg0)"); - + lab= JavaElementLabels.getTextLabel(invokeExact, JavaElementLabels.M_PARAMETER_TYPES); assertEqualString(lab, "invokeExact(Object...)"); - + lab= JavaElementLabels.getTextLabel(invokeExact, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES); assertEqualString(lab, "invokeExact(Object... arg0)"); - + lab= JavaElementLabels.getTextLabel(invokeExact, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invokeExact(Object...)"); } private IJavaElement createInvokeReference(String invocation) throws CoreException, JavaModelException { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); - + IPackageFragment pack1= sourceFolder.createPackageFragment("org.test", false, null); StringBuilder buf= new StringBuilder(); buf.append("package org.test;\n"); @@ -104,7 +104,7 @@ public class JavaElementLabelsTest18 extends CoreTests { buf.append("}\n"); String content= buf.toString(); ICompilationUnit cu= pack1.createCompilationUnit("Test.java", content, false, null); - + IJavaElement elem= cu.codeSelect(content.indexOf("invoke("), 0)[0]; return elem; } @@ -112,107 +112,107 @@ public class JavaElementLabelsTest18 extends CoreTests { private static void assertInvokeUnresolved(IJavaElement elem) { String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT); assertEqualString(lab, "invoke(Object...)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_NAMES); assertEqualString(lab, "invoke(arg0)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES); assertEqualString(lab, "invoke(Object...)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PRE_RETURNTYPE); assertEqualString(lab, "Object invoke(Object... arg0)"); } public void testMethodLabelPolymorphicSignatureReference0() throws Exception { IJavaElement elem= createInvokeReference("mh.invoke()"); - + assertInvokeUnresolved(elem); - + String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke()"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke()"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "void invoke()"); } public void testMethodLabelPolymorphicSignatureReference0Ret() throws Exception { IJavaElement elem= createInvokeReference("String s= (String) mh.invoke()"); - + assertInvokeUnresolved(elem); - + String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke()"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke()"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "Object invoke()"); } - + public void testMethodLabelPolymorphicSignatureReference1() throws Exception { IJavaElement elem= createInvokeReference("mh.invoke(1)"); - + assertInvokeUnresolved(elem); - + String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(int)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(int)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "void invoke(int arg00)"); } - + public void testMethodLabelPolymorphicSignatureReference1Array() throws Exception { IJavaElement elem= createInvokeReference("mh.invoke(new Object[42])"); - + assertInvokeUnresolved(elem); - + String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(Object[])"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(Object[])"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "void invoke(Object[] arg00)"); } - + public void testMethodLabelPolymorphicSignatureReference2() throws Exception { IJavaElement elem= createInvokeReference("mh.invoke('a', new Integer[0][])"); - + assertInvokeUnresolved(elem); - + String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(char, Integer[][])"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(char, Integer[][])"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "void invoke(char arg00, Integer[][] arg01)"); } - + public void testMethodLabelPolymorphicSignatureReference3Ret() throws Exception { IJavaElement elem= createInvokeReference("long l= (long) mh.invoke('a', new java.util.ArrayList<String>(), null)"); - + assertInvokeUnresolved(elem); - + String lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(char, ArrayList, Void)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "invoke(char, ArrayList, Void)"); - + lab= JavaElementLabels.getTextLabel(elem, JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.USE_RESOLVED); assertEqualString(lab, "Object invoke(char arg00, ArrayList arg01, Void arg02)"); } - + public void testTypeLabelLambda1() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -236,7 +236,7 @@ public class JavaElementLabelsTest18 extends CoreTests { lab= JavaElementLabels.getTextLabel(lambdaMethod, JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.M_POST_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES); assertEqualString(lab, "accept(int i) - org.test.C.c.() -> {...} IntConsumer"); - + IJavaElement lambdaType= lambdaMethod.getParent(); lab= JavaElementLabels.getTextLabel(lambdaType, JavaElementLabels.T_POST_QUALIFIED); assertEqualString(lab, "() -> {...} IntConsumer - org.test.C.c"); @@ -268,7 +268,7 @@ public class JavaElementLabelsTest18 extends CoreTests { lab= JavaElementLabels.getTextLabel(lambdaMethod, JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.M_POST_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES); assertEqualString(lab, "accept(String s) - org.test.C.c.() -> {...} Consumer"); - + IJavaElement lambdaType= lambdaMethod.getParent(); lab= JavaElementLabels.getTextLabel(lambdaType, JavaElementLabels.T_POST_QUALIFIED); assertEqualString(lab, "() -> {...} Consumer - org.test.C.c"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaModelUtilTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaModelUtilTest.java index b08929a070..4a1d4a9f4b 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaModelUtilTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/JavaModelUtilTest.java @@ -122,9 +122,9 @@ public class JavaModelUtilTest extends TestCase { assertMatching(true, "org.junit.Test", "Test"); assertMatching(true, "X.Test", "Test"); assertMatching(true, "Test", "Test"); - + assertMatching(true, "java.lang.Thread.State", "Thread.State"); - + assertMatching(false, "org.junit.Test", "org.junitX.Test"); assertMatching(false, "org.junit.Test", "X.Test"); assertMatching(false, "org.junit.Test", "Xorg.junit.Test"); @@ -132,7 +132,7 @@ public class JavaModelUtilTest extends TestCase { assertMatching(false, "Test", "Test.X"); assertMatching(false, "Test", ".Test"); } - + private void assertMatching(boolean matching, String nameA, String nameB) { assertEquals(matching, JavaModelUtil.isMatchingName(nameA, nameB)); assertEquals(matching, JavaModelUtil.isMatchingName(nameB, nameA)); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java index 67f23edcb1..d0e3469f47 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java @@ -304,7 +304,7 @@ public class MethodOverrideTest extends CoreTests { } IType focusType= types[focusIndex]; - + IType overridingType= types[overridingIndex]; ITypeBinding overridingTypeBinding= typeBindings[overridingIndex]; assertSameType(overridingType, overridingTypeBinding); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest18.java index a20977ef15..ceb29c447e 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest18.java @@ -78,20 +78,20 @@ public class MethodOverrideTest18 extends MethodOverrideTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("MyFunction.java", buf.toString(), false, null); - + CompilationUnit root= assertNoCompilationError(cu); IType focusType= cu.getTypes()[0]; - + int vStart= buf.indexOf("v))"); ILocalVariable v= (ILocalVariable) cu.codeSelect(vStart, 1)[0]; IType overridingType= v.getDeclaringMember().getDeclaringType(); - + LambdaExpression lambda= (LambdaExpression) NodeFinder.perform(root, buf.indexOf("->"), 2); ITypeBinding overridingTypeBinding= lambda.resolveTypeBinding(); - + IType overriddenType= focusType; ITypeBinding overriddenTypeBinding= ((TypeDeclaration) root.types().get(0)).resolveBinding(); - + doOverrideTests(root, focusType, overridingType, overridingTypeBinding, overriddenType, overriddenTypeBinding); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/NameProposerTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/NameProposerTest.java index b0dcb47c85..3930a6518d 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/NameProposerTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/NameProposerTest.java @@ -106,7 +106,7 @@ public class NameProposerTest extends TestCase { assertEqualString("isModified", GetterSetterUtil.getGetterName(f5, excluded)); assertEqualString("setTouched", GetterSetterUtil.getSetterName(f6, excluded)); assertEqualString("isTouched", GetterSetterUtil.getGetterName(f6, excluded)); - + assertEqualString("setConst", GetterSetterUtil.getSetterName(f7, excluded)); assertEqualString("getConst", GetterSetterUtil.getGetterName(f7, excluded)); assertEqualString("setMyConstAnt", GetterSetterUtil.getSetterName(f8, excluded)); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/NoSuperTestsSuite.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/NoSuperTestsSuite.java index 567e0b616f..c0c7684688 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/NoSuperTestsSuite.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/NoSuperTestsSuite.java @@ -19,7 +19,7 @@ import junit.framework.TestSuite; /** * Test suite that only includes tests from the given test class, but not tests from super classes. - * + * * @since 3.10 */ public class NoSuperTestsSuite extends TestSuite { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/JUnitSourceSetup.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/rules/JUnitSourceSetup.java index 34dc1b7ce7..9ad6f4ccfc 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/JUnitSourceSetup.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/rules/JUnitSourceSetup.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -11,17 +11,18 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.jdt.ui.tests.search; +package org.eclipse.jdt.ui.tests.core.rules; import java.io.File; -import junit.extensions.TestSetup; -import junit.framework.Test; +import org.junit.rules.ExternalResource; import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.jdt.testplugin.JavaTestPlugin; import org.eclipse.jdt.testplugin.TestOptions; +import org.eclipse.core.runtime.CoreException; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; @@ -33,7 +34,7 @@ import org.eclipse.jdt.internal.ui.search.SearchParticipantRecord; import org.eclipse.jdt.internal.ui.search.SearchParticipantsExtensionPoint; -public class JUnitSourceSetup extends TestSetup { +public class JUnitSourceSetup extends ExternalResource { public static final String PROJECT_NAME= "JUnitSource"; public static final String SRC_CONTAINER= "src"; @@ -52,17 +53,16 @@ public class JUnitSourceSetup extends TestSetup { return JavaCore.create(project); } - public JUnitSourceSetup(Test test, SearchParticipantsExtensionPoint participants) { - super(test); + public JUnitSourceSetup(SearchParticipantsExtensionPoint participants) { fExtensionPoint= participants; } - public JUnitSourceSetup(Test test) { - this(test, new NullExtensionPoint()); + public JUnitSourceSetup() { + this( new NullExtensionPoint()); } @Override - protected void setUp() throws Exception { + public void before() throws Throwable { SearchParticipantsExtensionPoint.debugSetInstance(fExtensionPoint); fProject= JavaProjectHelper.createJavaProject(PROJECT_NAME, "bin"); JavaProjectHelper.addRTJar(fProject); @@ -74,8 +74,12 @@ public class JUnitSourceSetup extends TestSetup { } @Override - protected void tearDown() throws Exception { - JavaProjectHelper.delete(fProject); + public void after() { + try { + JavaProjectHelper.delete(fProject); + } catch (CoreException e) { + e.printStackTrace(); + } SearchParticipantsExtensionPoint.debugSetInstance(null); } } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/rules/LeakTestSetup.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/rules/LeakTestSetup.java new file mode 100644 index 0000000000..998203ec23 --- /dev/null +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/rules/LeakTestSetup.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.ui.tests.core.rules; + +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.intro.IIntroManager; + +/** + * + */ +public class LeakTestSetup extends JUnitSourceSetup { + + private static LeakTestSetup fgCurrentSetup= null; + + public LeakTestSetup() { + super(); + if (fgCurrentSetup == null) { + fgCurrentSetup= this; + } + } + + @Override + public void before() throws Throwable { + super.before(); + if (fgCurrentSetup != this) { + return; + } + IIntroManager introManager= PlatformUI.getWorkbench().getIntroManager(); + introManager.closeIntro(introManager.getIntro()); + } + + @Override + public void after() { + super.after(); + if (fgCurrentSetup != this) { + return; + } + // nothing done at the moment + } +} diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/AddUnimplementedConstructorsTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/AddUnimplementedConstructorsTest.java index 4ee55a9bb0..67bcbd5233 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/AddUnimplementedConstructorsTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/AddUnimplementedConstructorsTest.java @@ -666,7 +666,7 @@ public class AddUnimplementedConstructorsTest extends CoreTests { JavaModelUtil.reconcile(testClass.getCompilationUnit()); IMethod[] existingMethods= testClass.getMethods(); - checkMethods(new String[] { "Test1"}, existingMethods); //$NON-NLS-1$ + checkMethods(new String[] { "Test1"}, existingMethods); //$NON-NLS-1$ StringBuilder buf= new StringBuilder(); buf.append("public class Test1 extends A {\n"); @@ -702,7 +702,7 @@ public class AddUnimplementedConstructorsTest extends CoreTests { JavaModelUtil.reconcile(testClass.getCompilationUnit()); IMethod[] existingMethods= testClass.getMethods(); - checkMethods(new String[] { "Test1"}, existingMethods); //$NON-NLS-1$ + checkMethods(new String[] { "Test1"}, existingMethods); //$NON-NLS-1$ StringBuilder buf= new StringBuilder(); buf.append("public class Test1 implements A {\n"); @@ -739,7 +739,7 @@ public class AddUnimplementedConstructorsTest extends CoreTests { JavaModelUtil.reconcile(testClass.getCompilationUnit()); IMethod[] createdMethods= testClass.getMethods(); - checkMethods(new String[] { "Test1"}, createdMethods); //$NON-NLS-1$ + checkMethods(new String[] { "Test1"}, createdMethods); //$NON-NLS-1$ StringBuilder buf= new StringBuilder(); buf.append("public class Test1 extends A {\n"); @@ -822,7 +822,7 @@ public class AddUnimplementedConstructorsTest extends CoreTests { JavaModelUtil.reconcile(testClass.getCompilationUnit()); IMethod[] createdMethods= testClass.getMethods(); - checkMethods(new String[] { "Test1"}, createdMethods); //$NON-NLS-1$ + checkMethods(new String[] { "Test1"}, createdMethods); //$NON-NLS-1$ checkDefaultConstructorWithCommentWithSuper(createdMethods[0].getSource()); @@ -916,7 +916,7 @@ public class AddUnimplementedConstructorsTest extends CoreTests { IMethod[] createdMethods= testClass.getMethods(); String fullSource= testClass.getCompilationUnit().getSource(); - checkMethods(new String[] { "Test1"}, createdMethods); //$NON-NLS-1$ + checkMethods(new String[] { "Test1"}, createdMethods); //$NON-NLS-1$ StringBuilder buf= new StringBuilder(); buf.append("package ibm.util.bogus;\n"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/AddUnimplementedMethodsTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/AddUnimplementedMethodsTest.java index 3a43183916..0b8ab22d1d 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/AddUnimplementedMethodsTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/AddUnimplementedMethodsTest.java @@ -96,7 +96,7 @@ public class AddUnimplementedMethodsTest extends TestCase { fJavaProject.setOptions(options); assertNotNull(JavaProjectHelper.addRTJar(fJavaProject)); - + StubUtility.setCodeTemplate(CodeTemplateContextType.METHODSTUB_ID, "${body_statement}\n// TODO", null); IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(fJavaProject, "src"); @@ -257,7 +257,7 @@ public class AddUnimplementedMethodsTest extends TestCase { buf.append(" int getArea();\r\n"); buf.append("}\r\n"); fPackage.createCompilationUnit("Shape.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package ibm.util;\n"); buf.append("interface Circle extends Shape {\r\n"); @@ -265,23 +265,23 @@ public class AddUnimplementedMethodsTest extends TestCase { buf.append("}\r\n"); buf.append("\r\n"); fPackage.createCompilationUnit("Circle.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package ibm.util;\n"); buf.append("public class DefaultCircle implements Circle {\n"); buf.append("}\n"); ICompilationUnit cu= fPackage.getCompilationUnit("DefaultCircle.java"); IType testClass= cu.createType(buf.toString(), null, true, null); - + testHelper(testClass, -1, false); - + IMethod[] methods= testClass.getMethods(); checkMethodsInOrder(new String[] { "getX", "getY", "getEdges", "getArea", "getR"}, methods); - + IImportDeclaration[] imports= cu.getImports(); checkImports(new String[0], imports); } - + public void testInsertAt() throws Exception { fJavaProject= JavaProjectHelper.createJavaProject("DummyProject", "bin"); assertNotNull(JavaProjectHelper.addRTJar(fJavaProject)); @@ -396,11 +396,11 @@ public class AddUnimplementedMethodsTest extends TestCase { public void testJLS4() throws Exception { doTestOldAstLevel(AST.JLS4); } - + public void testJLS8() throws Exception { doTestOldAstLevel(AST.JLS8); } - + /** * @param astLevel AST.JLS* * @throws Exception @@ -424,9 +424,9 @@ public class AddUnimplementedMethodsTest extends TestCase { assertNotNull("Could not find type declaration node", declaration); ITypeBinding binding= declaration.resolveBinding(); assertNotNull("Binding for type declaration could not be resolved", binding); - + IMethodBinding[] overridableMethods= StubUtility2Core.getOverridableMethods(unit.getAST(), binding, false); - + AddUnimplementedMethodsOperation op= new AddUnimplementedMethodsOperation(unit, binding, overridableMethods, -1, true, true, true); op.run(new NullProgressMonitor()); @@ -435,7 +435,7 @@ public class AddUnimplementedMethodsTest extends TestCase { IImportDeclaration[] imports= cu.getImports(); checkImports(new String[] { "java.util.Date", "java.util.Hashtable", "java.util.Vector", "java.util.ArrayList" }, imports); - + IProblem[] problems= parser.parse(cu, true).getProblems(); assertArrayEquals(new IProblem[0], problems); } @@ -466,7 +466,7 @@ public class AddUnimplementedMethodsTest extends TestCase { } assertEquals(Strings.concatenate(expected, ", "), Strings.concatenate(actualNames, ", ")); } - + private void checkMethods(String[] expected, IMethod[] methods) { int nMethods= methods.length; int nExpected= expected.length; diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateGettersSettersTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateGettersSettersTest.java index ac461a69dc..6620fcae06 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateGettersSettersTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateGettersSettersTest.java @@ -161,7 +161,7 @@ public class GenerateGettersSettersTest extends SourceTestCase { /** * Tests normal getter/setter generation for one field. - * + * * @throws Exception */ public void testDoneWithSmartIs() throws Exception { @@ -193,7 +193,7 @@ public class GenerateGettersSettersTest extends SourceTestCase { /** * Tests normal getter/setter generation for one field. - * + * * @throws Exception */ public void testIsDoneWithSmartIs() throws Exception { @@ -225,7 +225,7 @@ public class GenerateGettersSettersTest extends SourceTestCase { /** * Tests normal getter/setter generation for one field. - * + * * @throws Exception */ public void testDoneWithoutSmartIs() throws Exception { @@ -262,7 +262,7 @@ public class GenerateGettersSettersTest extends SourceTestCase { /** * Tests normal getter/setter generation for one field. - * + * * @throws Exception */ public void testIsDoneWithoutSmartIs() throws Exception { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateHashCodeEqualsTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateHashCodeEqualsTest.java index 7558ac13b8..0a9e75b38b 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateHashCodeEqualsTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateHashCodeEqualsTest.java @@ -983,7 +983,7 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { /** * Test with J7+ Objects.hash and Objects.equals method calls * Using non-array instance variables and Enum - * + * * @throws Exception */ public void testHashCodeEqualsIn17() throws Exception { @@ -1046,11 +1046,11 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test with J7+ Objects.hash and Objects.equals method calls * Using unique non-array instance variables - * + * * @throws Exception */ public void testHashCodeEqualsUniqueFieldIn17() throws Exception { @@ -1094,11 +1094,11 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test with J7+ Objects.hash and Objects.equals method calls * Using non-array instance variables with 'instanceof' comparison - * + * * @throws Exception */ public void testHashCodeEqualsInstanceOfIn17() throws Exception { @@ -1155,11 +1155,11 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test with J7+ Objects.hash and Objects.equals method calls * Using 1-dim array amongst other instance variables - * + * * @throws Exception */ public void testHashCodeEqualsArrayIn17() throws Exception { @@ -1294,7 +1294,7 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test with J7+ Objects.hash and Objects.equals method calls * Using 1-dim Serializable array amongst other instance variables @@ -1365,7 +1365,7 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test with J7+ Objects.hash and Objects.equals method calls * Using 1-dim Object array amongst other instance variables @@ -1434,7 +1434,7 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test with J7+ Objects.hash and Objects.equals method calls * Using 1-dim type variable arrays extending Serializable and Number @@ -1486,7 +1486,7 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test with J7+ Objects.hash and Objects.equals method calls * Using multidimensional array amongst other instance variables @@ -1555,11 +1555,11 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test with J7+ Objects.hash and Objects.equals method calls * Using both multidimensional and 1-dimensional primitive arrays amongst other instance variables - * + * * @throws Exception */ public void testHashCodeEqualsVariousArraysIn17() throws Exception { @@ -1628,11 +1628,11 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test with J7+ Objects.hash and Objects.equals method calls * Using ONLY multidimensional and 1-dimensional arrays as instance variables - * + * * @throws Exception */ public void testHashCodeEqualsOnlyArraysIn17() throws Exception { @@ -1680,7 +1680,7 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { compareSource(expected, a.getSource()); } - + /** * Test member types * @@ -1975,7 +1975,7 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { /** * Test with J7+ Objects.hash and Objects.equals method calls Using sub-type - * + * * @throws Exception */ public void testSubTypeIn17() throws Exception { @@ -2040,7 +2040,7 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { /** * Test implementation based only on super class - * + * * @throws Exception */ public void testSubTypeNoFields() throws Exception { @@ -2151,7 +2151,7 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { * @throws Exception rarely */ public void testAbstractSuperMethods() throws Exception { - + ICompilationUnit a= fPackageP.createCompilationUnit("A.java", "package p;\r\n" + "\r\n" + "abstract class Super {\r\n" + @@ -2163,10 +2163,10 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { " String name;\r\n" + "}" + "", true, null); - + IField[] fields= getFields(a.getType("Sub"), new String[] {"name" }); runOperation(a.getType("Sub"), fields, null, false, false, false, false, false); - + String expected= "package p;\r\n" + "\r\n" + "abstract class Super {\r\n" + @@ -2203,10 +2203,10 @@ public class GenerateHashCodeEqualsTest extends SourceTestCase { " }\r\n" + "}" + ""; - + compareSource(expected, a.getSource()); } - + /** * Test that generated equals() should use Arrays.deepEquals() instead of Arrays.equals() for projects with compliance >= 1.5 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=304176 diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateToStringTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateToStringTest.java index 54513fbc00..d5bac533c1 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateToStringTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateToStringTest.java @@ -176,12 +176,12 @@ public class GenerateToStringTest extends SourceTestCase { /** * Compares source with expected and asserts that no new compile errors have been created. - * + * * @param expected source * @param cu compilation unit * @param oldCUNode the old AST root * @throws Exception if test failed if test failed - * + * * @since 3.5 */ private void compareSourceAssertCompilation(String expected, ICompilationUnit cu, CompilationUnit oldCUNode) throws Exception { @@ -201,7 +201,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - basic functionality and comment - * + * * @throws Exception if test failed */ public void testConcatComment() throws Exception { @@ -242,7 +242,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - skip nulls - * + * * @throws Exception if test failed */ public void testConcatNulls() throws Exception { @@ -283,7 +283,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom array toString without limit of elements - * + * * @throws Exception if test failed */ public void testConcatArray() throws Exception { @@ -323,7 +323,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - limit of elements but not in arrays - * + * * @throws Exception if test failed */ public void testConcatLimit() throws Exception { @@ -378,7 +378,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom array toString and limit of elements - * + * * @throws Exception if test failed */ public void testConcatArrayLimit() throws Exception { @@ -436,7 +436,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom Array, limit elements, java 1.4 compatibility - * + * * @throws Exception if test failed */ public void testConcatArrayLimit1_4() throws Exception { @@ -499,7 +499,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom Array, limit elements, java 1.4 compatibility, unique variable * names needed - * + * * @throws Exception if test failed */ public void testConcatArrayLimit1_4Unique() throws Exception { @@ -555,7 +555,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom Array, limit elements, java 1.5 compatibility - * + * * @throws Exception if test failed */ public void testConcatArrayLimit1_5() throws Exception { @@ -620,7 +620,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom Array, limit elements, java 1.5 compatibility, unique names * needed - * + * * @throws Exception if test failed */ public void testConcatArrayLimit1_5Unique() throws Exception { @@ -677,7 +677,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom Array, limit elements to 0 - * + * * @throws Exception if test failed */ public void testConcatArrayLimitZero() throws Exception { @@ -730,7 +730,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom Array, limit elements to 0, skip nulls - * + * * @throws Exception if test failed */ public void testConcatArrayLimitZeroNulls() throws Exception { @@ -784,7 +784,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - 'use keyword this' and no one-line blocks - * + * * @throws Exception if test failed */ public void testConcatArrayLimitThisNoBlock() throws Exception { @@ -845,7 +845,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom array, limit elements, skip nulls - * + * * @throws Exception if test failed */ public void testConcatArrayLimitNulls() throws Exception { @@ -906,7 +906,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - custom array, limit elements, no members require helper method - * + * * @throws Exception if test failed */ public void testConcatArrayLimitNoHelpers() throws Exception { @@ -964,7 +964,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - different template - * + * * @throws Exception if test failed */ public void testConcatTemplate() throws Exception { @@ -1006,7 +1006,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string concatenation - replacing existing toString() and arrayToString(array,int), leaving * toString(Collection) - * + * * @throws Exception if test failed */ public void testConcatReplace() throws Exception { @@ -1059,7 +1059,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - skip nulls - * + * * @throws Exception if test failed */ public void testBuilderNulls() throws Exception { @@ -1089,7 +1089,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - custom array toString without limit of elements - * + * * @throws Exception if test failed */ public void testBuilderArray() throws Exception { @@ -1118,7 +1118,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - limit of elements but not in arrays - * + * * @throws Exception if test failed */ public void testBuilderLimit() throws Exception { @@ -1158,7 +1158,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - custom array toString and limit of elements - * + * * @throws Exception if test failed */ public void testBuilderArrayLimit() throws Exception { @@ -1205,7 +1205,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - custom array, limit of elements, without java 5.0 compatibility - * + * * @throws Exception if test failed */ public void testBuilderArrayLimit1_4() throws Exception { @@ -1257,7 +1257,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - custom array, limit of elements, without java 5.0 compatibility, unique * names needed - * + * * @throws Exception if test failed */ public void testBuilderArrayLimit1_4Unique() throws Exception { @@ -1304,7 +1304,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - custom array, limit of elements, skip nulls, use keyword this, no one-line * blocks - * + * * @throws Exception if test failed */ public void testBuilderArrayLimitNullsThisNoBlocks() throws Exception { @@ -1357,7 +1357,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - custom array, limit elements, skip nulls - * + * * @throws Exception if test failed */ public void testBuilderArrayLimitNulls() throws Exception { @@ -1410,7 +1410,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - custom array, limit elements, no members require helper methods - * + * * @throws Exception if test failed */ public void testBuilderArrayLimitNoHelpers() throws Exception { @@ -1452,7 +1452,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - custom array, limit elements to 0 - * + * * @throws Exception if test failed */ public void testBuilderArrayLimitZero() throws Exception { @@ -1492,7 +1492,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder - custom array, limit elements to 0, skip nulls - * + * * @throws Exception if test failed */ public void testBuilderArrayLimitZeroNulls() throws Exception { @@ -1534,7 +1534,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder, chained calls - skip nulls - * + * * @throws Exception if test failed */ public void testChainedBuilderNulls() throws Exception { @@ -1563,7 +1563,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder, chained calls - custom array toString without limit of elements - * + * * @throws Exception if test failed */ public void testChainedBuilderArray() throws Exception { @@ -1606,7 +1606,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder, chained calls - custom array toString without limit of elements, unique names * needed - * + * * @throws Exception if test failed */ public void testChainedBuilderArrayUnique() throws Exception { @@ -1657,7 +1657,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder, chained calls - custom array, limit of elements, without java 5.0 * compatibility - * + * * @throws Exception if test failed */ public void testChainedBuilderArrayLimit1_4() throws Exception { @@ -1723,7 +1723,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder, chained calls - custom array, JDK 1.5 compatybility - * + * * @throws Exception if test failed */ public void testChainedBuilderArray1_5() throws Exception { @@ -1781,7 +1781,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * string builder, chained calls - custom array, limit of elements, skip nulls, use keyword * this, no one-line blocks - * + * * @throws Exception if test failed */ public void testChainedBuilderArrayLimitNullsThisNoBlocks() throws Exception { @@ -1831,7 +1831,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * String.format() - basic test - * + * * @throws Exception if test failed */ public void testFormat() throws Exception { @@ -1872,7 +1872,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * String.format() - custom array toString without limit of elements - * + * * @throws Exception if test failed */ public void testFormatArray() throws Exception { @@ -1913,7 +1913,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * String.format() - limit of elements but not arrays - * + * * @throws Exception if test failed */ public void testFormatLimit() throws Exception { @@ -1969,7 +1969,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * String.format() - custom array toString and limit of elements - * + * * @throws Exception if test failed */ public void testFormatArrayLimit() throws Exception { @@ -2029,7 +2029,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * String.format() - custom array toString, limit of elements, JDK 1.5, no members require * helper methods - * + * * @throws Exception if test failed */ public void testFormatArrayLimit1_5NoHelpers() throws Exception { @@ -2083,7 +2083,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * String.format() - custom array toString and limit number of elements to 0 - * + * * @throws Exception if test failed */ public void testFormatArrayLimitZero() throws Exception { @@ -2137,7 +2137,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * String.format() - custom array, limit of elements, 'use keyword this' - * + * * @throws Exception if test failed */ public void testFormatLimitThis() throws Exception { @@ -2195,7 +2195,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * String.format() - custom array, limit of elements, jdk 1.4 - * + * * @throws Exception if test failed */ public void testFormatLimit1_4() throws Exception { @@ -2253,7 +2253,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - basic case - * + * * @throws Exception if test failed */ public void testCustomBuilder() throws Exception { @@ -2279,7 +2279,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - skip nulls - * + * * @throws Exception if test failed */ public void testCustomBuilderNulls() throws Exception { @@ -2307,7 +2307,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - custom array toString without limit of elements - * + * * @throws Exception if test failed */ public void testCustomBuilderArray() throws Exception { @@ -2334,7 +2334,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - limit of elements but not arrays - * + * * @throws Exception if test failed */ public void testCustomBuilderLimit() throws Exception { @@ -2373,7 +2373,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - custom array toString and limit of elements - * + * * @throws Exception if test failed */ public void testCustomBuilderArrayLimit() throws Exception { @@ -2418,7 +2418,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - custom array toString and limit of elements, unique names needed - * + * * @throws Exception if test failed */ public void testCustomBuilderArrayLimitUnique() throws Exception { @@ -2460,7 +2460,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - skip nulls, use keyword this, no one-line blocks - * + * * @throws Exception if test failed */ public void testCustomBuilderNullsThisNoBlocks() throws Exception { @@ -2499,7 +2499,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - custom array, limit elements, skip nulls - * + * * @throws Exception if test failed */ public void testCustomBuilderArrayLimitNulls() throws Exception { @@ -2547,7 +2547,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - chained calls - * + * * @throws Exception if test failed */ public void testChainedCustomBuilder() throws Exception { @@ -2592,7 +2592,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - chained calls, skip nulls - * + * * @throws Exception if test failed */ public void testChainedCustomBuilderNulls() throws Exception { @@ -2621,7 +2621,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom ToString() builder - chained calls, add comment - * + * * @throws Exception if test failed */ public void testChainedCustomBuilderComments() throws Exception { @@ -2667,7 +2667,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom toString() builder - alternative class, basic case - * + * * @throws Exception if test failed */ public void testAlternativeCustomBuilder() throws Exception { @@ -2723,7 +2723,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom toString() builder - alternative class, unique names needed - * + * * @throws Exception if test failed */ public void testAlternativeCustomBuilderUnique() throws Exception { @@ -2796,7 +2796,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom toString() builder - alternative class, skip nulls - * + * * @throws Exception if test failed */ public void testAlternativeCustomBuilderNulls() throws Exception { @@ -2859,7 +2859,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom toString() builder - alternative class, chained calls - * + * * @throws Exception if test failed */ public void testChainedAlternativeCustomBuilderCreator() throws Exception { @@ -2909,10 +2909,10 @@ public class GenerateToStringTest extends SourceTestCase { compareSourceAssertCompilation(expected, a, oldCUNode); } - + /** * string builder - custom array, limit elements, JDK1.4, use prefixes and suffixes for local variables and parameters - * + * * @throws Exception if test failed */ public void testBuilderArrayLimit1_4Prefixes() throws Exception { @@ -2922,7 +2922,7 @@ public class GenerateToStringTest extends SourceTestCase { + " A[] AArray;\r\n" + " char[] charArrayMethod() {\r\n" + " return new char[0];\r\n" + " }\r\n" + " List<Boolean> list;\r\n" + " HashMap<Integer, String> hashMap;\r\n" + " Collection<?> wildCollection;\r\n" + " Collection<Integer> integerCollection;\r\n" + " \r\n" + "}\r\n" + "", true, null); CompilationUnit oldCUNode= getCUNode(a); - + IMember[] members= getMembers(a.getType("A"), new String[] { "AArray", "hashMap", "intArray", "integerCollection", "list", "wildCollection", "charArrayMethod"}); fSettings2.customArrayToString= true; fSettings2.limitElements= true; @@ -3017,7 +3017,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom toString() builder - alternative class, chained calls, skip nulls - * + * * @throws Exception if test failed */ public void testChainedAlternativeCustomBuilderNulls() throws Exception { @@ -3081,7 +3081,7 @@ public class GenerateToStringTest extends SourceTestCase { /** * Custom toString() builder - alternative class with append method that takes only one argument * for most of the types - * + * * @throws Exception if test failed */ public void testChainedOneArgumentCustomBuilders() throws Exception { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/hover/PackageJavadocTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/hover/PackageJavadocTests.java index a4981539da..c3c41f8c48 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/hover/PackageJavadocTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/hover/PackageJavadocTests.java @@ -52,7 +52,7 @@ import org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover; /** * Tests for fetching package Javadoc. - * + * * @since 3.9 */ public class PackageJavadocTests extends CoreTests { @@ -246,7 +246,7 @@ public class PackageJavadocTests extends CoreTests { /** * Package Javadoc hover throws NullPointerException if package-info.java contains references. * This test case is to test the fix. - * + * * @throws Exception when the test case fails */ public void testPackageInfoWithReferenceLinks() throws Exception { @@ -296,7 +296,7 @@ public class PackageJavadocTests extends CoreTests { packageFragment= (IPackageFragment)codeSelect[0]; JavadocBrowserInformationControlInput hoverInfo= JavadocHover.getHoverInfo(new IJavaElement[] { packageFragment }, cu, new Region(offset, length), null); String actualHtmlContent= hoverInfo.getHtml(); - + Assert.assertTrue(actualHtmlContent, actualHtmlContent.contains(CorextMessages.JavaDocLocations_noAttachedJavadoc)); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java index f7b06db2e3..db28d08026 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/jarexport/FatJarExportTests.java @@ -585,7 +585,7 @@ public class FatJarExportTests extends TestCase { boolean found= false; if (libName.isEmpty()) { libName= ((Element)xmlZipfilesets.item(i)).getAttribute("src"); //$NON-NLS-1$ - found= libName.equals(FatJarRsrcUrlBuilder.JAR_RSRC_LOADER_ZIP); + found= libName.equals(FatJarRsrcUrlBuilder.JAR_RSRC_LOADER_ZIP); } for (String zipfileset : zipfilesets) { if (libName.equals(zipfileset)) { @@ -980,13 +980,13 @@ public class FatJarExportTests extends TestCase { assertAntScript(data, antScriptLocation(getName() + "_JiJ"), //$NON-NLS-1$ new PackageLibraryHandler(), new String[] { "TestSetupProject/bin", "testresources/externalClassFolder" }, //$NON-NLS-1$ - new String[] { "rtstubs15.jar" }); //$NON-NLS-1$ + new String[] { "rtstubs15.jar" }); //$NON-NLS-1$ // sub-folder libraries data= createAndRunFatJar(fProject, getName() + "_SL", true, new CopyLibraryHandler()); //$NON-NLS-1$ assertAntScript(data, antScriptLocation(getName() + "_SL"), //$NON-NLS-1$ new CopyLibraryHandler(), new String[] { "TestSetupProject/bin", "testresources/externalClassFolder" }, //$NON-NLS-1$ - new String[] { "rtstubs15.jar" }); //$NON-NLS-1$ + new String[] { "rtstubs15.jar" }); //$NON-NLS-1$ } finally { JavaProjectHelper.removeFromClasspath(fProject, externalRoot.getPath()); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/jarexport/PlainJarExportTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/jarexport/PlainJarExportTests.java index 8714248ea5..102c5a91b7 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/jarexport/PlainJarExportTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/jarexport/PlainJarExportTests.java @@ -61,7 +61,7 @@ public class PlainJarExportTests extends TestCase { public static Test suite() { return setUpTest(new TestSuite(THIS)); } - + public static Test setUpTest(Test test) { System.setProperty("jdt.bug.367669", "non-null"); return new ProjectTestSetup(test); @@ -101,14 +101,14 @@ public class PlainJarExportTests extends TestCase { protected void tearDown() throws Exception { JavaProjectHelper.clear(fProject, ProjectTestSetup.getDefaultClasspath()); } - - + + public void testExportCu() throws Exception { JarPackageData data= createJarPackageData(); - + data.setElements(new Object[] { fCU }); data.setExportClassFiles(true); - + ArrayList<String> entries; try (ZipFile jar= createArchive(data)) { entries= getSortedEntries(jar); @@ -127,7 +127,7 @@ public class PlainJarExportTests extends TestCase { data.setElements(new Object[] { fCU.getResource() }); data.setExportClassFiles(true); - + ArrayList<String> entries; try (ZipFile jar= createArchive(data)) { entries= getSortedEntries(jar); @@ -138,7 +138,7 @@ public class PlainJarExportTests extends TestCase { assertEquals(expected.toString(), entries.toString()); } - + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=229052 public void testExternalClassFolder() throws Exception { JarPackageData data= createJarPackageData(); @@ -173,14 +173,14 @@ public class PlainJarExportTests extends TestCase { private static ZipFile createArchive(JarPackageData data) throws Exception, CoreException { IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - + IJarExportRunnable op= data.createJarExportRunnable(window.getShell()); window.run(false, false, op); - + IStatus status= op.getStatus(); if (status.getSeverity() == IStatus.ERROR) throw new CoreException(status); - + return JarPackagerUtil.getArchiveFile(data.getJarLocation()); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/model/ContentProviderTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/model/ContentProviderTests.java index 604e13b1ec..ab2cb7a955 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/model/ContentProviderTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/model/ContentProviderTests.java @@ -140,10 +140,10 @@ public class ContentProviderTests extends TestCase { private static void assertEqualSets(String message, Object[] expected, Object[] actual) { List<Object> expList= Arrays.asList(expected); List<Object> actList= Arrays.asList(actual); - + LinkedHashSet<Object> exp= new LinkedHashSet<>(expList); LinkedHashSet<Object> act= new LinkedHashSet<>(actList); - + if (!exp.equals(act)) throw new ComparisonFailure(message, expList.toString(), actList.toString()); } @@ -172,38 +172,38 @@ public class ContentProviderTests extends TestCase { public void testOutgoingChangeInNonPackage261198() throws Exception { IProject project = (IProject)fJProject1.getResource(); - + IFolder f1= ((IFolder) fPackageFragment1.getResource()); IFolder noPackage= f1.getFolder("no-package"); noPackage.create(false, true, null); - + IFile textfile = noPackage.getFile("textfile.txt"); - textfile.create(new ByteArrayInputStream("Hi".getBytes()), false, null); - + textfile.create(new ByteArrayInputStream("Hi".getBytes()), false, null); + fMyPart.addOutgoingChange(project, "f1/no-package/textfile.txt"); - + // Children of project Object[] expectedChildren = new Object[] { fPackageFragment1 }; Object[] children = fProvider.getChildren(fJProject1); assertEqualSets("Expected children of project does not match actual children", expectedChildren, children); - + // Children of fragment 1 expectedChildren = new Object[] { noPackage }; children = fProvider.getChildren(fPackageFragment1); assertEqualSets("Expected children of f1 does not match actual children", expectedChildren, children); - + // Children of no-package expectedChildren = new Object[] { textfile }; children = fProvider.getChildren(noPackage); assertEqualSets("Expected children of no-package does not match actual children", expectedChildren, children); } - + public void testOutgoingPackageDeletion269167() throws Exception { IProject project = (IProject)fJProject1.getResource(); - + fMyPart.addOutgoingDeletion(project, "f3/"); IFolder f3= project.getFolder("f3"); - + IPackageFragment packageFragment3= (IPackageFragment)JavaCore.create(f3); LogicalPackage logicalPackage3= new LogicalPackage(packageFragment3); ResourceMapping resourceMapping= logicalPackage3.getAdapter(ResourceMapping.class); @@ -212,13 +212,13 @@ public class ContentProviderTests extends TestCase { assertEqualSets("", new IResource[] { f3 }, traversals[0].getResources()); assertEquals(IResource.DEPTH_ONE, traversals[0].getDepth()); assertEquals(0, traversals[0].getFlags()); - + // Children of project Object[] expectedChildren = new Object[] { f3 }; Object[] children = fProvider.getChildren(fJProject1); assertEqualSets("Expected children of project does not match actual children", expectedChildren, children); } - + public void testIncomingAddition159884() { IProject project = (IProject)fJProject1.getResource(); fMyPart.addIncomingAddition(project, "f1/newFolder/"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/model/MockPluginView.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/model/MockPluginView.java index 9b81688577..ba9fe5b864 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/model/MockPluginView.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/model/MockPluginView.java @@ -215,12 +215,12 @@ public class MockPluginView extends ViewPart implements INavigatorContentService IDiff diff= createOutgoingChange(project,path); add(diff); } - + private IDiff createOutgoingChange(IProject project, String path) { ResourceDiff diff= createResourceDiff(project, path, IDiff.CHANGE); return new ThreeWayDiff(diff, null); } - + private void add(IDiff diff) { ((ResourceDiffTree)fContext.getDiffTree()).add(diff); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests1.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests1.java index 50fa4d3535..ac94ecd235 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests1.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests1.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,9 +13,15 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.packageview; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.jdt.testplugin.JavaTestPlugin; @@ -55,18 +61,10 @@ import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElement; * * @since 2.1 */ -public class ContentProviderTests1 extends TestCase { - +@RunWith(JUnit4.class) +public class ContentProviderTests1{ - public static Test suite() { - TestSuite suite= new TestSuite(ContentProviderTests1.class.getName()); - //$JUnit-BEGIN$ - suite.addTestSuite(ContentProviderTests1.class); - //$JUnit-END$ - return suite; - } - private IJavaProject fJProject1; private IJavaProject fJProject2; @@ -104,49 +102,50 @@ public class ContentProviderTests1 extends TestCase { private boolean fEnableAutoBuildAfterTesting; private ICompilationUnit fCU3; - public ContentProviderTests1(String name) { - super(name); - } - //---------Test for getChildren------------------- - + @Test public void testGetChildrenProjectWithSourceFolders() throws Exception{ Object[] expectedChildren= new Object[]{fRoot1, fDotClasspathFile, fDotProjectFile}; Object[] children= fProvider.getChildren(fJProject2); assertTrue("Wrong children found for project", compareArrays(children, expectedChildren));//$NON-NLS-1$ } - + @Test public void testGetChildrentMidLevelFragment() throws Exception{ Object[] expectedChildren= new Object[]{fPack4, fPack5}; Object[] children= fProvider.getChildren(fPack3); assertTrue("Wrong children found for PackageFragment",compareArrays(children, expectedChildren));//$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragment() throws Exception{ Object[] expectedChildren= new Object[]{fCU1}; Object[] children= fProvider.getChildren(fPack2); assertTrue("Wrong children found for PackageFragment",compareArrays(children, expectedChildren));//$NON-NLS-1$ } + @Test public void testGetChildrenMidLevelFragmentInArchive() throws Exception{ Object[] expectedChildren= new Object[]{fPackJunitSamplesMoney, fCUAllTests, fCUSimpleTest, fCUVectorTest }; Object[] children= fProvider.getChildren(fPackJunitSamples); assertTrue("wrong chidren found for mid level PackageFragment in Archive", compareArrays(children, expectedChildren));//$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragmentInArchive() throws Exception{ Object[] expectedChildren= new Object[]{fCUIMoney, fCUMoney, fCUMoneyBag, fCUMoneyTest}; Object[] children= fProvider.getChildren(fPackJunitSamplesMoney); assertTrue("wrong children found for a bottom PackageFragment in PackageFragmentRoot Archive", compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenSourceFolder() throws Exception { Object[] expectedChildren = new Object[] { fPack1, fPack2, fPack3, fRoot1.getPackageFragment("")};//$NON-NLS-1$ Object[] children = fProvider.getChildren(fRoot1); assertTrue("Wrong children found for PackageFragmentRoot", compareArrays(children, expectedChildren));//$NON-NLS-1$ } + @Test public void testGetChildrenArchive(){ Object[] expectedChildren= new Object[]{fPackJunit, fArchiveFragmentRoot.getPackageFragment("")};//$NON-NLS-1$ Object[] children= fProvider.getChildren(fArchiveFragmentRoot); assertTrue("Wrong child found for PackageFragmentRoot Archive", compareArrays(children,expectedChildren));//$NON-NLS-1$ @@ -154,29 +153,34 @@ public class ContentProviderTests1 extends TestCase { //---------------Get Parent Tests----------------------------- + @Test public void testGetParentArchive() throws Exception{ Object parent= fProvider.getParent(fArchiveFragmentRoot); assertTrue("Wrong parent found for PackageFragmentRoot Archive", parent==fJProject1);//$NON-NLS-1$ } + @Test public void testGetParentMidLevelFragmentInArchive() throws Exception{ Object expectedParent= fPackJunitSamples; Object parent= fProvider.getParent(fPackJunitSamplesMoney); assertTrue("Wrong parent found for a NON top level PackageFragment in an Archive", expectedParent.equals(parent));//$NON-NLS-1$ } + @Test public void testGetParentTopLevelFragmentInArchive() throws Exception{ Object expectedParent= fPackJunit; Object parent= fProvider.getParent(fPackJunitSamples); assertTrue("Wrong parent found for a top level PackageFragment in an Archive", expectedParent.equals(parent)); //$NON-NLS-1$ } + @Test public void testGetParentTopLevelFragment() throws Exception{ Object expectedParent= fRoot1; Object parent= fProvider.getParent(fPack3); assertTrue("Wrong parent found for a top level PackageFragment", expectedParent.equals(parent));//$NON-NLS-1$ } + @Test public void testGetParentMidLevelFragment() throws Exception{ Object expectedParent= fPack3; Object parent= fProvider.getParent(fPack4); @@ -184,6 +188,7 @@ public class ContentProviderTests1 extends TestCase { } + @Test public void testDeleteBottomLevelFragment() throws Exception{ //send a delta indicating fragment deleted @@ -199,6 +204,7 @@ public class ContentProviderTests1 extends TestCase { assertEquals("No refreshes", 0, fMyPart.getRefreshedObject().size());//$NON-NLS-1$ } + @Test public void testAddBottomLevelFragment() throws Exception { IPackageFragment test= fRoot1.createPackageFragment("test", true, null);//$NON-NLS-1$ @@ -215,6 +221,7 @@ public class ContentProviderTests1 extends TestCase { assertEquals("No refreshes", 0, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$ } + @Test public void testChangedTopLevelPackageFragment() throws Exception { //send a delta indicating fragment deleted IElementChangedListener listener= (IElementChangedListener) fProvider; @@ -227,6 +234,7 @@ public class ContentProviderTests1 extends TestCase { assertEquals("No refresh happened", 0, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$ } + @Test public void testChangeBottomLevelPackageFragment() throws Exception{ //send a delta indicating fragment deleted fMyPart.clear(); @@ -240,6 +248,7 @@ public class ContentProviderTests1 extends TestCase { assertEquals("No refresh happened", 0, fMyPart.getRefreshedObject().size());//$NON-NLS-1$ } + @Test public void testRemoveCUsFromPackageFragment() throws Exception{ //send a delta indicating fragment deleted @@ -254,6 +263,7 @@ public class ContentProviderTests1 extends TestCase { assertEquals("One refresh", 1, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$ } + @Test public void testRemoveCUFromPackageFragment() throws Exception { //send a delta indicating fragment deleted @@ -269,6 +279,7 @@ public class ContentProviderTests1 extends TestCase { assertEquals("No refreshes", 0, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$ } + @Test public void testBug65240() throws Exception { IClasspathEntry[] rawClasspath= fJProject2.getRawClasspath(); IClasspathEntry src1= rawClasspath[0]; @@ -321,9 +332,8 @@ public class ContentProviderTests1 extends TestCase { /** * @see TestCase#setUp() */ - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fWorkspace= ResourcesPlugin.getWorkspace(); assertNotNull(fWorkspace); @@ -428,8 +438,8 @@ public class ContentProviderTests1 extends TestCase { /** * @see TestCase#tearDown() */ - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { fArchiveFragmentRoot.close(); JavaProjectHelper.delete(fJProject1); @@ -439,7 +449,6 @@ public class ContentProviderTests1 extends TestCase { if (fEnableAutoBuildAfterTesting) CoreUtility.setAutoBuilding(true); - super.tearDown(); } /** diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests2.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests2.java index b55a77bff5..3add860cec 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests2.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests2.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,11 +13,16 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.packageview; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.File; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.jdt.testplugin.JavaTestPlugin; @@ -52,16 +57,8 @@ import org.eclipse.jdt.internal.ui.util.CoreUtility; * * @since 2.1 */ -public class ContentProviderTests2 extends TestCase{ - - - public static Test suite() { - TestSuite suite= new TestSuite(ContentProviderTests2.class.getName()); - //$JUnit-BEGIN$ - suite.addTestSuite(ContentProviderTests2.class); - //$JUnit-END$ - return suite; - } +@RunWith(JUnit4.class) +public class ContentProviderTests2{ private IPackageFragmentRoot fRoot1; private IPackageFragment fPack1; @@ -94,52 +91,56 @@ public class ContentProviderTests2 extends TestCase{ private IWorkbenchPage page; private boolean fEnableAutoBuildAfterTesting; - public ContentProviderTests2(String name) { - super(name); - } - + @Test public void testGetChildrenProject() throws Exception{ Object[] expectedChildren= new Object[]{fPack1, fPack2, fPack3, fRoot1.getPackageFragment(""), fFile1, fFile2,fInternalRoot1,jdk}; //$NON-NLS-1$ Object[] children= fProvider.getChildren(fJProject3); assertTrue("Wrong children found for project", compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrentMidLevelFragment() throws Exception{ Object[] expectedChildren= new Object[]{fPack4, fPack5}; Object[] children= fProvider.getChildren(fPack3); assertTrue("Wrong children found for PackageFragment",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragment() throws Exception{ Object[] expectedChildren= new Object[]{}; Object[] children= fProvider.getChildren(fPack1); assertTrue("Wrong children found for PackageFragment",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragmentWithCU() throws Exception{ Object[] expectedChildren= new Object[]{fCU1}; Object[] children= fProvider.getChildren(fPack2); assertTrue("Wrong children found for PackageFragment with CU",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragmentFile() throws Exception{ Object[] expectedChildren= new Object[]{}; Object[] children= fProvider.getChildren(fPack1); assertTrue("Wrong children found for PackageFragment with File",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragment2() throws Exception{ Object[] expectedChildren= new Object[]{fCU2}; Object[] children= fProvider.getChildren(fPack6); assertTrue("Wrong children found for PackageFragment",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenMidLevelFragmentInInternalArchive() throws Exception{ Object[] expectedChildren= new Object[]{fC}; Object[] children= fProvider.getChildren(fB); assertTrue("wrong children found for a NON bottom PackageFragment in PackageFragmentRoot Internal Archive", compareArrays(children, expectedChildren));//$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragmentInInternalArchive() throws Exception{ Object[] expectedChildren= new Object[]{fYClassFile}; Object[] children= fProvider.getChildren(fY); @@ -154,29 +155,34 @@ public class ContentProviderTests2 extends TestCase{ //---------------Get Parent Tests----------------------------- + @Test public void testGetParentArchive() throws Exception{ Object parent= fProvider.getParent(fInternalRoot1); assertTrue("Wrong parent found for PackageFragmentRoot Archive", parent==fJProject3); //$NON-NLS-1$ } + @Test public void testGetParentMidLevelFragmentInArchive() throws Exception{ Object expectedParent= fB; Object parent= fProvider.getParent(fC); assertTrue("Wrong parent found for a NON top level PackageFragment in an Archive", expectedParent.equals(parent)); //$NON-NLS-1$ } + @Test public void testGetParentTopLevelFragmentInArchive() throws Exception{ Object expectedParent= fInternalRoot1; Object parent= fProvider.getParent(fA); assertTrue("Wrong parent found for a top level PackageFragment in an Archive", expectedParent.equals(parent)); //$NON-NLS-1$ } + @Test public void testGetParentTopLevelFragment() throws Exception{ Object expectedParent= fJProject3; Object parent= fProvider.getParent(fPack3); assertTrue("Wrong parent found for a top level PackageFragment", expectedParent.equals(parent)); //$NON-NLS-1$ } + @Test public void testGetParentMidLevelFragment() throws Exception{ Object expectedParent= fPack3; Object parent= fProvider.getParent(fPack5); @@ -189,9 +195,8 @@ public class ContentProviderTests2 extends TestCase{ * @see TestCase#setUp() */ - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fWorkspace= ResourcesPlugin.getWorkspace(); @@ -287,8 +292,8 @@ public class ContentProviderTests2 extends TestCase{ /** * @see TestCase#tearDown() */ - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { fInternalRoot1.close(); JavaProjectHelper.delete(fJProject3); page.hideView(fMyPart); @@ -296,7 +301,6 @@ public class ContentProviderTests2 extends TestCase{ if (fEnableAutoBuildAfterTesting) CoreUtility.setAutoBuilding(true); - super.tearDown(); } /** diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests3.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests3.java index 06e1aecd7c..8ff8fcaeab 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests3.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests3.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,11 +13,17 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.packageview; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.File; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.jdt.testplugin.JavaTestPlugin; @@ -54,17 +60,8 @@ import org.eclipse.jdt.internal.ui.util.CoreUtility; * * @since 2.1 */ -public class ContentProviderTests3 extends TestCase { - - - public static Test suite() { - TestSuite suite= new TestSuite(ContentProviderTests3.class.getName()); - //$JUnit-BEGIN$ - suite.addTestSuite(ContentProviderTests3.class); - //$JUnit-END$ - return suite; - } - +@RunWith(JUnit4.class) +public class ContentProviderTests3{ private IJavaProject fJProject1; private IJavaProject fJProject2; @@ -106,12 +103,9 @@ public class ContentProviderTests3 extends TestCase { private IPackageFragmentRoot jdk; private boolean fEnableAutoBuildAfterTesting; - public ContentProviderTests3(String name) { - super(name); - } - //---------Test for getChildren------------------- + @Test public void testGetChildrenProjectWithSourceFolders() throws Exception{ Object[] expectedChildren= new Object[]{fRoot1, fFile1, fFile2, jdk}; Object[] children= fProvider.getChildren(fJProject2); @@ -119,12 +113,14 @@ public class ContentProviderTests3 extends TestCase { } + @Test public void testGetChildrentMidLevelFragment() throws Exception{ Object[] expectedChildren= new Object[]{fPack4, fPack6}; Object[] children= fProvider.getChildren(fPack3); assertTrue("Wrong children found for PackageFragment with folding",compareArrays(children, expectedChildren));//$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragment() throws Exception{ Object[] expectedChildren= new Object[]{}; Object[] children= fProvider.getChildren(fPack1); @@ -132,24 +128,28 @@ public class ContentProviderTests3 extends TestCase { } + @Test public void testGetChildrenBottomLevelFragmentWithCU() throws Exception{ Object[] expectedChildren= new Object[]{fCU1}; Object[] children= fProvider.getChildren(fPack2); assertTrue("Wrong children found for PackageFragment with folding",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragmentInArchive() throws Exception{ Object[] expectedChildren= new Object[]{fCUIMoney, fCUMoney, fCUMoneyBag, fCUMoneyTest}; Object[] children= fProvider.getChildren(fPackJunitSamplesMoney); assertTrue("wrong children found for a bottom PackageFragment in PackageFragmentRoot Archive with folding", compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenSource() throws Exception{ Object[] expectedChildren= new Object[]{fPack1,fPack2,fPack3, fRoot1.getPackageFragment("")};//$NON-NLS-1$ Object[] children= fProvider.getChildren(fRoot1); assertTrue("Wrong children found for PackageFragmentRoot with folding", compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenArchive(){ Object[] expectedChildren= new Object[]{fPackJunit, fArchiveFragmentRoot.getPackageFragment("")};//$NON-NLS-1$ Object[] children= fProvider.getChildren(fArchiveFragmentRoot); @@ -159,23 +159,27 @@ public class ContentProviderTests3 extends TestCase { //---------------Get Parent Tests----------------------------- + @Test public void testGetParentArchive() throws Exception{ Object parent= fProvider.getParent(fArchiveFragmentRoot); assertTrue("Wrong parent found for PackageFragmentRoot Archive with folding", parent==fJProject1);//$NON-NLS-1$ } + @Test public void testGetParentTopLevelFragmentInArchive() throws Exception{ Object expectedParent= fPackJunit; Object parent= fProvider.getParent(fPackJunitSamples); assertTrue("Wrong parent found for a top level PackageFragment in an Archive with folding", expectedParent.equals(parent)); //$NON-NLS-1$ } + @Test public void testGetParentTopLevelFragment() throws Exception{ Object expectedParent= fRoot1; Object parent= fProvider.getParent(fPack3); assertTrue("Wrong parent found for a top level PackageFragment with folding", expectedParent.equals(parent)); //$NON-NLS-1$ } + @Test public void testGetParentFoldedBottomFragment() throws Exception{ Object expectedParent= fRoot1; Object parent= fProvider.getParent(fPack3); @@ -183,12 +187,14 @@ public class ContentProviderTests3 extends TestCase { } + @Test public void testGetParentMidLevelFragment() throws Exception{ Object expectedParent= fPack3; Object parent= fProvider.getParent(fPack4); assertTrue("Wrong parent found for a NON top level PackageFragment with folding", expectedParent.equals(parent));//$NON-NLS-1$ } + @Test public void testDeleteBottomLevelFragmentFolding() throws Exception { //send a delta indicating fragment deleted @@ -204,6 +210,7 @@ public class ContentProviderTests3 extends TestCase { assertTrue("Single refresh", fMyPart.getRefreshedObject().size() == 1); //$NON-NLS-1$ } + @Test public void testAddBottomLevelFragmentFolding() throws Exception { IPackageFragment test= fRoot1.createPackageFragment("test", true, null); //$NON-NLS-1$ @@ -222,6 +229,7 @@ public class ContentProviderTests3 extends TestCase { assertTrue("Single refresh", fMyPart.getRefreshedObject().size() == 1); //$NON-NLS-1$ } + @Test public void testChangedTopLevelPackageFragmentFolding() throws Exception { //send a delta indicating fragment deleted IElementChangedListener listener= (IElementChangedListener) fProvider; @@ -235,6 +243,7 @@ public class ContentProviderTests3 extends TestCase { assertEquals("No refreshs", 0, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$ } + @Test public void testChangeBottomLevelPackageFragmentFolding() throws Exception { //send a delta indicating fragment deleted IElementChangedListener listener= (IElementChangedListener) fProvider; @@ -248,6 +257,7 @@ public class ContentProviderTests3 extends TestCase { assertEquals("No refreshs",0, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$ } + @Test public void testRemoveCUsFromPackageFragment() throws Exception{ //send a delta indicating fragment deleted @@ -263,6 +273,7 @@ public class ContentProviderTests3 extends TestCase { assertEquals("One refresh", 1, fMyPart.getRefreshedObject().size()); //$NON-NLS-1$ } + @Test public void testRemoveCUFromPackageFragment() throws Exception { //send a delta indicating fragment deleted @@ -283,9 +294,8 @@ public class ContentProviderTests3 extends TestCase { /* * @see TestCase#setUp() */ - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fWorkspace= ResourcesPlugin.getWorkspace(); assertNotNull(fWorkspace); @@ -405,8 +415,8 @@ public class ContentProviderTests3 extends TestCase { /** * @see TestCase#tearDown() */ - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { fArchiveFragmentRoot.close(); JavaProjectHelper.delete(fJProject1); JavaProjectHelper.delete(fJProject2); @@ -415,7 +425,6 @@ public class ContentProviderTests3 extends TestCase { if (fEnableAutoBuildAfterTesting) CoreUtility.setAutoBuilding(true); - super.tearDown(); } /** diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests4.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests4.java index 731d54e046..5ceea38e51 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests4.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests4.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,11 +13,16 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.packageview; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.File; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.jdt.testplugin.JavaTestPlugin; @@ -52,16 +57,8 @@ import org.eclipse.jdt.internal.ui.util.CoreUtility; * * @since 2.1 */ -public class ContentProviderTests4 extends TestCase{ - - public static Test suite() { - TestSuite suite= new TestSuite(ContentProviderTests4.class.getName()); - //$JUnit-BEGIN$ - suite.addTestSuite(ContentProviderTests4.class); - //$JUnit-END$ - return suite; - } - +@RunWith(JUnit4.class) +public class ContentProviderTests4{ private IPackageFragmentRoot fRoot1; private IPackageFragment fPack1; @@ -98,52 +95,56 @@ public class ContentProviderTests4 extends TestCase{ private File myInternalLibJar; private boolean fEnableAutoBuildAfterTesting; - public ContentProviderTests4(String name) { - super(name); - } - + @Test public void testGetChildrenProject() throws Exception{ Object[] expectedChildren= new Object[]{fPack1, fPack2, fPack3, fDefaultPackage, fFile1, fFile2,fInternalRoot1,jdk}; Object[] children= fProvider.getChildren(fJProject3); assertTrue("Wrong children found for project with folding", compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenDefaultProject(){ Object[] expectedChildren= new Object[]{fCUinDefault}; Object[] children= fProvider.getChildren(fDefaultPackage); assertTrue("Wrong children found for default package with folding", compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrentMidLevelFragment() throws Exception{ Object[] expectedChildren= new Object[]{fPack4, fPack6}; Object[] children= fProvider.getChildren(fPack3); assertTrue("Wrong children found for PackageFragment with folding",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragment() throws Exception{ Object[] expectedChildren= new Object[]{}; Object[] children= fProvider.getChildren(fPack1); assertTrue("Wrong children found for PackageFragment with folding",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragmentWithCU() throws Exception{ Object[] expectedChildren= new Object[]{fCU1}; Object[] children= fProvider.getChildren(fPack2); assertTrue("Wrong children found for PackageFragment with folding",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragmenWithCU2() throws Exception{ Object[] expectedChildren= new Object[]{fCU2}; Object[] children= fProvider.getChildren(fPack6); assertTrue("Wrong children found for PackageFragment with folding",compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenMidLevelFragmentInInternalArchive() throws Exception{ Object[] expectedChildren= new Object[]{fC, fD, fAClassFile}; Object[] children= fProvider.getChildren(fA); assertTrue("wrong children found for a NON bottom PackageFragment in PackageFragmentRoot Internal Archive with folding", compareArrays(children, expectedChildren)); //$NON-NLS-1$ } + @Test public void testGetChildrenBottomLevelFragmentInInternalArchive() throws Exception{ Object[] expectedChildren= new Object[]{fYClassFile}; Object[] children= fProvider.getChildren(fY); @@ -158,35 +159,41 @@ public class ContentProviderTests4 extends TestCase{ //---------------Get Parent Tests----------------------------- + @Test public void testGetParentArchive() throws Exception{ Object parent= fProvider.getParent(fInternalRoot1); assertTrue("Wrong parent found for PackageFragmentRoot Archive with folding", parent==fJProject3);//$NON-NLS-1$ } + @Test public void testGetParentMidLevelFragmentInArchive() throws Exception{ Object expectedParent= fA; Object parent= fProvider.getParent(fC); assertTrue("Wrong parent found for a NON top level PackageFragment in an Archive with folding", expectedParent.equals(parent));//$NON-NLS-1$ } + @Test public void testGetParentTopLevelFragmentInArchive() throws Exception{ Object expectedParent= fInternalRoot1; Object parent= fProvider.getParent(fA); assertTrue("Wrong parent found for a top level PackageFragment in an Archive with folding", expectedParent.equals(parent)); //$NON-NLS-1$ } + @Test public void testGetParentTopLevelFragment() throws Exception{ Object expectedParent= fJProject3; Object parent= fProvider.getParent(fPack3); assertTrue("Wrong parent found for a top level PackageFragment with folding", expectedParent.equals(parent));//$NON-NLS-1$ } + @Test public void testGetParentMidLevelFragment() throws Exception{ Object expectedParent= fPack3; Object parent= fProvider.getParent(fPack6); assertTrue("Wrong parent found for a NON top level PackageFragment with folding", expectedParent.equals(parent));//$NON-NLS-1$ } + @Test public void testGetParentMidLevelFragment2() throws Exception{ Object expectedParent= fPack3; Object parent= fProvider.getParent(fPack5); @@ -199,10 +206,8 @@ public class ContentProviderTests4 extends TestCase{ * @see TestCase#setUp() */ - @Override - protected void setUp() throws Exception { - super.setUp(); - + @Before + public void setUp() throws Exception { fWorkspace= ResourcesPlugin.getWorkspace(); assertNotNull(fWorkspace); IWorkspaceDescription workspaceDesc= fWorkspace.getDescription(); @@ -300,8 +305,8 @@ public class ContentProviderTests4 extends TestCase{ /** * @see TestCase#tearDown() */ - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { fInternalRoot1.close(); JavaProjectHelper.delete(fJProject3); @@ -310,7 +315,6 @@ public class ContentProviderTests4 extends TestCase{ if (fEnableAutoBuildAfterTesting) CoreUtility.setAutoBuilding(true); - super.tearDown(); } /** diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests5.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests5.java index 1fdad128a2..59814a69f4 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests5.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests5.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,13 +13,20 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.packageview; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; import java.util.Arrays; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; @@ -64,7 +71,8 @@ import org.eclipse.jdt.internal.ui.util.CoreUtility; * * @since 3.0+ */ -public class ContentProviderTests5 extends TestCase{ +@RunWith(JUnit4.class) +public class ContentProviderTests5{ private boolean fEnableAutoBuildAfterTesting; private ITreeContentProvider fProvider; @@ -73,17 +81,8 @@ public class ContentProviderTests5 extends TestCase{ private IFile fDotProject; private IPackageFragmentRoot jdk; - public ContentProviderTests5(String name) { - super(name); - } - - public static Test suite() { - return new TestSuite(ContentProviderTests5.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { IWorkspace workspace= ResourcesPlugin.getWorkspace(); assertNotNull(workspace); @@ -138,9 +137,8 @@ public class ContentProviderTests5 extends TestCase{ JavaPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.APPEARANCE_FOLD_PACKAGES_IN_PACKAGE_EXPLORER, fold); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { JavaProjectHelper.delete(fJProject); if (fEnableAutoBuildAfterTesting) @@ -151,6 +149,7 @@ public class ContentProviderTests5 extends TestCase{ return new ByteArrayInputStream(string.getBytes(ResourcesPlugin.getEncoding())); } + @Test public void testProjectSource1() throws Exception { //bug 35851, 66694 IPath[] inclusionFilters= {new Path("**"), new Path("excl/incl/")}; IPath[] exclusionFilters= {new Path("excl/*"), new Path("x/*.java"), new Path("y/")}; @@ -201,6 +200,7 @@ public class ContentProviderTests5 extends TestCase{ assertEqualElements(new Object[] {yX, yhidden}, fProvider.getChildren(y)); } + @Test public void testNestedSource1() throws Exception { //bug 35851, 66694 // <classpathentry excluding="a-b/a/b/" kind="src" path="src"/> // <classpathentry kind="src" path="src/a-b/a/b"/> @@ -236,6 +236,7 @@ public class ContentProviderTests5 extends TestCase{ assertEqualElements(new Object[] {b}, fProvider.getChildren(defaultAbab)); } + @Test public void testInclExcl1() throws Exception { //bug 35851, 66694 // <classpathentry including="a/b/c/" excluding="a/b/c/d/" kind="src" path="src2"/> IPath[] inclusionFilters= {new Path("a/b/c/")}; diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java index 8c42a7ffee..c88547b5fc 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests6.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,11 +13,16 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.packageview; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayInputStream; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; @@ -53,10 +58,11 @@ import org.eclipse.jdt.internal.ui.util.CoreUtility; * <ul> * <li>Bug 357450: Class folder in Java project have refresh problem</li> * </ul> - * + * * @since 3.9 */ -public class ContentProviderTests6 extends TestCase { +@RunWith(JUnit4.class) +public class ContentProviderTests6 { private boolean fEnableAutoBuildAfterTesting; private IWorkbenchPage page; @@ -67,19 +73,7 @@ public class ContentProviderTests6 extends TestCase { private IJavaProject fJProject; private IPackageFragmentRoot classFolder; - - public ContentProviderTests6(String name) { - super(name); - } - - public static Test suite() { - TestSuite suite= new TestSuite(ContentProviderTests6.class.getName()); - //$JUnit-BEGIN$ - suite.addTestSuite(ContentProviderTests6.class); - //$JUnit-END$ - return suite; - } - + @Test public void testAddFileToClassFolder() throws Exception { IFile file= ((IFolder)classFolder.getResource()).getFile("testFile.class"); //$NON-NLS-1$ if (!file.exists()) { @@ -100,6 +94,7 @@ public class ContentProviderTests6 extends TestCase { assertions(); } + @Test public void testAddFolderToClassFolder() throws Exception { IFolder folder= ((IFolder)classFolder.getResource()).getFolder("testFolder"); //$NON-NLS-1$ if (!folder.exists()) { @@ -120,6 +115,7 @@ public class ContentProviderTests6 extends TestCase { assertions(); } + @Test public void testRemoveFileFromClassFolder() throws Exception { IFile file= ((IFolder)classFolder.getResource()).getFile("testFile.class"); //$NON-NLS-1$ if (!file.exists()) { @@ -141,6 +137,7 @@ public class ContentProviderTests6 extends TestCase { assertions(); } + @Test public void testRemoveFolderFromClassFolder() throws Exception { IFolder folder= ((IFolder)classFolder.getResource()).getFolder("testFolder"); //$NON-NLS-1$ if (!folder.exists()) { @@ -162,6 +159,7 @@ public class ContentProviderTests6 extends TestCase { assertions(); } + @Test public void testChangeClassInProject() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject, "src"); IPackageFragment pack1= sourceFolder.createPackageFragment("pack1", false, null); @@ -191,9 +189,8 @@ public class ContentProviderTests6 extends TestCase { /* * @see TestCase#setUp() */ - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { IWorkspaceDescription workspaceDesc= ResourcesPlugin.getWorkspace().getDescription(); fEnableAutoBuildAfterTesting= workspaceDesc.isAutoBuilding(); if (fEnableAutoBuildAfterTesting) @@ -229,9 +226,8 @@ public class ContentProviderTests6 extends TestCase { /** * @see TestCase#tearDown() */ - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { JavaProjectHelper.delete(fJProject); if (fEnableAutoBuildAfterTesting) CoreUtility.setAutoBuilding(true); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests7.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests7.java index 7d6d6ac66f..75dfc17013 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests7.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/ContentProviderTests7.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 GK Software AG, and others. + * Copyright (c) 2017, 2020 GK Software AG, and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,15 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.packageview; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.core.runtime.IPath; @@ -32,44 +41,27 @@ import org.eclipse.jdt.internal.core.ClasspathAttribute; import org.eclipse.jdt.internal.ui.packageview.PackageExplorerContentProvider; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - - /** * Tests for the PackageExplorerContentProvider. * <ul> * <li>Bug 501507: [1.9] Consider displaying the module-info.java file in the source folder root * </ul> - * + * * @since 3.14 */ -public class ContentProviderTests7 extends TestCase { +@RunWith(JUnit4.class) +public class ContentProviderTests7 { private static Object[] NO_CHILDREN= new Object[0]; private IJavaProject fJProject; private IPackageFragmentRoot fSrcFolder; - - public ContentProviderTests7(String name) { - super(name); - } - - public static Test suite() { - TestSuite suite= new TestSuite(ContentProviderTests7.class.getName()); - //$JUnit-BEGIN$ - suite.addTestSuite(ContentProviderTests7.class); - //$JUnit-END$ - return suite; - } - // test matrix: // Criterion (true/false): NameSegment: - // no ordinary CU in dlft package / with ordinary CU in dflt package = Module1 / Module2 + // no ordinary CU in dlft package / with ordinary CU in dflt package = Module1 / Module2 // hierarchical layout / flat layout = Hierarchical / Flat - // empty module-info / real module = Empty / + // empty module-info / real module = Empty / // Checking in each test: // - children of fSrcFolder // - children of the default package @@ -90,10 +82,10 @@ public class ContentProviderTests7 extends TestCase { } private void createEmptyClass(IPackageFragment fragment, String name, String packageName) throws JavaModelException { - String packDecl= packageName != null ? "package "+packageName+";\n" : ""; + String packDecl= packageName != null ? "package "+packageName+";\n" : ""; fragment.createCompilationUnit(name+".java", packDecl+"public class "+name+" {}\n", true, null); } - + private IJavaElement getModuleInfo() { return fSrcFolder.getPackageFragment("").getCompilationUnit("module-info.java"); } @@ -103,12 +95,13 @@ public class ContentProviderTests7 extends TestCase { provider.setIsFlatLayout(isFlatLayout); return provider.getChildren(src); } - + private void assertResults(Object[][] actual, Object[] expectedSrcFolderChildren, Object[] expectedDefaultPkgChildren) { assertTrue("Wrong children found for source folder", compareArrays(actual[0], expectedSrcFolderChildren)); assertTrue("Wrong children found for default package", compareArrays(actual[1], expectedDefaultPkgChildren));//$NON-NLS-1$ } + @Test public void testModule1EmptyHierarchical() throws Exception { Object[][] actualResult= runTest(false, false, false); Object[] expectedChildren= new Object[] { @@ -118,6 +111,7 @@ public class ContentProviderTests7 extends TestCase { assertResults(actualResult, expectedChildren, NO_CHILDREN); } + @Test public void testModule1Hierarchical() throws Exception { Object[][] actualResult= runTest(false, false, true); Object[] expectedChildren= new Object[]{ @@ -127,6 +121,7 @@ public class ContentProviderTests7 extends TestCase { assertResults(actualResult, expectedChildren, NO_CHILDREN); } + @Test public void testModule1EmptyFlat() throws Exception { Object[][] actualResult= runTest(false, true, false); Object[] expectedChildren= new Object[] { @@ -136,7 +131,8 @@ public class ContentProviderTests7 extends TestCase { }; assertResults(actualResult, expectedChildren, NO_CHILDREN); } - + + @Test public void testModule1Flat() throws Exception { Object[][] actualResult= runTest(false, true, true); Object[] expectedChildren= new Object[] { @@ -147,6 +143,7 @@ public class ContentProviderTests7 extends TestCase { assertResults(actualResult, expectedChildren, NO_CHILDREN); } + @Test public void testModule2EmptyHierarchical() throws Exception { Object[][] actualResult= runTest(true, false, false); createEmptyClass(fSrcFolder.getPackageFragment(""), "DefC", null); @@ -158,6 +155,7 @@ public class ContentProviderTests7 extends TestCase { assertResults(actualResult, expectedChildren, new Object[] {fSrcFolder.getPackageFragment("").getCompilationUnit("DefC.java") } ); } + @Test public void testModule2Hierarchical() throws Exception { Object[][] actualResult= runTest(true, false, true); Object[] expectedChildren= new Object[] { @@ -167,7 +165,8 @@ public class ContentProviderTests7 extends TestCase { }; assertResults(actualResult, expectedChildren, new Object[] {fSrcFolder.getPackageFragment("").getCompilationUnit("DefC.java") } ); } - + + @Test public void testModule2EmptyFlat() throws Exception { Object[][] actualResult= runTest(true, true, false); Object[] expectedChildren= new Object[] { @@ -179,6 +178,7 @@ public class ContentProviderTests7 extends TestCase { assertResults(actualResult, expectedChildren, new Object[] {fSrcFolder.getPackageFragment("").getCompilationUnit("DefC.java") } ); } + @Test public void testModule2Flat() throws Exception { Object[][] actualResult= runTest(true, true, true); Object[] expectedChildren= new Object[] { @@ -193,9 +193,8 @@ public class ContentProviderTests7 extends TestCase { /* * @see TestCase#setUp() */ - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fJProject= JavaProjectHelper.createJavaProject("TestProject", "bin");//$NON-NLS-1$//$NON-NLS-2$ assertNotNull("project null", fJProject);//$NON-NLS-1$ IPath[] rtJarPath= JavaProjectHelper.findRtJar(JavaProjectHelper.RT_STUBS_9); @@ -251,9 +250,8 @@ public class ContentProviderTests7 extends TestCase { /** * @see TestCase#tearDown() */ - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { JavaProjectHelper.delete(fJProject); } }
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/HierarchicalContentProviderTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/HierarchicalContentProviderTests.java index 6c6ee16d0a..d3e7fe8cda 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/HierarchicalContentProviderTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/HierarchicalContentProviderTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -20,9 +20,17 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExternalResource; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.jdt.testplugin.JavaTestPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.IClassFile; @@ -38,15 +46,10 @@ import org.eclipse.jdt.ui.PreferenceConstants; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.packageview.PackageExplorerContentProvider; -import junit.extensions.TestSetup; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - +@RunWith(JUnit4.class) +public class HierarchicalContentProviderTests { -public class HierarchicalContentProviderTests extends TestCase { - - private static class MyTestSetup extends TestSetup { + private static class MyTestSetup extends ExternalResource { public static IJavaProject fJProject; public static IPackageFragmentRoot fJAR; @@ -54,11 +57,8 @@ public class HierarchicalContentProviderTests extends TestCase { public static List<String> fExpectedInJAR, fExpectedInCF; - public MyTestSetup(Test test) { - super(test); - } @Override - protected void setUp() throws Exception { + protected void before() throws Exception { fJProject= JavaProjectHelper.createJavaProject("Testing", "bin"); JavaProjectHelper.addRTJar(fJProject); @@ -83,38 +83,21 @@ public class HierarchicalContentProviderTests extends TestCase { } @Override - protected void tearDown() throws Exception { - JavaProjectHelper.delete(fJProject); + protected void after() { + try { + JavaProjectHelper.delete(fJProject); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } fExpectedInJAR= null; fExpectedInCF= null; } } - private static final Class<HierarchicalContentProviderTests> THIS= HierarchicalContentProviderTests.class; - - public HierarchicalContentProviderTests(String name) { - super(name); - } - - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } - - public static Test setUpTest(Test test) { - return new MyTestSetup(test); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Rule + public MyTestSetup mytestsetup=new MyTestSetup(); private static void testAndAdd(Object curr, List<String> res) { if (curr instanceof ICompilationUnit || curr instanceof IClassFile) { @@ -123,21 +106,25 @@ public class HierarchicalContentProviderTests extends TestCase { } } + @Test public void testJARHierarchical() { List<String> res= collectChildren(MyTestSetup.fJAR, false, false); assertEquals(MyTestSetup.fExpectedInJAR, res); } + @Test public void testJARFoldedHierarchical() { List<String> res= collectChildren(MyTestSetup.fJAR, true, false); assertEquals(MyTestSetup.fExpectedInJAR, res); } + @Test public void testClassFolderHierarchical() { List<String> res= collectChildren(MyTestSetup.fClassfolder, false, false); assertEquals(MyTestSetup.fExpectedInCF, res); } + @Test public void testClassFolderFoldedHierarchical() { List<String> res= collectChildren(MyTestSetup.fClassfolder, true, false); assertEquals(MyTestSetup.fExpectedInCF, res); @@ -147,7 +134,7 @@ public class HierarchicalContentProviderTests extends TestCase { private void assertEquals(List<String> expected, List<String> current) { - assertEquals(getString(expected), getString(current)); + Assert.assertEquals(getString(expected), getString(current)); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/MockPluginView.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/MockPluginView.java index eac00fc705..0cff3bd978 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/MockPluginView.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/MockPluginView.java @@ -137,7 +137,7 @@ public class MockPluginView extends PackageExplorerPart { fAddedObject= object; fAddedParentObject= parentObject; } - + @Override public Widget[] testFindItems(Object element) { return new Widget[1]; // for https://bugs.eclipse.org/311212 @@ -146,7 +146,7 @@ public class MockPluginView extends PackageExplorerPart { /** * Returns whether the given object was refreshed. - * + * * @param c the object to test * @return <code>true</code> if the object was refreshed */ @@ -207,7 +207,7 @@ public class MockPluginView extends PackageExplorerPart { /** * Sets the folding preference. - * + * * @param fold <code>true</code> to enable folding, <code>false</code> otherwise */ public void setFolding(boolean fold) { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageCacheTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageCacheTest.java index d0021e7311..250da87ee5 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageCacheTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageCacheTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 Simeon Andreev and others. + * Copyright (c) 2017, 2020 Simeon Andreev and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.packageview; +import static org.junit.Assert.assertEquals; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -20,7 +22,11 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.junit.After; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; @@ -34,13 +40,12 @@ import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.internal.ui.packageview.PackageCache; -import junit.framework.TestCase; - /** * Tests for {@link PackageCache}. * */ -public class PackageCacheTest extends TestCase { +@RunWith(JUnit4.class) +public class PackageCacheTest { private IJavaProject testProject; @@ -58,9 +63,8 @@ public class PackageCacheTest extends TestCase { private PackageCache packageCache; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { IProgressMonitor monitor= new NullProgressMonitor(); @@ -81,10 +85,9 @@ public class PackageCacheTest extends TestCase { packageCache= new PackageCache(src); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { testProject.getProject().delete(true, false, new NullProgressMonitor()); - super.tearDown(); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerShowInTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerShowInTests.java index 8348571dfb..c0f0562713 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerShowInTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerShowInTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,8 +14,17 @@ package org.eclipse.jdt.ui.tests.packageview; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayInputStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.core.runtime.IAdaptable; @@ -39,44 +48,30 @@ import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jdt.ui.tests.core.ProjectTestSetup; +import org.eclipse.jdt.ui.tests.core.rules.ProjectTestSetup; import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class PackageExplorerShowInTests extends TestCase { - private static final Class<PackageExplorerShowInTests> clazz= PackageExplorerShowInTests.class; - - public PackageExplorerShowInTests(String name) { - super(name); - } - - public static Test suite() { - return new ProjectTestSetup(new TestSuite(clazz)); - } - - public static Test setUpTest(Test someTest) { - return new ProjectTestSetup(someTest); - } +@RunWith(JUnit4.class) +public class PackageExplorerShowInTests { + @Rule + public ProjectTestSetup pts=new ProjectTestSetup(); private IJavaProject fJProject; private PackageExplorerPart fPackageExplorer; private IWorkbenchPage fPage; - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { fJProject= ProjectTestSetup.getProject(); fPage= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); fPackageExplorer= (PackageExplorerPart) fPage.showView(JavaUI.ID_PACKAGES); fPackageExplorer.selectAndReveal(new StructuredSelection()); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { JavaProjectHelper.clear(fJProject, ProjectTestSetup.getDefaultClasspath()); fPage.hideView(fPackageExplorer); fPage= null; @@ -87,45 +82,47 @@ public class PackageExplorerShowInTests extends TestCase { ////////////TODO: should also test non-UI part of tryToReveal(..) /////////////////////////////// + @Test public void testCU() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject, "src"); IPackageFragment pack= sourceFolder.createPackageFragment("p", true, null); ICompilationUnit cu= pack.createCompilationUnit("A.java", "package p;\nclass A {\n\n}", true, null); - + IStructuredSelection selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(cu)); assertEquals(1, selection.size()); assertEquals(cu, selection.getFirstElement()); - + selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(pack)); assertEquals(1, selection.size()); assertEquals(pack, selection.getFirstElement()); - + selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(sourceFolder)); assertEquals(1, selection.size()); assertEquals(sourceFolder, selection.getFirstElement()); - + selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(fJProject)); assertEquals(1, selection.size()); assertEquals(fJProject, selection.getFirstElement()); - + // check corresponding resources: selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(cu.getResource())); assertEquals(1, selection.size()); assertEquals(cu, selection.getFirstElement()); - + selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(pack.getResource())); assertEquals(1, selection.size()); assertEquals(pack, selection.getFirstElement()); - + selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(sourceFolder.getResource())); assertEquals(1, selection.size()); assertEquals(sourceFolder, selection.getFirstElement()); - + selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(fJProject.getProject())); assertEquals(1, selection.size()); assertEquals(fJProject, selection.getFirstElement()); } + @Test public void testCUAdaptedCU() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject, "src"); IPackageFragment pack= sourceFolder.createPackageFragment("p", true, null); @@ -148,6 +145,7 @@ public class PackageExplorerShowInTests extends TestCase { } + @Test public void testCUAdaptedResource() throws Exception { IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fJProject, "src"); IPackageFragment pack= sourceFolder.createPackageFragment("p", true, null); @@ -169,26 +167,27 @@ public class PackageExplorerShowInTests extends TestCase { assertEquals(cu, selection.getFirstElement()); } + @Test public void testCUNotOnClasspath() throws Exception { IFolder folder= fJProject.getProject().getFolder("folder"); folder.create(true, true, null); IFile file= folder.getFile("A.java"); file.create(new ByteArrayInputStream("package p;\nclass A {\n\n}".getBytes()), true, null); - + IStructuredSelection selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(file)); assertEquals(1, selection.size()); assertEquals(file, selection.getFirstElement()); - + IEditorPart editor= EditorUtility.openInEditor(file); try { selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(file)); assertEquals(1, selection.size()); assertEquals(file, selection.getFirstElement()); - + selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(JavaCore.create(file))); assertEquals(1, selection.size()); assertEquals(file, selection.getFirstElement()); - + selection= (IStructuredSelection) fPackageExplorer.convertSelection(new StructuredSelection(folder)); assertEquals(1, selection.size()); assertEquals(folder, selection.getFirstElement()); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerTests.java index 62c4e6d750..ce3dd1d989 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/PackageExplorerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,26 +14,22 @@ package org.eclipse.jdt.ui.tests.packageview; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +@RunWith(Suite.class) +@Suite.SuiteClasses({ + ContentProviderTests1.class, + ContentProviderTests2.class, + ContentProviderTests3.class, + ContentProviderTests4.class, + ContentProviderTests5.class, + ContentProviderTests6.class, + ContentProviderTests7.class, + PackageExplorerShowInTests.class, + WorkingSetDropAdapterTest.class, + HierarchicalContentProviderTests.class, + PackageCacheTest.class +}) public class PackageExplorerTests { - - public static Test suite() { - TestSuite suite= new TestSuite(PackageExplorerTests.class.getName()); - //$JUnit-BEGIN$ - suite.addTest(ContentProviderTests1.suite()); - suite.addTest(ContentProviderTests2.suite()); - suite.addTest(ContentProviderTests3.suite()); - suite.addTest(ContentProviderTests4.suite()); - suite.addTest(ContentProviderTests5.suite()); - suite.addTest(ContentProviderTests6.suite()); - suite.addTest(ContentProviderTests7.suite()); - suite.addTest(PackageExplorerShowInTests.suite()); - suite.addTestSuite(WorkingSetDropAdapterTest.class); - suite.addTest(HierarchicalContentProviderTests.suite()); - suite.addTestSuite(PackageCacheTest.class); - //$JUnit-END$ - return suite; - } } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/WorkingSetDropAdapterTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/WorkingSetDropAdapterTest.java index 3522a9db05..21353d4dfe 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/WorkingSetDropAdapterTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/packageview/WorkingSetDropAdapterTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,10 +13,17 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.packageview; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; @@ -49,8 +56,8 @@ import org.eclipse.jdt.internal.ui.packageview.WorkingSetDropAdapter; import org.eclipse.jdt.internal.ui.workingsets.IWorkingSetIDs; import org.eclipse.jdt.internal.ui.workingsets.WorkingSetModel; - -public class WorkingSetDropAdapterTest extends TestCase { +@RunWith(JUnit4.class) +public class WorkingSetDropAdapterTest { private IJavaProject fProject; private PackageExplorerPart fPackageExplorer; @@ -58,9 +65,8 @@ public class WorkingSetDropAdapterTest extends TestCase { private WorkingSetDropAdapter fAdapter; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fProject= JavaProjectHelper.createJavaProject("Test", "bin"); IWorkbenchPage activePage= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); fPackageExplorer= (PackageExplorerPart)activePage.showView(JavaUI.ID_PACKAGES); @@ -68,21 +74,22 @@ public class WorkingSetDropAdapterTest extends TestCase { fAdapter= new WorkingSetDropAdapter(fPackageExplorer); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { JavaProjectHelper.delete(fProject); IWorkbenchPage activePage= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); activePage.hideView(fPackageExplorer); assertTrue(fPackageExplorer.getTreeViewer().getTree().isDisposed()); - super.tearDown(); } + @Test public void testInvalidTarget2() throws Exception { ITreeSelection selection= createSelection(fProject, null); performDnD(DND.DROP_NONE, selection, fProject); } + @Test public void testInvalidSource1() throws Exception { IPackageFragmentRoot root= JavaProjectHelper.addSourceContainer(fProject, "src"); @@ -92,6 +99,7 @@ public class WorkingSetDropAdapterTest extends TestCase { performDnD(DND.DROP_NONE, selection, target); } + @Test public void testInvalidSource2() throws Exception { JavaProjectHelper.addSourceContainer(fProject, "src"); IFolder folder= fProject.getProject().getFolder("folder"); @@ -103,6 +111,7 @@ public class WorkingSetDropAdapterTest extends TestCase { performDnD(DND.DROP_NONE, selection, target); } + @Test public void testAddProject() throws Exception { ITreeSelection selection= createSelection(fProject, null); @@ -114,6 +123,7 @@ public class WorkingSetDropAdapterTest extends TestCase { assertEquals(fProject, elements[0]); } + @Test public void testMoveProject() throws Exception { IWorkingSet source= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet( "Source", new IAdaptable[] {fProject}); @@ -131,6 +141,7 @@ public class WorkingSetDropAdapterTest extends TestCase { assertEquals(0, elements.length); } + @Test public void testMoveToOthersProject() throws Exception { IWorkingSet source= PlatformUI.getWorkbench().getWorkingSetManager().createWorkingSet( "Source", new IAdaptable[] {fProject}); @@ -150,6 +161,7 @@ public class WorkingSetDropAdapterTest extends TestCase { assertEquals(0, elements.length); } + @Test public void testRearrange1() throws Exception { IWorkingSet workingSets[]= createJavaWorkingSets(new String[] { "ws1", "ws2", "ws3" }); @@ -179,6 +191,7 @@ public class WorkingSetDropAdapterTest extends TestCase { return sets; } + @Test public void testRearrange2() throws Exception { IWorkingSet workingSets[]= createJavaWorkingSets(new String[] { "ws1", "ws2", "ws3" }); @@ -191,6 +204,7 @@ public class WorkingSetDropAdapterTest extends TestCase { assertEquals(workingSets[1], actual[2]); } + @Test public void testRearrange3() throws Exception { IWorkingSet workingSets[]= createJavaWorkingSets(new String[] { "ws1", "ws2", "ws3" }); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/preferences/OptionsConfigurationBlockTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/preferences/OptionsConfigurationBlockTest.java index 9ab5420dfb..0d1e5a67a0 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/preferences/OptionsConfigurationBlockTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/preferences/OptionsConfigurationBlockTest.java @@ -107,9 +107,9 @@ public class OptionsConfigurationBlockTest extends TestCase { JavaCore.COMPILER_PB_UNUSED_TYPE_ARGUMENTS_FOR_METHOD_INVOCATION, // maybe for 1.7 JavaCore.CODEASSIST_IMPLICIT_QUALIFICATION, // TODO: not used: bug? - + JavaCore.COMPILER_PB_DEAD_CODE_IN_TRIVIAL_IF_STATEMENT, // default is good (don't flag trivial 'if (DEBUG)') - + JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK, // is on the Type Filters page now, see https://bugs.eclipse.org/218487 JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK, // is on the Type Filters page now, see https://bugs.eclipse.org/218487 })); @@ -129,7 +129,7 @@ public class OptionsConfigurationBlockTest extends TestCase { keysMethod.setAccessible(true); Key[] keys= (Key[]) (keysMethod.getParameterTypes().length > 0 ? keysMethod.invoke(null, Boolean.FALSE) : keysMethod.invoke(null)); HashSet<Key> keySet= new HashSet<>(Arrays.asList(keys)); - + for (Field field : configurationBlock.getDeclaredFields()) { field.setAccessible(true); if (field.getType() == Key.class) { @@ -144,7 +144,7 @@ public class OptionsConfigurationBlockTest extends TestCase { } } } - + assertEquals(configurationBlock.getName() + "#getKeys() includes keys that are not declared in the class", Collections.emptySet(), keySet); } } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AbstractAnnotateAssistTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AbstractAnnotateAssistTests.java index 00ca06e7b6..f11dfb1fc2 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AbstractAnnotateAssistTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AbstractAnnotateAssistTests.java @@ -94,7 +94,7 @@ public abstract class AbstractAnnotateAssistTests extends QuickFixTest { String annotationpath, String compliance, ClassFileFilter classFileFilter) throws CoreException, IOException { IProject project= createLibrary(javaProject, jarName, sourceZipName, pathAndContents, compliance, classFileFilter); - + String projectPath= '/' + project.getName() + '/'; IClasspathEntry entry= JavaCore.newLibraryEntry( new Path(projectPath + jarName), @@ -148,7 +148,7 @@ public abstract class AbstractAnnotateAssistTests extends QuickFixTest { protected static void assertEqualLines(String message, String expected, String actual) { String[] expectedLines= Strings.convertIntoLines(expected); String[] actualLines= Strings.convertIntoLines(actual); - + String expected2= (expectedLines == null ? null : Strings.concatenate(expectedLines, "\n")); String actual2= (actualLines == null ? null : Strings.concatenate(actualLines, "\n")); assertEquals(message, expected2, actual2); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java index fe4994d7b0..a50733b8a7 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest.java @@ -235,7 +235,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { ArrayList<String> previews= new ArrayList<>(); ArrayList<String> expecteds= new ArrayList<>(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -252,7 +252,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); addPreviewAndExpected(proposals, buf, expecteds, previews); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -265,7 +265,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); addPreviewAndExpected(proposals, buf, expecteds, previews); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -279,7 +279,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); addPreviewAndExpected(proposals, buf, expecteds, previews); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -293,7 +293,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); addPreviewAndExpected(proposals, buf, expecteds, previews); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -309,7 +309,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { assertEqualStringsIgnoreOrder(previews, expecteds); } - + @Test public void testJoinAndIfStatements1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -1098,7 +1098,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertProposalDoesNotExist(proposals, "Put '>' expression in parentheses"); - + } @Test @@ -1120,7 +1120,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertProposalDoesNotExist(proposals, "Put '>' expression in parentheses"); - + } @Test @@ -1426,13 +1426,13 @@ public class AdvancedQuickAssistTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + int offset= buf.toString().indexOf("if"); AssistContext context= getCorrectionContext(cu, offset, 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test;\n"); buf.append("public class E {\n"); @@ -1445,7 +1445,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] {expected1}); } @@ -1463,13 +1463,13 @@ public class AdvancedQuickAssistTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + int offset= buf.toString().indexOf("if ("); AssistContext context= getCorrectionContext(cu, offset, 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -1481,7 +1481,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] {expected1}); } @@ -4607,15 +4607,15 @@ public class AdvancedQuickAssistTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + int offset= buf.toString().indexOf("switch"); AssistContext context= getCorrectionContext(cu, offset, 0); assertNoErrors(context); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 0); } - + @Test public void testConvertIfToSwitch1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -5904,7 +5904,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { assertProposalDoesNotExist(proposals, "Pick out selected part of String"); } - + @Test public void testCombineStringsProposals1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -5923,7 +5923,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -5936,7 +5936,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected }); } - + @Test public void testCombineStringsProposals2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -5955,7 +5955,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -5968,7 +5968,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected }); } - + @Test public void testCombineStringsProposals3() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -5988,7 +5988,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { assertProposalDoesNotExist(proposals, CorrectionMessages.AdvancedQuickAssistProcessor_combineSelectedStrings); } - + @Test public void testCombineStringsProposals4() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -6007,7 +6007,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -6020,7 +6020,7 @@ public class AdvancedQuickAssistTest extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected }); } - + @Test public void testCombineStringsProposals5() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest17.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest17.java index 5ee96c6815..a34409addd 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest17.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AdvancedQuickAssistTest17.java @@ -472,7 +472,7 @@ public class AdvancedQuickAssistTest17 extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected1 }); } - + @Test public void testReplaceReturnIfWithCondition3() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -512,7 +512,7 @@ public class AdvancedQuickAssistTest17 extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] {expected1}); } - + @Test public void testReplaceReturnIfWithCondition4() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -530,14 +530,14 @@ public class AdvancedQuickAssistTest17 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + int offset= buf.toString().indexOf("if"); AssistContext context= getCorrectionContext(cu, offset, 0); assertNoErrors(context); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.io.IOException;\n"); @@ -548,12 +548,12 @@ public class AdvancedQuickAssistTest17 extends QuickFixTest { buf.append(" return a > 0 ? Collections.<String, IOException>emptyMap() : Collections.<String, IOException>singletonMap(\"none\", null);\n"); buf.append(" }\n"); buf.append("}\n"); - + String expected1= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] {expected1}); } - + @Test public void testConvertIfToSwitch() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest15.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest15.java index 14e426c1d3..f759a377d6 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest15.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest15.java @@ -58,21 +58,21 @@ import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer; @RunWith(JUnit4.class) public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { - + @Rule public ProjectTestSetup projectsetup = new ProjectTestSetup(); protected static final String ANNOTATION_PATH= "annots"; - + protected static final Class<?> THIS= AnnotateAssistTest15.class; - + @Before public void setUp() throws Exception { fJProject1= ProjectTestSetup.getProject(); fJProject1.getProject().getFolder(ANNOTATION_PATH).create(true, true, null); fJProject1.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); } - + // === Tests === /* @@ -80,7 +80,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateReturn() throws Exception { - + String MY_MAP_PATH= "pack/age/MyMap"; String[] pathAndContents= new String[] { MY_MAP_PATH+".java", @@ -118,7 +118,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { Thread.sleep(200); ICompletionProposal proposal= proposalBox[0]; assertNotNull("should have a proposal", proposal); - + viewer.getQuickAssistAssistant().uninstall(); JavaProjectHelper.emptyDisplayLoop(); @@ -132,7 +132,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append("pack/age/MyMap.eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -153,7 +153,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateReturn2() throws Exception { - + String MY_MAP_PATH= "pack/age/MyMap"; String[] pathAndContents= new String[] { MY_MAP_PATH+".java", @@ -170,10 +170,10 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("V get"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull V'", list); String expectedInfo= "<dl><dt>get</dt>" + @@ -192,7 +192,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(MY_MAP_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -213,7 +213,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateRemove() throws Exception { - + String MY_MAP_PATH= "pack/age/MyMap"; String[] pathAndContents= new String[] { @@ -233,17 +233,17 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { " (TK;)T0V;\n"; ensureExists(annotationFile.getParent()); annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); - + JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); try { int offset= pathAndContents[1].indexOf("V get"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull V'", list); String expectedInfo= "<dl><dt>get</dt>" + @@ -262,7 +262,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + assertTrue("Annotation file should still exist", annotationFile.exists()); String expectedContent= @@ -275,7 +275,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { JavaPlugin.getActivePage().closeAllEditors(false); } } - + /* * Assert two proposals ("@NonNull" and "@Nullable") on an (outer) array type (in parameter position). @@ -284,7 +284,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateParameter_Array1() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -295,7 +295,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -311,10 +311,10 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("[][] ints"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'int @NonNull [][]'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -333,7 +333,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -351,12 +351,12 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { /* * Assert two proposals ("@NonNull" and "@Nullable") on the array representing the varargs ellipsis * Apply the second proposal and check the effect. - * + * * Cf. {@link AnnotateAssistTest15#testAnnotateParameter_Array1()} */ @Test public void testAnnotateParameter_Varargs1() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -367,7 +367,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -383,10 +383,10 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("..."); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'int @NonNull ...'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -405,7 +405,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -426,7 +426,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateConstructorParameter() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -437,7 +437,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -453,10 +453,10 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("String"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull String'", list); String expectedInfo= "<dl><dt><init></dt>" + @@ -475,7 +475,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -496,7 +496,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateField1() throws Exception { - + String NODE_PATH= "pack/age/Node"; String[] pathAndContents= new String[] { NODE_PATH+".java", @@ -513,10 +513,10 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("V value"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull V'", list); String expectedInfo= "<dl><dt>value</dt>" + @@ -535,7 +535,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(NODE_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -556,7 +556,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateField2() throws Exception { - + String NODE_PATH= "pack/age/Node"; String[] pathAndContents= new String[] { NODE_PATH+".java", @@ -573,10 +573,10 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("Node<String> next"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull Node'", list); String expectedInfo= "<dl><dt>next</dt>" + @@ -595,7 +595,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(NODE_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -629,7 +629,7 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { " }\n" + "}\n" }; - + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, new ClassFileFilter() { @Override public boolean include(CompilationResult unitResult) { @@ -660,9 +660,9 @@ public class AnnotateAssistTest15 extends AbstractAnnotateAssistTests { log.log(new Status(IStatus.INFO, JavaUI.ID_PLUGIN, "Expecting an error message to be logged after this.")); log.addLogListener(logListener); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertEquals("Expected number of proposals", 0, list.size()); - + assertNotNull("Expected status", resultingStatus[0]); } finally { if (logListener != null) { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest18.java index 1fe4577de7..c900e8122d 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest18.java @@ -51,7 +51,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { protected static final String ANNOTATION_PATH= "annots"; protected static final Class<?> THIS= AnnotateAssistTest18.class; - + @Before public void setUp() throws Exception { fJProject1= Java18ProjectTestSetup.getProject(); @@ -67,7 +67,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateParameter_TypeArgument() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -78,7 +78,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -95,10 +95,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("String> list"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull String'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -117,7 +117,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -138,7 +138,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateParameter_ArrayOfPrimitive() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -156,7 +156,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("int[]"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertNumberOfProposals(list, 0); } finally { JavaPlugin.getActivePage().closeAllEditors(false); @@ -172,7 +172,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateParameter_WildcardBound() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -183,7 +183,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -200,10 +200,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("Number> list"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull Number'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -222,7 +222,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -241,13 +241,13 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { * Assert two proposals ("@NonNull" and "@Nullable") on an inner array type (in parameter position). * A single line entry using this selector exists and will be amended. * Apply the second proposal and check the effect. - * + * * Cf. {@link AnnotateAssistTest15#testAnnotateParameter_Array1()} * @throws Exception multiple causes */ @Test public void testAnnotateParameter_Array2() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -258,7 +258,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -273,10 +273,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("[] ints"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'int[] @NonNull []'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -295,7 +295,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -314,13 +314,13 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { * Assert two proposals ("@NonNull" and "@Nullable") on an inner array type (in parameter position). * An entry with annotation on the outer array already exists and will be amended. * Apply the second proposal and check the effect. - * + * * Cf. {@link AnnotateAssistTest15#testAnnotateParameter_Array1()} * @throws Exception multiple causes */ @Test public void testAnnotateParameter_Array3() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -331,7 +331,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -348,10 +348,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("[] ints"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'int[] @NonNull []'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -370,7 +370,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -389,13 +389,13 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { * Assert two proposals ("@NonNull" and "@Nullable") on an inner array type - extra dimensions (in parameter position). * An entry with annotation on the outer array already exists and will be amended. * Apply the second proposal and check the effect. - * + * * Cf. {@link AnnotateAssistTest18#testAnnotateParameter_Array3()} * @throws Exception multiple causes */ @Test public void testAnnotateParameter_Array4() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -406,7 +406,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -423,10 +423,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("[],"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'int[] @NonNull []'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -445,7 +445,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -464,13 +464,13 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { * Assert two proposals ("@NonNull" and "@Nullable") on an outer array type - extra dimensions (in parameter position). * An entry with annotation on the inner array already exists and will be amended. * Apply the second proposal and check the effect. - * + * * Cf. {@link AnnotateAssistTest18#testAnnotateParameter_Array3()} * @throws Exception multiple causes */ @Test public void testAnnotateParameter_Array5() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -481,7 +481,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -498,10 +498,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("[][][],"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'int @NonNull [][][]'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -520,7 +520,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -539,12 +539,12 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { * Assert two proposals ("@NonNull" and "@Nullable") on an array type in normal syntax. * A two line entry using this selector & signature exists and will be amended. * Apply the second proposal and check the effect. - * + * * @throws Exception multiple causes */ @Test public void testAnnotateMethod_Array1() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -555,7 +555,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -571,10 +571,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("[] test"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'String @NonNull []'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -593,7 +593,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -612,12 +612,12 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { * Assert two proposals ("@NonNull" and "@Nullable") on an array type in extra-dims syntax. * A two line entry using this selector & signature exists and will be amended. * Apply the second proposal and check the effect. - * + * * @throws Exception multiple causes */ @Test public void testAnnotateMethod_Array2() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -628,7 +628,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -644,10 +644,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("[];"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'String @NonNull []'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -666,7 +666,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -684,13 +684,13 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { /** * Assert two proposals ("@NonNull" and "@Nullable") on the array representing the varargs ellipsis * Apply the second proposal and check the effect. - * + * * Cf. {@link AnnotateAssistTest18#testAnnotateParameter_Array3()} * @throws Exception multiple causes */ @Test public void testAnnotateParameter_Varargs1() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -701,7 +701,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -709,18 +709,18 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { " (Ljava/util/List<Ljava/lang/String;>;[I)Ljava/lang/String;\n"; ensureExists(annotationFile.getParent()); annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); - + IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); - + try { int offset= pathAndContents[1].indexOf("..."); - + List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'int @NonNull ...'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -728,7 +728,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "<dd>(Ljava/util/List<Ljava/lang/String;>;[<b>1</b>I)Ljava/lang/String;</dd>" + // <= 1 "</dl>"; assertEquals("expect detail", expectedInfo, proposal.getAdditionalProposalInfo()); - + proposal= findProposalByName("Annotate as 'int @Nullable ...'", list); expectedInfo= "<dl><dt>test</dt>" + @@ -736,13 +736,13 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "<dd>(Ljava/util/List<Ljava/lang/String;>;[<b>0</b>I)Ljava/lang/String;</dd>" + // <= 0 "</dl>"; assertEquals("expect detail", expectedInfo, proposal.getAdditionalProposalInfo()); - + IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); - + String expectedContent= "class pack/age/X\n" + "test\n" + @@ -758,13 +758,13 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { * Assert two proposals ("@NonNull" and "@Nullable") on the array representing the varargs ellipsis * An entry with annotation on the inner array already exists and will be amended. * Apply the second proposal and check the effect. - * + * * Cf. {@link AnnotateAssistTest18#testAnnotateParameter_Varargs1()} * @throws Exception multiple causes */ @Test public void testAnnotateParameter_Varargs2() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -775,7 +775,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -792,10 +792,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("..."); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'int[] @NonNull ...'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -814,7 +814,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -832,13 +832,13 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { /** * Assert two proposals ("@NonNull" and "@Nullable") on the element type of a varargs type * Apply the second proposal and check the effect. - * + * * Cf. {@link AnnotateAssistTest18#testAnnotateParameter_Array3()} * @throws Exception multiple causes */ @Test public void testAnnotateParameter_Varargs3() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -849,7 +849,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "}\n" }; addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); String initialContent= "class pack/age/X\n" + @@ -857,18 +857,18 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { " (Ljava/util/List<Ljava/lang/String;>;[Ljava/lang/String;)Ljava/lang/String;\n"; ensureExists(annotationFile.getParent()); annotationFile.create(new ByteArrayInputStream(initialContent.getBytes("UTF-8")), 0, null); - + IType type= fJProject1.findType(X_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); - + try { int offset= pathAndContents[1].indexOf("String ..."); - + List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull String'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -876,7 +876,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "<dd>(Ljava/util/List<Ljava/lang/String;>;[L<b>1</b>java/lang/String;)Ljava/lang/String;</dd>" + // <= 1 "</dl>"; assertEquals("expect detail", expectedInfo, proposal.getAdditionalProposalInfo()); - + proposal= findProposalByName("Annotate as '@Nullable String'", list); expectedInfo= "<dl><dt>test</dt>" + @@ -884,13 +884,13 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { "<dd>(Ljava/util/List<Ljava/lang/String;>;[L<b>0</b>java/lang/String;)Ljava/lang/String;</dd>" + // <= 0 "</dl>"; assertEquals("expect detail", expectedInfo, proposal.getAdditionalProposalInfo()); - + IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); - + String expectedContent= "class pack/age/X\n" + "test\n" + @@ -910,7 +910,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateMethod_TypeParameter1() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -929,10 +929,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("T extends"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull T extends List<X>'", list); String expectedInfo= "<dl><dt>test</dt>" + @@ -951,7 +951,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -1011,7 +1011,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateMethod_TypeParameter2() throws Exception { - + String X_PATH= "pack/age/X"; String[] pathAndContents= new String[] { X_PATH+".java", @@ -1030,10 +1030,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("T extends"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as '@NonNull T extends List<X>'", list); String expectedInfo= "<dl><dt>class pack/age/X</dt>" + @@ -1052,7 +1052,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); @@ -1109,7 +1109,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { */ @Test public void testAnnotateField1() throws Exception { - + String NODE_PATH= "pack/age/Node"; String[] pathAndContents= new String[] { NODE_PATH+".java", @@ -1127,10 +1127,10 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { int offset= pathAndContents[1].indexOf("[]> value"); List<ICompletionProposal> list= collectAnnotateProposals(javaEditor, offset); - + assertCorrectLabels(list); assertNumberOfProposals(list, 2); - + ICompletionProposal proposal= findProposalByName("Annotate as 'Object @NonNull []'", list); String expectedInfo= "<dl><dt>value</dt>" + @@ -1149,7 +1149,7 @@ public class AnnotateAssistTest18 extends AbstractAnnotateAssistTests { IDocument document= javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); proposal.apply(document); - + IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(NODE_PATH+".eea")); assertTrue("Annotation file should have been created", annotationFile.exists()); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java index 6792f8baec..30166b573f 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java @@ -68,7 +68,7 @@ import org.eclipse.jdt.internal.ui.text.correction.proposals.RenameRefactoringPr @RunWith(JUnit4.class) public class AssistQuickFixTest extends QuickFixTest { - + @Rule public ProjectTestSetup projectsetup = new ProjectTestSetup(); @@ -550,7 +550,7 @@ public class AssistQuickFixTest extends QuickFixTest { ArrayList<String> previews= new ArrayList<>(); ArrayList<String> expecteds= new ArrayList<>(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -588,7 +588,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); addPreviewAndExpected(proposals, buf, expecteds, previews); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -601,7 +601,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); addPreviewAndExpected(proposals, buf, expecteds, previews); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -614,10 +614,10 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); addPreviewAndExpected(proposals, buf, expecteds, previews); - + assertEqualStringsIgnoreOrder(previews, expecteds); } - + @Test public void testAssignToLocal9() throws Exception { // assign to local of field access @@ -887,7 +887,7 @@ public class AssistQuickFixTest extends QuickFixTest { assertCorrectLabels(proposals); String[] expecteds= new String[5]; - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class Timer {\n"); @@ -907,7 +907,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expecteds[1]= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class Timer {\n"); @@ -957,13 +957,13 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("Gen.java", buf.toString(), false, null); - + String str= "g.get(0);"; AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertNumberOfProposals(proposals, 5); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.ArrayList;\n"); @@ -977,7 +977,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.ArrayList;\n"); @@ -993,9 +993,9 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected2= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] { expected1, expected2 }); - + } // bug 217984 @@ -1015,13 +1015,13 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("Gen.java", buf.toString(), false, null); - + String str= "ge.get(0)"; AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertNumberOfProposals(proposals, 7); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.ArrayList;\n"); @@ -1035,7 +1035,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.ArrayList;\n"); @@ -1051,7 +1051,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected2= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] { expected1, expected2 }); } @@ -1073,13 +1073,13 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("Gen.java", buf.toString(), false, null); - + String str= "gs.get(0)"; AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertNumberOfProposals(proposals, 7); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.ArrayList;\n"); @@ -1094,7 +1094,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.ArrayList;\n"); @@ -1111,7 +1111,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected2= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] { expected1, expected2 }); } @@ -1133,13 +1133,13 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("Snippet.java", buf.toString(), false, null); - + String str= "workItemType.getEnumConstants();"; AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str) + str.length(), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertNumberOfProposals(proposals, 4); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -1154,7 +1154,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -1171,7 +1171,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected2= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] { expected1, expected2 }); } @@ -3263,14 +3263,14 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + String str= "message;"; AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -3305,10 +3305,10 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String ex2= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] { ex1, ex2 }); } - + @Test public void testJoinDeclaration5() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -3328,14 +3328,14 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + String str= "message ="; AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(str), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 4); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -3407,7 +3407,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String ex4= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] { ex1, ex2, ex3, ex4 }); } @@ -4826,7 +4826,7 @@ public class AssistQuickFixTest extends QuickFixTest { ArrayList<String> previews= new ArrayList<>(); ArrayList<String> expecteds= new ArrayList<>(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -4835,7 +4835,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); addPreviewAndExpected(proposals, buf, expecteds, previews); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -4846,7 +4846,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); addPreviewAndExpected(proposals, buf, expecteds, previews); - + assertEqualStringsIgnoreOrder(previews, expecteds); } @@ -5726,7 +5726,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected2= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -5738,7 +5738,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected3= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -5747,7 +5747,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected4= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] {expected1, expected2, expected3, expected4}); } @@ -6729,14 +6729,14 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + int offset= buf.toString().indexOf("i="); AssistContext context= getCorrectionContext(cu, offset, 1); List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertNumberOfProposals(proposals, 1); assertProposalDoesNotExist(proposals, CHANGE_MODIFIER_TO_FINAL); - + buf= new StringBuffer(); buf.append("package test;\n"); buf.append("public class E {\n"); @@ -7753,7 +7753,7 @@ public class AssistQuickFixTest extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8, expected9 }); } - + @Test public void testConvertToStringBufferExisting2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -7766,13 +7766,13 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); - + AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("\" + 5"), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 9); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class A {\n"); @@ -7784,7 +7784,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class A {\n"); @@ -7876,7 +7876,7 @@ public class AssistQuickFixTest extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8, expected9 }); } - + @Test public void testConvertToMessageFormat14() throws Exception { @@ -8462,7 +8462,7 @@ public class AssistQuickFixTest extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7 }); } - + @Test public void testConvertToMessageFormatExtendedOperands() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -8474,13 +8474,13 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); - + AssistContext context= getCorrectionContext(cu, buf.toString().indexOf(" + "), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 8); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -8492,7 +8492,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class A {\n"); @@ -8510,7 +8510,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected2= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class A {\n"); @@ -8571,7 +8571,7 @@ public class AssistQuickFixTest extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3, expected4, expected5, expected6, expected7, expected8 }); } - + @Test public void testMissingEnumConstantsInCase1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("p", false, null); @@ -9007,7 +9007,7 @@ public class AssistQuickFixTest extends QuickFixTest { assertExpectedExistInProposals(proposals, expected); } - + @Test public void testConvertEnhancedForArray02() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -9068,7 +9068,7 @@ public class AssistQuickFixTest extends QuickFixTest { assertExpectedExistInProposals(proposals, expected); } - + @Test public void testConvertEnhancedForList01() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -9131,7 +9131,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[1]= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Arrays;\n"); @@ -9181,13 +9181,13 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("for"), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 3); assertCorrectLabels(proposals); - + String[] expected= new String[3]; buf= new StringBuffer(); buf.append("package test1;\n"); @@ -9233,10 +9233,10 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[2]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } - + @Test public void testGenerateForSimple() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -9473,7 +9473,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append("private class MySecondOwnIterable extends MyFirstOwnIterable<Integer, String>{}"); buf.append("}\n"); expected[1]= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.LinkedList;\n"); @@ -9494,7 +9494,7 @@ public class AssistQuickFixTest extends QuickFixTest { fJProject1.setOptions(saveOptions); } } - + @Test public void testGenerateForGenerics() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -9555,7 +9555,7 @@ public class AssistQuickFixTest extends QuickFixTest { fJProject1.setOptions(saveOptions); } } - + @Test public void testGenerateForComplexGenerics() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -9623,7 +9623,7 @@ public class AssistQuickFixTest extends QuickFixTest { fJProject1.setOptions(saveOptions); } } - + @Test public void testGenerateForUpperboundWildcard() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -9976,10 +9976,10 @@ public class AssistQuickFixTest extends QuickFixTest { String selection= "array"; AssistContext context= getCorrectionContext(cu, buf.toString().lastIndexOf(selection) + selection.length(), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 6); assertCorrectLabels(proposals); - + String[] expected= new String[2]; buf= new StringBuffer(); buf.append("package test1;\n"); @@ -9992,7 +9992,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -10003,7 +10003,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[1]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } finally { fJProject1.setOptions(saveOptions); @@ -10057,7 +10057,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[1]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } finally { fJProject1.setOptions(saveOptions); @@ -10076,7 +10076,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + Map<String, String> saveOptions= fJProject1.getOptions(false); Map<String, String> newOptions= new HashMap<>(saveOptions); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true"); @@ -10085,10 +10085,10 @@ public class AssistQuickFixTest extends QuickFixTest { String selection= "nums"; AssistContext context= getCorrectionContext(cu, buf.toString().lastIndexOf(selection) + selection.length(), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 7); assertCorrectLabels(proposals); - + String[] expected= new String[2]; buf= new StringBuffer(); buf.append("package test1;\n"); @@ -10102,7 +10102,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -10114,7 +10114,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[1]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } finally { fJProject1.setOptions(saveOptions); @@ -10146,7 +10146,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf2.append(" return java.util.Collections.emptySet();\n"); buf2.append(" }\n"); buf2.append("}"); - + ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); pack1.createCompilationUnit("B.java", buf2.toString(), false, null); @@ -10156,14 +10156,14 @@ public class AssistQuickFixTest extends QuickFixTest { newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true"); try { fJProject1.setOptions(newOptions); - + String selection= "B.get( /*important: empty*/ );"; AssistContext context= getCorrectionContext(cu, buf.toString().lastIndexOf(selection) + selection.length(), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 5); assertCorrectLabels(proposals); - + String[] expected= new String[3]; buf= new StringBuffer(); buf.append("package test1;\n"); @@ -10179,7 +10179,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -10196,7 +10196,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[1]= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -10212,13 +10212,13 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[2]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } finally { fJProject1.setOptions(saveOptions); } } - + @Test public void testGenerateForImportsAndFormat2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -10245,7 +10245,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf2.append(" return java.util.Collections.emptySet();\n"); buf2.append(" }\n"); buf2.append("}"); - + ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); pack1.createCompilationUnit("B.java", buf2.toString(), false, null); @@ -10255,14 +10255,14 @@ public class AssistQuickFixTest extends QuickFixTest { newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true"); try { fJProject1.setOptions(newOptions); - + String selection= "B.raw(1+ 2);"; AssistContext context= getCorrectionContext(cu, buf.toString().lastIndexOf(selection) + selection.length(), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 4); assertCorrectLabels(proposals); - + String[] expected= new String[2]; buf= new StringBuffer(); buf.append("package test1;\n"); @@ -10276,7 +10276,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class A {\n"); @@ -10291,13 +10291,13 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[1]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } finally { fJProject1.setOptions(saveOptions); } } - + @Test public void testGenerateForImportsArray() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -10318,7 +10318,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf2.append(" return new Date[1];\n"); buf2.append(" }\n"); buf2.append("}"); - + ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); pack1.createCompilationUnit("B.java", buf2.toString(), false, null); @@ -10328,14 +10328,14 @@ public class AssistQuickFixTest extends QuickFixTest { newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true"); try { fJProject1.setOptions(newOptions); - + String selection= "B.get();"; AssistContext context= getCorrectionContext(cu, buf.toString().lastIndexOf(selection) + selection.length(), 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 4); assertCorrectLabels(proposals); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package test1;\n"); @@ -10348,7 +10348,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } finally { fJProject1.setOptions(saveOptions); @@ -10408,7 +10408,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); - + assertProposalPreviewEquals(buf.toString(), "Create 'for' loop using Iterator", proposals); } finally { fJProject1.setOptions(saveOptions); @@ -10468,7 +10468,7 @@ public class AssistQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); - + assertProposalPreviewEquals(buf.toString(), "Create 'for' loop using Iterator", proposals); } finally { fJProject1.setOptions(saveOptions); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest10.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest10.java index de9819dc49..4e80b6a8e3 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest10.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest10.java @@ -51,7 +51,7 @@ import org.eclipse.jdt.internal.ui.text.correction.proposals.TypeChangeCorrectio @RunWith(JUnit4.class) public class AssistQuickFixTest10 extends QuickFixTest { - + @Rule public ProjectTestSetup projectsetup = new Java10ProjectTestSetup(); @@ -267,7 +267,7 @@ public class AssistQuickFixTest10 extends QuickFixTest { assertEqualString(preview, buf.toString()); } - + @Test public void testChangeVarToTypeNoTypeChangeProposal() throws Exception { StringBuffer buf= new StringBuffer(); @@ -306,7 +306,7 @@ public class AssistQuickFixTest10 extends QuickFixTest { assertNumberOfProposals(proposals, 0); } - + @Test public void testChangeTypeToVarChangeProposalRemoveUnusedImport() throws Exception { StringBuffer buf= new StringBuffer(); @@ -415,7 +415,7 @@ public class AssistQuickFixTest10 extends QuickFixTest { buf.append("}\n"); IPackageFragment def= fSourceFolder.createPackageFragment("", false, null); def.createCompilationUnit("module-info.java", buf.toString(), false, null); - + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); buf= new StringBuffer(); buf.append("package test;\n\n"); @@ -447,7 +447,7 @@ public class AssistQuickFixTest10 extends QuickFixTest { assertEqualString(preview, buf.toString()); } - + private static final ArrayList<IJavaCompletionProposal> getExpectedProposals(ArrayList<IJavaCompletionProposal> proposals, Class<?>[] expectedTypes) { ArrayList<IJavaCompletionProposal> expected= new ArrayList<>(proposals); if (expectedTypes != null && expectedTypes.length > 0) { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest17.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest17.java index 12d5beb720..653c805b7b 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest17.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest17.java @@ -694,7 +694,7 @@ public class AssistQuickFixTest17 extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected1, expected2, expected3 }); } - + @Test public void testReplaceMultiCatchClauseWithThrows4() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -838,7 +838,7 @@ public class AssistQuickFixTest17 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected3= buf.toString(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.lang.reflect.InvocationTargetException;\n"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java index 1725415477..692a2895b9 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest18.java @@ -1533,6 +1533,74 @@ public class AssistQuickFixTest18 extends QuickFixTest { } @Test + public void testConvertToLambda28() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); + String buf= + "package test;\n" + + "public class C1 {\n" + + " private final String s;\n" + + " Runnable run = new Runnable() {\n" + + " @Override\n" + + " public void run() {\n" + + " for (int i=0; i < s.length(); ++i) {\n" + + " int j = i;\n" + + " }\n" + + " }\n" + + " };\n" + + " public C1() {\n" + + " s = \"abc\";\n" + + " }\n" + + "}\n"; + ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf, false, null); + + int offset= buf.toString().indexOf("new"); + AssistContext context= getCorrectionContext(cu, offset, 0); + assertNoErrors(context); + List<IJavaCompletionProposal> proposals= collectAssists(context, false); + + assertNumberOfProposals(proposals, 0); + } + + @Test + public void testConvertToLambda29() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); + String buf= "" + + "package test;\n" + + "public class C1 {\n" + + " private final String s = \"ABC\";\n" + + " Runnable run = new Runnable() {\n" + + " @Override\n" + + " public void run() {\n" + + " for (int i=0; i < s.length(); ++i) {\n" + + " int j = i;\n" + + " }\n" + + " }\n" + + " };\n" + + "}\n"; + ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf, false, null); + + int offset= buf.toString().indexOf("new"); + AssistContext context= getCorrectionContext(cu, offset, 0); + assertNoErrors(context); + List<IJavaCompletionProposal> proposals= collectAssists(context, false); + + assertNumberOfProposals(proposals, 1); + assertCorrectLabels(proposals); + + String expected1= "" + + "package test;\n" + + "public class C1 {\n" + + " private final String s = \"ABC\";\n" + + " Runnable run = () -> {\n" + + " for (int i=0; i < s.length(); ++i) {\n" + + " int j = i;\n" + + " }\n" + + " };\n" + + "}\n"; + assertExpectedExistInProposals(proposals, new String[] { expected1 }); + } + + @Test public void testConvertToLambdaAmbiguousOverridden() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf= new StringBuffer(); @@ -1551,7 +1619,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("Test.java", buf.toString(), false, null); - + int offset= buf.toString().indexOf("public boolean test("); AssistContext context= getCorrectionContext(cu, offset, 0); assertNoErrors(context); @@ -1573,7 +1641,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { assertExpectedExistInProposals(proposals, new String[] { expected1 }); } - + @Test public void testConvertToAnonymousClassCreation1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -2081,15 +2149,15 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" IntFunction<String> toString= (int i) -> Integer.toString(i);\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + int offset= buf.toString().indexOf("->"); AssistContext context= getCorrectionContext(cu, offset, 0); assertNoErrors(context); List<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertNumberOfProposals(proposals, 4); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.function.IntFunction;\n"); @@ -2102,7 +2170,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" };\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] { expected1 }); } @@ -3430,14 +3498,14 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E10.java", buf.toString(), false, null); - + int offset= buf.toString().indexOf("::") + 1; AssistContext context= getCorrectionContext(cu, offset, 0); assertNoErrors(context); List<IJavaCompletionProposal> proposals= collectAssists(context, false); assertNumberOfProposals(proposals, 4); assertCorrectLabels(proposals); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.lang.annotation.*;\n"); @@ -3452,7 +3520,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertExpectedExistInProposals(proposals, new String[] { expected1 }); } @@ -4812,7 +4880,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" };\n"); buf.append("}\n"); assertProposalPreviewEquals(buf.toString(), "Convert to anonymous class creation", proposals); - + } @Test @@ -4821,7 +4889,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); JavaCore.setOptions(options); JavaProjectHelper.addLibrary(fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path())); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf; @@ -4912,7 +4980,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); assertProposalPreviewEquals(buf.toString(), "Convert to anonymous class creation", proposals); - + } @Test @@ -4921,7 +4989,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); JavaCore.setOptions(options); JavaProjectHelper.addLibrary(fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path())); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf; @@ -5020,7 +5088,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); assertProposalPreviewEquals(buf.toString(), "Convert to anonymous class creation", proposals); - + } @Test @@ -5029,7 +5097,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); JavaCore.setOptions(options); JavaProjectHelper.addLibrary(fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path())); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf; @@ -5132,7 +5200,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); assertProposalPreviewEquals(buf.toString(), "Convert to anonymous class creation", proposals); - + } @Test @@ -5141,7 +5209,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); JavaCore.setOptions(options); JavaProjectHelper.addLibrary(fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path())); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf; @@ -5213,8 +5281,8 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(""); pack1.createCompilationUnit("Test.java", buf.toString(), false, null); - // --- Classes in which the quick assists are checked (without and with NonNullByDefault in effect at the target location) --- - + // --- Classes in which the quick assists are checked (without and with NonNullByDefault in effect at the target location) --- + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -5252,7 +5320,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { List<IJavaCompletionProposal> proposals2= collectAssists(context2, false); // --- Convert to method reference without and with NNBD --- - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -5282,7 +5350,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { assertProposalPreviewEquals(buf.toString(), "Convert to method reference", proposals2); // --- Add inferred lambda parameter types without and with NNBD --- - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -5330,7 +5398,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); assertProposalPreviewEquals(buf.toString(), "Convert to anonymous class creation", proposals1); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("\n"); @@ -5392,9 +5460,9 @@ public class AssistQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append(" };\n"); buf.append("}\n"); - assertProposalPreviewEquals(buf.toString(), "Convert to anonymous class creation", proposals); + assertProposalPreviewEquals(buf.toString(), "Convert to anonymous class creation", proposals); } - + @Test public void testNoRedundantNonNullInConvertArrayForLoop() throws Exception { NullTestUtils.prepareNullTypeAnnotations(fSourceFolder); @@ -5414,7 +5482,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("for"), 0); ArrayList<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 3); @@ -5454,7 +5522,7 @@ public class AssistQuickFixTest18 extends QuickFixTest { AssistContext context= getCorrectionContext(cu, buf.toString().indexOf("for"), 0); ArrayList<IJavaCompletionProposal> proposals= collectAssists(context, false); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 3); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpStressTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpStressTest.java index 88234c5808..583a9f1f2f 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpStressTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpStressTest.java @@ -5297,7 +5297,7 @@ public class CleanUpStressTest extends CleanUpTestCase { enable(CleanUpConstants.SORT_MEMBERS); enable(CleanUpConstants.SORT_MEMBERS_ALL); - + enable(CleanUpConstants.REMOVE_REDUNDANT_MODIFIERS); enable(CleanUpConstants.REMOVE_REDUNDANT_SEMICOLONS); @@ -5309,9 +5309,9 @@ public class CleanUpStressTest extends CleanUpTestCase { for (ICompilationUnit cu : units) { String previewContent= getNormalizedContent(new Document(cu.getBuffer().getContents())); String compilationUnitName= getCompilationUnitName(cu); - + String expected= fExpectedChangesAllTests.get(compilationUnitName); - + assertTrue("No expected value in table for " + compilationUnitName, expected != null); assertEquals("Content not as expected for " + compilationUnitName, expected, previewContent); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java index b4bf77e67b..d82129e5ea 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest.java @@ -5008,6 +5008,50 @@ public class CleanUpTest extends CleanUpTestCase { } @Test + public void testDoNotUseMapMethodInsideMapImplementation() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + String sample= "" // + + "package test1;\n" // + + "\n" // + + "import java.util.HashMap;\n" // + + "import java.util.Map;\n" // + + "\n" // + + "public class E1<K,V> extends HashMap<K,V> {\n" // + + " @Override\n" // + + " public boolean containsKey(Object key) {\n" // + + " return keySet().contains(key);\n" // + + " }\n" // + + "}\n"; + ICompilationUnit cu1= pack1.createCompilationUnit("E1.java", sample, false, null); + + enable(CleanUpConstants.USE_DIRECTLY_MAP_METHOD); + + assertRefactoringHasNoChange(new ICompilationUnit[] { cu1 }); + } + + @Test + public void testDoNotUseMapMethodInsideThisMapImplementation() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + String sample= "" // + + "package test1;\n" // + + "\n" // + + "import java.util.HashMap;\n" // + + "import java.util.Map;\n" // + + "\n" // + + "public class E1<K,V> extends HashMap<K,V> {\n" // + + " @Override\n" // + + " public boolean containsKey(Object key) {\n" // + + " return this.keySet().contains(key);\n" // + + " }\n" // + + "}\n"; + ICompilationUnit cu1= pack1.createCompilationUnit("E1.java", sample, false, null); + + enable(CleanUpConstants.USE_DIRECTLY_MAP_METHOD); + + assertRefactoringHasNoChange(new ICompilationUnit[] { cu1 }); + } + + @Test public void testSerialVersionBug139381() throws Exception { JavaProjectHelper.set14CompilerOptions(fJProject1); @@ -9005,7 +9049,7 @@ public class CleanUpTest extends CleanUpTestCase { buf.append("}\n"); String expected6 = buf.toString(); ICompilationUnit cu6= pack1.createCompilationUnit("NestedEnumExample.java", buf.toString(), false, null); - + enable(CleanUpConstants.REMOVE_REDUNDANT_MODIFIERS); assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1, cu2, cu3, cu4, cu5, cu6 }, new String[] { expected1, expected2, expected3, expected4, expected5, expected6 }); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest18.java index ca50a293c8..71be2f2e1f 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest18.java @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Fabrice TIERCELIN - Lambda expression cleanup *******************************************************************************/ package org.eclipse.jdt.ui.tests.quickfix; @@ -57,6 +58,268 @@ public class CleanUpTest18 extends CleanUpTestCase { } @Test + public void testSimplifyLambdaExpression() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + String sample= "" // + + "package test1;\n" // + + "\n" // + + "import static java.util.Calendar.getInstance;\n" // + + "import static java.util.Calendar.getAvailableLocales;\n" // + + "\n" // + + "import java.time.Instant;\n" // + + "import java.util.ArrayList;\n" // + + "import java.util.Calendar;\n" // + + "import java.util.Date;\n" // + + "import java.util.Locale;\n" // + + "import java.util.Vector;\n" // + + "import java.util.function.BiFunction;\n" // + + "import java.util.function.Function;\n" // + + "import java.util.function.Supplier;\n" // + + "\n" // + + "public class E extends Date {\n" // + + " public String changeableText = \"foo\";\n" // + + "\n" // + + " public Function<String, String> removeParentheses() {\n" // + + " return (someString) -> someString.trim().toLowerCase();\n" // + + " }\n" // + + "\n" // + + " public Function<String, String> doNotRemoveParenthesesWithSingleVariableDeclaration() {\n" // + + " return (String someString) -> someString.trim().toLowerCase();\n" // + + " }\n" // + + "\n" // + + " public BiFunction<String, String, Integer> doNotRemoveParenthesesWithTwoParameters() {\n" // + + " return (someString, anotherString) -> someString.trim().compareTo(anotherString.trim());\n" // + + " }\n" // + + "\n" // + + " public Supplier<Boolean> doNotRemoveParenthesesWithNoParameter() {\n" // + + " return () -> {System.out.println(\"foo\");return true;};\n" // + + " }\n" // + + "\n" // + + " public Function<String, String> removeReturnAndBrackets() {\n" // + + " return someString -> {return someString.trim().toLowerCase();};\n" // + + " }\n" // + + "\n" // + + " public Function<String, String> removeReturnAndBracketsWithParentheses() {\n" // + + " return someString -> {return someString.trim().toLowerCase() + \"bar\";};\n" // + + " }\n" // + + "\n" // + + " public Function<String, String> doNotRemoveReturnWithSeveralStatements() {\n" // + + " return someString -> {String trimmed = someString.trim();\n" // + + " return trimmed.toLowerCase();};\n" // + + " }\n" // + + "\n" // + + " public Supplier<ArrayList<String>> useCreationReference() {\n" // + + " return () -> new ArrayList<>();\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, ArrayList<String>> useCreationReferenceWithParameter() {\n" // + + " return capacity -> new ArrayList<>(capacity);\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, ArrayList<String>> useCreationReferenceWithParameterAndType() {\n" // + + " // TODO this can be refactored like useCreationReferenceWithParameter\n" // + + " return (Integer capacity) -> new ArrayList<>(capacity);\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, ArrayList<String>> doNotRefactorWithExpressions() {\n" // + + " return capacity -> new ArrayList<>(capacity + 1);\n" // + + " }\n" // + + "\n" // + + " public BiFunction<Integer, Integer, Vector<String>> useCreationReferenceWithParameters() {\n" // + + " return (initialCapacity, capacityIncrement) -> new Vector<>(initialCapacity, capacityIncrement);\n" // + + " }\n" // + + "\n" // + + " public BiFunction<Integer, Integer, Vector<String>> doNotRefactorShuffledParams() {\n" // + + " return (initialCapacity, capacityIncrement) -> new Vector<>(capacityIncrement, initialCapacity);\n" // + + " }\n" // + + "\n" // + + " public Function<Date, Long> useMethodReference() {\n" // + + " return date -> date.getTime();\n" // + + " }\n" // + + "\n" // + + " public BiFunction<Date, Date, Integer> useMethodReferenceWithParameter() {\n" // + + " return (date, anotherDate) -> date.compareTo(anotherDate);\n" // + + " }\n" // + + "\n" // + + " public Function<String, Long> useTypeReference() {\n" // + + " return numberInText -> Long.getLong(numberInText);\n" // + + " }\n" // + + "\n" // + + " public static Function<Instant, Date> useTypeReferenceOnClassMethod() {\n" // + + " return instant -> Date.from(instant);\n" // + + " }\n" // + + "\n" // + + " public static Function<Locale, Calendar> useTypeReferenceOnImportedMethod() {\n" // + + " return locale -> Calendar.getInstance(locale);\n" // + + " }\n" // + + "\n" // + + " public static Supplier<Locale[]> useTypeReferenceAsSupplier() {\n" // + + " return () -> Calendar.getAvailableLocales();\n" // + + " }\n" // + + "\n" // + + " public Function<String, Integer> useExpressionMethodReferenceOnLiteral() {\n" // + + " return textToSearch -> \"AutoRefactor\".indexOf(textToSearch);\n" // + + " }\n" // + + "\n" // + + " public Function<String, Integer> doNotUseExpressionMethodReferenceOnVariable() {\n" // + + " return textToSearch -> this.changeableText.indexOf(textToSearch);\n" // + + " }\n" // + + "\n" // + + " public Function<Date, Integer> useThisMethodReference() {\n" // + + " return anotherDate -> this.compareTo(anotherDate);\n" // + + " }\n" // + + "\n" // + + " public Function<Date, Integer> useThisMethodReferenceAddThis() {\n" // + + " return anotherDate -> this.compareTo(anotherDate);\n" // + + " }\n" // + + "\n" // + + " public Function<Date, Integer> useSuperMethodReference() {\n" // + + " return anotherDate -> super.compareTo(anotherDate);\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, String> doNotUseConflictingMethodReference() {\n" // + + " return numberToPrint -> numberToPrint.toString();\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, String> doNotUseConflictingStaticMethodReference() {\n" // + + " return numberToPrint -> Integer.toString(numberToPrint);\n" // + + " }\n" // + + "}\n"; + ICompilationUnit cu1= pack1.createCompilationUnit("E.java", sample, false, null); + + enable(CleanUpConstants.SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF); + + sample= "" // + + "package test1;\n" // + + "\n" // + + "import static java.util.Calendar.getInstance;\n" // + + "import static java.util.Calendar.getAvailableLocales;\n" // + + "\n" // + + "import java.time.Instant;\n" // + + "import java.util.ArrayList;\n" // + + "import java.util.Calendar;\n" // + + "import java.util.Date;\n" // + + "import java.util.Locale;\n" // + + "import java.util.Vector;\n" // + + "import java.util.function.BiFunction;\n" // + + "import java.util.function.Function;\n" // + + "import java.util.function.Supplier;\n" // + + "\n" // + + "public class E extends Date {\n" // + + " public String changeableText = \"foo\";\n" // + + "\n" // + + " public Function<String, String> removeParentheses() {\n" // + + " return someString -> someString.trim().toLowerCase();\n" // + + " }\n" // + + "\n" // + + " public Function<String, String> doNotRemoveParenthesesWithSingleVariableDeclaration() {\n" // + + " return (String someString) -> someString.trim().toLowerCase();\n" // + + " }\n" // + + "\n" // + + " public BiFunction<String, String, Integer> doNotRemoveParenthesesWithTwoParameters() {\n" // + + " return (someString, anotherString) -> someString.trim().compareTo(anotherString.trim());\n" // + + " }\n" // + + "\n" // + + " public Supplier<Boolean> doNotRemoveParenthesesWithNoParameter() {\n" // + + " return () -> {System.out.println(\"foo\");return true;};\n" // + + " }\n" // + + "\n" // + + " public Function<String, String> removeReturnAndBrackets() {\n" // + + " return someString -> someString.trim().toLowerCase();\n" // + + " }\n" // + + "\n" // + + " public Function<String, String> removeReturnAndBracketsWithParentheses() {\n" // + + " return someString -> (someString.trim().toLowerCase() + \"bar\");\n" // + + " }\n" // + + "\n" // + + " public Function<String, String> doNotRemoveReturnWithSeveralStatements() {\n" // + + " return someString -> {String trimmed = someString.trim();\n" // + + " return trimmed.toLowerCase();};\n" // + + " }\n" // + + "\n" // + + " public Supplier<ArrayList<String>> useCreationReference() {\n" // + + " return ArrayList::new;\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, ArrayList<String>> useCreationReferenceWithParameter() {\n" // + + " return ArrayList::new;\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, ArrayList<String>> useCreationReferenceWithParameterAndType() {\n" // + + " // TODO this can be refactored like useCreationReferenceWithParameter\n" // + + " return (Integer capacity) -> new ArrayList<>(capacity);\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, ArrayList<String>> doNotRefactorWithExpressions() {\n" // + + " return capacity -> new ArrayList<>(capacity + 1);\n" // + + " }\n" // + + "\n" // + + " public BiFunction<Integer, Integer, Vector<String>> useCreationReferenceWithParameters() {\n" // + + " return Vector::new;\n" // + + " }\n" // + + "\n" // + + " public BiFunction<Integer, Integer, Vector<String>> doNotRefactorShuffledParams() {\n" // + + " return (initialCapacity, capacityIncrement) -> new Vector<>(capacityIncrement, initialCapacity);\n" // + + " }\n" // + + "\n" // + + " public Function<Date, Long> useMethodReference() {\n" // + + " return Date::getTime;\n" // + + " }\n" // + + "\n" // + + " public BiFunction<Date, Date, Integer> useMethodReferenceWithParameter() {\n" // + + " return Date::compareTo;\n" // + + " }\n" // + + "\n" // + + " public Function<String, Long> useTypeReference() {\n" // + + " return Long::getLong;\n" // + + " }\n" // + + "\n" // + + " public static Function<Instant, Date> useTypeReferenceOnClassMethod() {\n" // + + " return instant -> Date.from(instant);\n" // + + " }\n" // + + "\n" // + + " public static Function<Locale, Calendar> useTypeReferenceOnImportedMethod() {\n" // + + " return Calendar::getInstance;\n" // + + " }\n" // + + "\n" // + + " public static Supplier<Locale[]> useTypeReferenceAsSupplier() {\n" // + + " return Calendar::getAvailableLocales;\n" // + + " }\n" // + + "\n" // + + " public Function<String, Integer> useExpressionMethodReferenceOnLiteral() {\n" // + + " return \"AutoRefactor\"::indexOf;\n" // + + " }\n" // + + "\n" // + + " public Function<String, Integer> doNotUseExpressionMethodReferenceOnVariable() {\n" // + + " return textToSearch -> this.changeableText.indexOf(textToSearch);\n" // + + " }\n" // + + "\n" // + + " public Function<Date, Integer> useThisMethodReference() {\n" // + + " return this::compareTo;\n" // + + " }\n" // + + "\n" // + + " public Function<Date, Integer> useThisMethodReferenceAddThis() {\n" // + + " return this::compareTo;\n" // + + " }\n" // + + "\n" // + + " public Function<Date, Integer> useSuperMethodReference() {\n" // + + " return super::compareTo;\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, String> doNotUseConflictingMethodReference() {\n" // + + " return numberToPrint -> numberToPrint.toString();\n" // + + " }\n" // + + "\n" // + + " public Function<Integer, String> doNotUseConflictingStaticMethodReference() {\n" // + + " return numberToPrint -> Integer.toString(numberToPrint);\n" // + + " }\n" // + + "}\n"; + String expected1= sample; + + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); + } + + @Test public void testConvertToLambda01() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -87,10 +350,10 @@ public class CleanUpTest18 extends CleanUpTestCase { String expected1= buf.toString(); assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); - + disable(CleanUpConstants.USE_LAMBDA); enable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { original }); } @@ -136,10 +399,10 @@ public class CleanUpTest18 extends CleanUpTestCase { String expected1= buf.toString(); assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); - + disable(CleanUpConstants.USE_LAMBDA); enable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { original }); } @@ -208,10 +471,10 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append("}\n"); String original= buf.toString(); ICompilationUnit cu1= pack1.createCompilationUnit("E.java", original, false, null); - + enable(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES); enable(CleanUpConstants.USE_LAMBDA); - + buf= new StringBuffer(); buf.append("package test;\n"); buf.append("import java.util.concurrent.Executors;\n"); @@ -221,12 +484,12 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); - + disable(CleanUpConstants.USE_LAMBDA); enable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { original }); } @@ -373,10 +636,10 @@ public class CleanUpTest18 extends CleanUpTestCase { String expected1= buf.toString(); assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); - + disable(CleanUpConstants.USE_LAMBDA); enable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { original }); } @@ -470,10 +733,10 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append("}\n"); String original= buf.toString(); ICompilationUnit cu1= pack1.createCompilationUnit("E.java", original, false, null); - + enable(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES); enable(CleanUpConstants.USE_LAMBDA); - + buf= new StringBuffer(); buf.append("package test;\n"); buf.append("\n"); @@ -519,12 +782,12 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); - + disable(CleanUpConstants.USE_LAMBDA); enable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { original }); } @@ -564,10 +827,10 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append("@FunctionalInterface interface ZV { void zoo(); }\n"); String original= buf.toString(); ICompilationUnit cu1= pack1.createCompilationUnit("E.java", original, false, null); - + enable(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES); enable(CleanUpConstants.USE_LAMBDA); - + buf= new StringBuffer(); buf.append("package test;\n"); buf.append("public interface E {\n"); @@ -589,12 +852,12 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append("@FunctionalInterface interface ZI { int zoo(); }\n"); buf.append("@FunctionalInterface interface ZV { void zoo(); }\n"); String expected1= buf.toString(); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); - + disable(CleanUpConstants.USE_LAMBDA); enable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { original }); } @@ -767,10 +1030,10 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append("}\n"); String original= buf.toString(); ICompilationUnit cu1= pack1.createCompilationUnit("E.java", original, false, null); - + enable(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES); enable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); - + buf= new StringBuffer(); buf.append("package test;\n"); buf.append("import java.util.*;\n"); @@ -803,12 +1066,12 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append(" };\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); - + disable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); enable(CleanUpConstants.USE_LAMBDA); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { original }); } @@ -873,10 +1136,10 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append("}\n"); String original= buf.toString(); ICompilationUnit cu1= pack1.createCompilationUnit("Test.java", original, false, null); - + enable(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES); enable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); - + buf= new StringBuffer(); buf.append("package test;\n"); buf.append("\n"); @@ -892,12 +1155,12 @@ public class CleanUpTest18 extends CleanUpTestCase { buf.append(" };\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { expected1 }); - + disable(CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION); enable(CleanUpConstants.USE_LAMBDA); - + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu1 }, new String[] { original }); } @@ -975,4 +1238,59 @@ public class CleanUpTest18 extends CleanUpTestCase { assertRefactoringHasNoChange(new ICompilationUnit[] { cu }); } + + // fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=560018 + @Test + public void testConvertToLambdaInFieldInitializerWithFinalFieldReference() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); + String buf= "" + + "package test;\n" + + "public class C1 {\n" + + " final String s;\n" + + " Runnable run1 = new Runnable() {\n" + + " @Override\n" + + " public void run() {\n" + + " System.out.println(s\n" + + " }\n" + + " };\n" + + " public C1() {\n" + + " s = \"abc\";\n" + + " };\n" + + "}\n"; + ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf, false, null); + + enable(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES); + enable(CleanUpConstants.USE_LAMBDA); + + assertRefactoringHasNoChange(new ICompilationUnit[] { cu }); + } + + // fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=560018 + @Test + public void testConvertToLambdaInFieldInitializerWithFinalFieldReference2() throws Exception { + IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); + String buf= "" + + "package test;\n" + + "public class C1 {\n" + + " final String s = \"abc\";\n" + + " Runnable run1 = new Runnable() {\n" + + " @Override\n" + + " public void run() {\n" + + " System.out.println(s);\n" + + " }\n" + + " };\n" + + "}\n"; + ICompilationUnit cu= pack1.createCompilationUnit("C1.java", buf, false, null); + + enable(CleanUpConstants.CONVERT_FUNCTIONAL_INTERFACES); + enable(CleanUpConstants.USE_LAMBDA); + + String expected1= "" + + "package test;\n" + + "public class C1 {\n" + + " final String s = \"abc\";\n" + + " Runnable run1 = () -> System.out.println(s);\n" + + "}\n"; + assertRefactoringResultAsExpected(new ICompilationUnit[] { cu }, new String[] { expected1 }); + } } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertForLoopQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertForLoopQuickFixTest.java index 5098d0d5a8..6a813cc286 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertForLoopQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertForLoopQuickFixTest.java @@ -2138,10 +2138,10 @@ public class ConvertForLoopQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); buf.append("\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + assertFalse(satisfiesPrecondition(cu)); } - + @Test public void testBodyPrecondition344674_1() throws Exception { //https://bugs.eclipse.org/bugs/show_bug.cgi?id=344674 @@ -2530,12 +2530,12 @@ public class ConvertForLoopQuickFixTest extends QuickFixTest { assertFalse(satisfiesPrecondition(cu)); } - + @Test public void testBug510758_1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuilder buf= new StringBuilder(); - + buf.append("package test1;\n"); buf.append("public class E1 {\n"); buf.append(" private Object[] array;\n"); @@ -2554,7 +2554,7 @@ public class ConvertForLoopQuickFixTest extends QuickFixTest { ICompilationUnit cu= pack1.createCompilationUnit("E1.java", buf.toString(), false, null); assertTrue(satisfiesPrecondition(cu)); - + List<IJavaCompletionProposal> proposals= fetchConvertingProposal(buf, cu); assertNotNull(fConvertLoopProposal); @@ -2582,12 +2582,12 @@ public class ConvertForLoopQuickFixTest extends QuickFixTest { String expected= buf.toString(); assertEqualString(preview1, expected); } - + @Test public void testBug510758_2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuilder buf= new StringBuilder(); - + buf.append("package test1;\n"); buf.append("public class E1 {\n"); buf.append(" private Object[] array;\n"); @@ -2606,19 +2606,19 @@ public class ConvertForLoopQuickFixTest extends QuickFixTest { ICompilationUnit cu= pack1.createCompilationUnit("E1.java", buf.toString(), false, null); assertFalse(satisfiesPrecondition(cu)); - + List<IJavaCompletionProposal> proposals= fetchConvertingProposal(buf, cu); assertNull(fConvertLoopProposal); - assertCorrectLabels(proposals); + assertCorrectLabels(proposals); } - + @Test public void testBug510758_3() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuilder buf= new StringBuilder(); - + buf.append("package test1;\n"); buf.append("public class E1 {\n"); buf.append(" private Object[] array;\n"); @@ -2637,12 +2637,12 @@ public class ConvertForLoopQuickFixTest extends QuickFixTest { ICompilationUnit cu= pack1.createCompilationUnit("E1.java", buf.toString(), false, null); assertFalse(satisfiesPrecondition(cu)); - + List<IJavaCompletionProposal> proposals= fetchConvertingProposal(buf, cu); assertNull(fConvertLoopProposal); - assertCorrectLabels(proposals); + assertCorrectLabels(proposals); } @Test @@ -2670,7 +2670,7 @@ public class ConvertForLoopQuickFixTest extends QuickFixTest { ICompilationUnit cu= pack1.createCompilationUnit("E1.java", orig.toString(), false, null); assertTrue(satisfiesPrecondition(cu)); - + List<IJavaCompletionProposal> proposals= fetchConvertingProposal(orig, cu); assertNotNull(fConvertLoopProposal); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertIterableLoopQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertIterableLoopQuickFixTest.java index d179f56140..5ab4608c40 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertIterableLoopQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ConvertIterableLoopQuickFixTest.java @@ -68,7 +68,7 @@ public final class ConvertIterableLoopQuickFixTest extends QuickFixTest { int offset= buf.toString().indexOf("for"); return fetchConvertingProposal(cu, offset); } - + private List<IJavaCompletionProposal> fetchConvertingProposal(ICompilationUnit cu, int offset) throws Exception { AssistContext context= getCorrectionContext(cu, offset, 0); List<IJavaCompletionProposal> proposals= collectAssists(context, false); @@ -228,7 +228,7 @@ public final class ConvertIterableLoopQuickFixTest extends QuickFixTest { String expected= buf.toString(); assertEqualString(preview, expected); } - + @Test public void testEnumeration() throws Exception { IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); @@ -1207,7 +1207,7 @@ public final class ConvertIterableLoopQuickFixTest extends QuickFixTest { String expected= buf.toString(); assertEqualString(preview, expected); } - + @Test public void testBug510758_1() throws Exception { IPackageFragment pack= fSourceFolder.createPackageFragment("test1", false, null); @@ -1234,7 +1234,7 @@ public final class ConvertIterableLoopQuickFixTest extends QuickFixTest { assertNull(fConvertLoopProposal); assertCorrectLabels(proposals); } - + @Test public void testBug510758_2() throws Exception { IPackageFragment pack= fSourceFolder.createPackageFragment("test1", false, null); @@ -1258,7 +1258,7 @@ public final class ConvertIterableLoopQuickFixTest extends QuickFixTest { offset= buf.indexOf("for", offset+1); List<IJavaCompletionProposal> proposals= fetchConvertingProposal(unit, offset); assertNotNull(fConvertLoopProposal); - + String preview= getPreviewContent(fConvertLoopProposal); buf= new StringBuffer(); @@ -1276,7 +1276,7 @@ public final class ConvertIterableLoopQuickFixTest extends QuickFixTest { String expected= buf.toString(); assertEqualString(preview, expected); - + assertCorrectLabels(proposals); } } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JarUtil.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JarUtil.java index a05e684caf..a1021c90d7 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JarUtil.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JarUtil.java @@ -169,7 +169,7 @@ private static class Requestor implements ICompilerRequestor { public String outputPath; public String problemLog = ""; private ClassFileFilter classFileFilter= null; - + public Requestor(ClassFileFilter classFileFilter) { if (classFileFilter != null) { this.classFileFilter = classFileFilter; @@ -223,7 +223,7 @@ public static void compile(String[] pathsAndContents, Map<String, String> option } else { classpath = classLibs; } - + INameEnvironment nameEnvironment = new FileSystem(classpath, new String[] {}, null); IErrorHandlingPolicy errorHandlingPolicy = new IErrorHandlingPolicy() { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JavadocQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JavadocQuickFixTest.java index 792a4685c8..1829cfca91 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JavadocQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JavadocQuickFixTest.java @@ -1334,7 +1334,7 @@ public class JavadocQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); pack1.createCompilationUnit("A.java", buf.toString(), false, null); - + IPackageFragment pack2= fSourceFolder.createPackageFragment("pack2", false, null); buf= new StringBuffer(); buf.append("package pack2;\n"); @@ -1347,13 +1347,13 @@ public class JavadocQuickFixTest extends QuickFixTest { buf.append("public class E {\n"); buf.append("}\n"); ICompilationUnit cu= pack2.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 2); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package pack2;\n"); @@ -1366,10 +1366,10 @@ public class JavadocQuickFixTest extends QuickFixTest { buf.append("public class E {\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } - + @Test public void testInvalidQualification3() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); @@ -1382,7 +1382,7 @@ public class JavadocQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); pack1.createCompilationUnit("A.java", buf.toString(), false, null); - + IPackageFragment pack2= fSourceFolder.createPackageFragment("pack2", false, null); buf= new StringBuffer(); buf.append("package pack2;\n"); @@ -1395,13 +1395,13 @@ public class JavadocQuickFixTest extends QuickFixTest { buf.append("public class E {\n"); buf.append("}\n"); ICompilationUnit cu= pack2.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 2); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package pack2;\n"); @@ -1414,7 +1414,7 @@ public class JavadocQuickFixTest extends QuickFixTest { buf.append("public class E {\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JavadocQuickFixTest9.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JavadocQuickFixTest9.java new file mode 100644 index 0000000000..ff88329b51 --- /dev/null +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/JavadocQuickFixTest9.java @@ -0,0 +1,806 @@ +/******************************************************************************* + * Copyright (c) 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Red Hat Inc. - new Javadoc quickfix test based on QuickFixTest9 + *******************************************************************************/ +package org.eclipse.jdt.ui.tests.quickfix; + +import java.util.ArrayList; +import java.util.Hashtable; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import org.eclipse.jdt.testplugin.JavaProjectHelper; +import org.eclipse.jdt.testplugin.TestOptions; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; + +import org.eclipse.jdt.internal.core.manipulation.CodeTemplateContextType; +import org.eclipse.jdt.internal.core.manipulation.StubUtility; + +import org.eclipse.jdt.ui.tests.core.rules.Java9ProjectTestSetup; +import org.eclipse.jdt.ui.tests.core.rules.ProjectTestSetup; +import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; +import org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal; + +@RunWith(JUnit4.class) +public class JavadocQuickFixTest9 extends QuickFixTest { + + @Rule + public ProjectTestSetup projectsetup = new Java9ProjectTestSetup(); + + private IJavaProject fJProject1; + + private IPackageFragmentRoot fSourceFolder; + + @Before + public void setUp() throws Exception { + Hashtable<String, String> options= TestOptions.getDefaultOptions(); + options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); + options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); + options.put(JavaCore.COMPILER_PB_INVALID_JAVADOC, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_METHOD_TYPE_PARAMETERS, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING, JavaCore.ENABLED); + JavaCore.setOptions(options); + + StringBuilder comment= new StringBuilder(); + comment.append("/**\n"); + comment.append(" * A comment.\n"); + comment.append(" * ${tags}\n"); + comment.append(" */"); + String res= comment.toString(); + StubUtility.setCodeTemplate(CodeTemplateContextType.CONSTRUCTORCOMMENT_ID, res, null); + StubUtility.setCodeTemplate(CodeTemplateContextType.METHODCOMMENT_ID, res, null); + StubUtility.setCodeTemplate(CodeTemplateContextType.TYPECOMMENT_ID, res, null); + + comment= new StringBuilder(); + comment.append("/**\n"); + comment.append(" * A field comment for ${field}.\n"); + comment.append(" */"); + StubUtility.setCodeTemplate(CodeTemplateContextType.FIELDCOMMENT_ID, comment.toString(), null); + + comment= new StringBuilder(); + comment.append("/**\n"); + comment.append(" * A override comment.\n"); + comment.append(" * ${see_to_overridden}\n"); + comment.append(" */"); + StubUtility.setCodeTemplate(CodeTemplateContextType.OVERRIDECOMMENT_ID, comment.toString(), null); + + comment= new StringBuilder(); + comment.append("/**\n"); + comment.append(" * A delegate comment.\n"); + comment.append(" * ${see_to_target}\n"); + comment.append(" */"); + StubUtility.setCodeTemplate(CodeTemplateContextType.DELEGATECOMMENT_ID, comment.toString(), null); + + comment= new StringBuilder(); + comment.append("/**\n"); + comment.append(" * A module comment.\n"); + comment.append(" * ${tags}\n"); + comment.append(" */"); + StubUtility.setCodeTemplate(CodeTemplateContextType.MODULECOMMENT_ID, comment.toString(), null); + + fJProject1= JavaProjectHelper.createJavaProject("TestProject1", "bin"); + JavaProjectHelper.set9CompilerOptions(fJProject1); + JavaProjectHelper.addRequiredModularProject(fJProject1, Java9ProjectTestSetup.getProject()); + + fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); + } + + @After + public void tearDown() throws Exception { + JavaProjectHelper.clear(fJProject1, ProjectTestSetup.getDefaultClasspath()); + } + + @Test + public void testMissingModuleComment() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("public class MyFormattable implements Formattable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); + + assertNumberOfProposals(proposals, 2); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * A module comment.\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + String expected= buf.toString(); + assertEqualString(preview1, expected); + } + + @Test + public void testMissingUsesTag1() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("public class MyFormattable implements Formattable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); + + assertNumberOfProposals(proposals, 3); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + + String expected= buf.toString(); + assertEqualString(preview1, expected); + + CUCorrectionProposal proposal2= (CUCorrectionProposal) proposals.get(1); + String preview2= getPreviewContent(proposal2); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + String expected2= buf.toString(); + assertEqualString(preview2, expected2); + } + + @Test + public void testMissingUsesTag2() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import java.utio.Formatter;\n"); + buf.append("public class MyFormattable implements Formattable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import java.lang.Appendable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" uses Appendable;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); + + assertNumberOfProposals(proposals, 3); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import java.lang.Appendable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses Appendable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" uses Appendable;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + + String expected= buf.toString(); + assertEqualString(preview1, expected); + + CUCorrectionProposal proposal2= (CUCorrectionProposal) proposals.get(1); + String preview2= getPreviewContent(proposal2); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import java.lang.Appendable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses Appendable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" uses Appendable;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + String expected2= buf.toString(); + assertEqualString(preview2, expected2); + } + + @Test + public void testMissingUsesTag3() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import java.utio.Formatter;\n"); + buf.append("public class MyFormattable implements Formattable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import java.lang.Appendable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" uses Appendable;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 2, null); + + assertNumberOfProposals(proposals, 3); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import java.lang.Appendable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" uses Appendable;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + + String expected= buf.toString(); + assertEqualString(preview1, expected); + + CUCorrectionProposal proposal2= (CUCorrectionProposal) proposals.get(1); + String preview2= getPreviewContent(proposal2); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import java.lang.Appendable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses Appendable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" uses Appendable;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + String expected2= buf.toString(); + assertEqualString(preview2, expected2); + } + + @Test + public void testMissingProvidesTag1() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("public class MyFormattable implements Formattable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); + + assertNumberOfProposals(proposals, 3); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + + String expected= buf.toString(); + assertEqualString(preview1, expected); + + CUCorrectionProposal proposal2= (CUCorrectionProposal) proposals.get(1); + String preview2= getPreviewContent(proposal2); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + String expected2= buf.toString(); + assertEqualString(preview2, expected2); + } + + @Test + public void testMissingProvidesTag2() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("public class MyFormattable implements Formattable, Appendable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append(" @Override\n"); + buf.append(" public Appendable append(CharSequence csq) throws IOException {\n"); + buf.append(" return null;\n"); + buf.append(" }\n"); + buf.append(" @Override\n"); + buf.append(" public Appendable append(CharSequence csq, int start, int end) throws IOException {\n"); + buf.append(" return null;\n"); + buf.append(" }\n"); + buf.append(" @Override\n"); + buf.append(" public Appendable append(char c) throws IOException {\n"); + buf.append(" return null;\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" provides Appendable with MyFormattable;\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 2, null); + + assertNumberOfProposals(proposals, 3); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Appendable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" provides Appendable with MyFormattable;\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + + String expected= buf.toString(); + assertEqualString(preview1, expected); + + CUCorrectionProposal proposal2= (CUCorrectionProposal) proposals.get(1); + String preview2= getPreviewContent(proposal2); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @provides Appendable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" provides Appendable with MyFormattable;\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + String expected2= buf.toString(); + assertEqualString(preview2, expected2); + } + + @Test + public void testDuplicateUsesTag1() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("public class MyFormattable implements Formattable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); + + assertNumberOfProposals(proposals, 2); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + + String expected= buf.toString(); + assertEqualString(preview1, expected); + } + + @Test + public void testDuplicateUsesTag2() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("public class MyFormattable implements Formattable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); + + assertNumberOfProposals(proposals, 2); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" * @provides Formattable*/\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + + String expected= buf.toString(); + assertEqualString(preview1, expected); + } + + @Test + public void testDuplicateProvidesTag1() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("public class MyFormattable implements Formattable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); + + assertNumberOfProposals(proposals, 2); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + + String expected= buf.toString(); + assertEqualString(preview1, expected); + } + + @Test + public void testDuplicateProvidesTag2() throws Exception { + IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null); + StringBuilder buf= new StringBuilder(); + buf.append("package test;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("public class MyFormattable implements Formattable {\n"); + buf.append(" @Override\n"); + buf.append(" public void formatTo(Formatter formatter, int flags, int width, int precision) {\n"); + buf.append(" }\n"); + buf.append("}\n"); + @SuppressWarnings("unused") + ICompilationUnit cu1= pack.createCompilationUnit("MyFormattable.java", buf.toString(), false, null); + + IPackageFragment pack1= fSourceFolder.createPackageFragment("", false, null); + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener\n"); + buf.append(" * @provides Formattable */\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + ICompilationUnit cu= pack1.createCompilationUnit("module-info.java", buf.toString(), false, null); + + CompilationUnit astRoot= getASTRoot(cu); + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); + + assertNumberOfProposals(proposals, 2); + assertCorrectLabels(proposals); + + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); + String preview1= getPreviewContent(proposal); + + buf= new StringBuilder(); + buf.append("import java.util.EventListener;\n"); + buf.append("import java.util.Formattable;\n"); + buf.append("import test.MyFormattable;\n"); + buf.append("/**\n"); + buf.append(" * module test\n"); + buf.append(" * @provides Formattable\n"); + buf.append(" * @uses EventListener*/\n"); + buf.append("module test {\n"); + buf.append(" uses EventListener;\n"); + buf.append(" provides Formattable with MyFormattable;\n"); + buf.append("}\n"); + + String expected= buf.toString(); + assertEqualString(preview1, expected); + } + +} diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest18.java index e911f3e178..c5c1c0011b 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest18.java @@ -1345,13 +1345,13 @@ public class LocalCorrectionsQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 1); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 6); - + buf= new StringBuffer(); buf.append("package pack;\n"); buf.append("import java.util.*;\n"); @@ -1362,7 +1362,7 @@ public class LocalCorrectionsQuickFixTest18 extends QuickFixTest { buf.append(" ArrayList<String> x=new ArrayList<String>();\n"); buf.append(" }\n"); buf.append("}\n"); - + assertProposalPreviewEquals(buf.toString(), "Change type to 'ArrayList<String>'", proposals); } finally { NullTestUtils.disableAnnotationBasedNullAnalysis(fSourceFolder); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest9.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest9.java index dcb6a27099..f4ef75038b 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest9.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest9.java @@ -116,7 +116,7 @@ public class ModifierCorrectionsQuickFixTest9 extends QuickFixTest { assertExpectedExistInProposals(proposals, expected); } - + @Test public void testAddSafeVarargs2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("p", false, null); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest.java index 1be4f07aad..b37ea9acc4 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest.java @@ -2063,16 +2063,16 @@ public class NullAnnotationsQuickFixTest extends QuickFixTest { StringBuilder buf= new StringBuilder(); buf.append("package test1;\n"); ICompilationUnit cu= pack1.createCompilationUnit("package-info.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 2); CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0); - + assertEqualString(proposal.getDisplayString(), "Add '@NonNullByDefault' to the package declaration"); - + String preview= getPreviewContent(proposal); - + buf= new StringBuilder(); buf.append("@org.eclipse.jdt.annotation.NonNullByDefault\n"); buf.append("package test1;\n"); @@ -2108,14 +2108,14 @@ public class NullAnnotationsQuickFixTest extends QuickFixTest { assertNumberOfProposals(proposals, 2); IJavaCompletionProposal proposal= proposals.get(0); - + assertEqualString(proposal.getDisplayString(), "Add package-info.java with '@NonNullByDefault'"); proposal.apply(null); cu.getJavaProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); assertEquals(0, pack1.getResource().findMarkers(null, true, IResource.DEPTH_INFINITE).length); - + ICompilationUnit packageInfoCU= pack1.getCompilationUnit("package-info.java"); StringBuilder expected=new StringBuilder(); expected.append("/**\n"); @@ -2288,7 +2288,7 @@ public class NullAnnotationsQuickFixTest extends QuickFixTest { ((CreatePackageInfoWithDefaultNullnessProposal) proposal).resolve(problems, new NullProgressMonitor()); cu1.getJavaProject().getProject().getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null); - + assertEquals(0, cu1.getJavaProject().getProject().findMarkers(null, true, IResource.DEPTH_INFINITE).length); assertEquals(0, cu2.getJavaProject().getProject().findMarkers(null, true, IResource.DEPTH_INFINITE).length); @@ -2384,7 +2384,7 @@ public class NullAnnotationsQuickFixTest extends QuickFixTest { ((CreatePackageInfoWithDefaultNullnessProposal) proposal).resolve(problems, new NullProgressMonitor()); cu1.getJavaProject().getProject().getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null); - + assertEquals(0, cu1.getJavaProject().getProject().findMarkers(null, true, IResource.DEPTH_INFINITE).length); assertEquals(0, cu2.getJavaProject().getProject().findMarkers(null, true, IResource.DEPTH_INFINITE).length); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest18.java index a80554243b..0d82841ae3 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest18.java @@ -133,7 +133,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@org.eclipse.jdt.annotation.NonNullByDefault\n"); buf.append("package test1;\n"); pack1.createCompilationUnit("package-info.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import org.eclipse.jdt.annotation.*;\n"); @@ -241,7 +241,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@org.eclipse.jdt.annotation.NonNullByDefault\n"); buf.append("package test1;\n"); pack1.createCompilationUnit("package-info.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import org.eclipse.jdt.annotation.*;\n"); @@ -399,7 +399,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@org.eclipse.jdt.annotation.NonNullByDefault\n"); buf.append("package test1;\n"); pack1.createCompilationUnit("package-info.java", buf.toString(), true, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import org.eclipse.jdt.annotation.*;\n"); @@ -473,7 +473,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@org.eclipse.jdt.annotation.NonNullByDefault\n"); buf.append("package test1;\n"); pack1.createCompilationUnit("package-info.java", buf.toString(), true, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -565,7 +565,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@org.eclipse.jdt.annotation.NonNullByDefault\n"); buf.append("package test1;\n"); pack1.createCompilationUnit("package-info.java", buf.toString(), true, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -656,7 +656,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@org.eclipse.jdt.annotation.NonNullByDefault\n"); buf.append("package test1;\n"); pack1.createCompilationUnit("package-info.java", buf.toString(), true, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -672,16 +672,16 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("Test.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 4); CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0); - + assertEqualString(proposal.getDisplayString(), "Create field 'x'"); - + String preview= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -699,13 +699,13 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); assertEqualString(preview, buf.toString()); - + proposal= (CUCorrectionProposal)proposals.get(1); - + assertEqualString(proposal.getDisplayString(), "Create parameter 'x'"); - + preview= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -721,13 +721,13 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); assertEqualString(preview, buf.toString()); - + proposal= (CUCorrectionProposal)proposals.get(2); - + assertEqualString(proposal.getDisplayString(), "Create local variable 'x'"); - + preview= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -762,16 +762,16 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("Test.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 3); CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0); - + assertEqualString(proposal.getDisplayString(), "Add cast to 'Map<String, Integer>'"); - + String preview= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -794,7 +794,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@org.eclipse.jdt.annotation.NonNullByDefault\n"); buf.append("package test1;\n"); pack1.createCompilationUnit("package-info.java", buf.toString(), true, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -885,7 +885,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@org.eclipse.jdt.annotation.NonNullByDefault\n"); buf.append("package test1;\n"); pack1.createCompilationUnit("package-info.java", buf.toString(), true, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -1024,11 +1024,11 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@NonNullByDefault\n"); buf.append("public class B extends A {\n"); buf.append(" @Override\n"); - buf.append(" public void SomeMethod(\n"); - buf.append(" String[] a)\n"); + buf.append(" public void SomeMethod(\n"); + buf.append(" String[] a)\n"); buf.append(" {\n"); buf.append("\n"); - buf.append(" }\n"); + buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu=pack1.createCompilationUnit("B.java", buf.toString(), false, null); @@ -1047,11 +1047,11 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@NonNullByDefault\n"); buf.append("public class B extends A {\n"); buf.append(" @Override\n"); - buf.append(" public void SomeMethod(\n"); - buf.append(" String @Nullable [] a)\n"); + buf.append(" public void SomeMethod(\n"); + buf.append(" String @Nullable [] a)\n"); buf.append(" {\n"); buf.append("\n"); - buf.append(" }\n"); + buf.append(" }\n"); buf.append("}\n"); assertEqualString(preview, buf.toString()); } @@ -1076,11 +1076,11 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@NonNullByDefault\n"); buf.append("public class B extends A {\n"); buf.append(" @Override\n"); - buf.append(" public void SomeMethod(\n"); - buf.append(" int[][] a)\n"); + buf.append(" public void SomeMethod(\n"); + buf.append(" int[][] a)\n"); buf.append(" {\n"); buf.append("\n"); - buf.append(" }\n"); + buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu=pack1.createCompilationUnit("B.java", buf.toString(), false, null); @@ -1099,11 +1099,11 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("@NonNullByDefault\n"); buf.append("public class B extends A {\n"); buf.append(" @Override\n"); - buf.append(" public void SomeMethod(\n"); - buf.append(" int @Nullable [][] a)\n"); + buf.append(" public void SomeMethod(\n"); + buf.append(" int @Nullable [][] a)\n"); buf.append(" {\n"); buf.append("\n"); - buf.append(" }\n"); + buf.append(" }\n"); buf.append("}\n"); assertEqualString(preview, buf.toString()); } @@ -1127,11 +1127,11 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("import org.eclipse.jdt.annotation.*;\n"); buf.append("public class B extends A {\n"); buf.append(" @Override\n"); - buf.append(" public void SomeMethod(\n"); - buf.append(" String @NonNull [] a)\n"); + buf.append(" public void SomeMethod(\n"); + buf.append(" String @NonNull [] a)\n"); buf.append(" {\n"); buf.append("\n"); - buf.append(" }\n"); + buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu=pack1.createCompilationUnit("B.java", buf.toString(), false, null); @@ -1149,11 +1149,11 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append("import org.eclipse.jdt.annotation.*;\n"); buf.append("public class B extends A {\n"); buf.append(" @Override\n"); - buf.append(" public void SomeMethod(\n"); - buf.append(" String @Nullable [] a)\n"); + buf.append(" public void SomeMethod(\n"); + buf.append(" String @Nullable [] a)\n"); buf.append(" {\n"); buf.append("\n"); - buf.append(" }\n"); + buf.append(" }\n"); buf.append("}\n"); assertEqualString(preview, buf.toString()); } @@ -1180,7 +1180,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append(" public String[][][] SomeMethod()\n"); buf.append(" {\n"); buf.append(" return new String[0][][];\n"); - buf.append(" }\n"); + buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu=pack1.createCompilationUnit("B.java", buf.toString(), false, null); @@ -1203,12 +1203,12 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append(" public String @NonNull [][][] SomeMethod()\n"); buf.append(" {\n"); buf.append(" return new String[0][][];\n"); - buf.append(" }\n"); + buf.append(" }\n"); buf.append("}\n"); assertEqualString(preview, buf.toString()); } @Test - public void testBug525424() throws Exception { + public void testBug525424() throws Exception { Hashtable<String, String> options= JavaCore.getOptions(); try { Hashtable<String, String> myOptions= new Hashtable<>(options); @@ -1312,7 +1312,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { JavaCore.setOptions(options); } } - public void runBug531511Test(boolean useTypeAnnotations, String defaultNullnessAnnotations, boolean expectReturnAnnotation, boolean expectParamAnnotation) throws Exception { + public void runBug531511Test(boolean useTypeAnnotations, String defaultNullnessAnnotations, boolean expectReturnAnnotation, boolean expectParamAnnotation) throws Exception { Map<String, String> options= fJProject1.getOptions(false); try { Hashtable<String, String> myOptions= new Hashtable<>(options); @@ -1448,7 +1448,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { buf.append(" @NonNull public Object someMethod(@NonNull Object p);\n"); buf.append("}\n"); api.createCompilationUnit("I.java", buf.toString(), false, null); - + IPackageFragment test= fSourceFolder.createPackageFragment("test", false, null); buf= new StringBuffer(); buf.append("@my.NonNullByDefault(my.DefaultLocation.TYPE_BOUND)\n"); // create irrelevant package default, so no tested combination will be redunant @@ -1459,7 +1459,7 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { fJProject1.getProject().getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); IMarker[] markers= fJProject1.getResource().findMarkers(null, true, IResource.DEPTH_INFINITE); assertEquals(0, markers.length); - + // actual test begins here buf= new StringBuffer(); buf.append("package test;\n"); @@ -1502,91 +1502,91 @@ public class NullAnnotationsQuickFixTest18 extends QuickFixTest { } @Test - public void testBug531511_none_type() throws Exception { + public void testBug531511_none_type() throws Exception { runBug531511Test(true, "", true, true); } @Test - public void testBug531511_none_decl() throws Exception { + public void testBug531511_none_decl() throws Exception { runBug531511Test(false, "", true, true); } @Test - public void testBug531511_combined_multi_first_type() throws Exception { + public void testBug531511_combined_multi_first_type() throws Exception { runBug531511Test(true, "@NNApi @NNFields", false, false); } @Test - public void testBug531511_combined_multi_first_decl() throws Exception { + public void testBug531511_combined_multi_first_decl() throws Exception { runBug531511Test(false, "@NNApi @NNFields", false, false); } @Test - public void testBug531511_combined_multi_second_type() throws Exception { + public void testBug531511_combined_multi_second_type() throws Exception { runBug531511Test(true, "@NNApi @NNFields", false, false); } @Test - public void testBug531511_combined_multi_second_decl() throws Exception { + public void testBug531511_combined_multi_second_decl() throws Exception { runBug531511Test(false, "@NNApi @NNFields", false, false); } @Test - public void testBug531511_param_multi_first_type() throws Exception { + public void testBug531511_param_multi_first_type() throws Exception { runBug531511Test(true, "@NNParams @NNFields", true, false); } @Test - public void testBug531511_param_multi_first_decl() throws Exception { + public void testBug531511_param_multi_first_decl() throws Exception { runBug531511Test(false, "@NNParams @NNFields", true, false); } @Test - public void testBug531511_param_multi_second_type() throws Exception { + public void testBug531511_param_multi_second_type() throws Exception { runBug531511Test(true, "@NNFields @NNParams", true, false); } @Test - public void testBug531511_param_multi_second_decl() throws Exception { + public void testBug531511_param_multi_second_decl() throws Exception { runBug531511Test(false, "@NNFields @NNParams", true, false); } @Test - public void testBug531511_return_multi_first_type() throws Exception { + public void testBug531511_return_multi_first_type() throws Exception { runBug531511Test(true, "@NNReturn @NNFields", false, true); } @Test - public void testBug531511_return_multi_first_decl() throws Exception { + public void testBug531511_return_multi_first_decl() throws Exception { runBug531511Test(false, "@NNReturn @NNFields", false, true); } @Test - public void testBug531511_return_multi_second_type() throws Exception { + public void testBug531511_return_multi_second_type() throws Exception { runBug531511Test(true, "@NNFields @NNReturn", false, true); } @Test - public void testBug531511_return_multi_second_decl() throws Exception { + public void testBug531511_return_multi_second_decl() throws Exception { runBug531511Test(false, "@NNFields @NNReturn", false, true); } @Test - public void testBug531511_boolean_default_type() throws Exception { + public void testBug531511_boolean_default_type() throws Exception { runBug531511Test(true, "@NNBDBoolean", false, false); } @Test - public void testBug531511_boolean_default_decl() throws Exception { + public void testBug531511_boolean_default_decl() throws Exception { runBug531511Test(false, "@NNBDBoolean", false, false); } @Test - public void testBug531511_boolean_true_type() throws Exception { + public void testBug531511_boolean_true_type() throws Exception { runBug531511Test(true, "@NNBDBoolean(true)", false, false); } @Test - public void testBug531511_boolean_true_decl() throws Exception { + public void testBug531511_boolean_true_decl() throws Exception { runBug531511Test(false, "@NNBDBoolean(true)", false, false); } @Test - public void testBug531511_boolean_false_type() throws Exception { + public void testBug531511_boolean_false_type() throws Exception { runBug531511Test(true, "@NNBDBoolean(false)", true, true); } @Test - public void testBug531511_boolean_false_decl() throws Exception { + public void testBug531511_boolean_false_decl() throws Exception { runBug531511Test(false, "@NNBDBoolean(false)", true, true); } @Test - public void testBug531511_unconfigurable_type() throws Exception { + public void testBug531511_unconfigurable_type() throws Exception { runBug531511Test(true, "@NNBDUnconfigurable", false, false); } @Test - public void testBug531511_unconfigurable_decl() throws Exception { + public void testBug531511_unconfigurable_decl() throws Exception { runBug531511Test(false, "@NNBDUnconfigurable", false, false); } } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest9.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest9.java index 26191375dc..0a7f71ea5b 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest9.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/NullAnnotationsQuickFixTest9.java @@ -154,7 +154,7 @@ public class NullAnnotationsQuickFixTest9 extends QuickFixTest { def.createCompilationUnit("module-info.java", buf.toString(), false, null); IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.Map;\n"); @@ -244,7 +244,7 @@ public class NullAnnotationsQuickFixTest9 extends QuickFixTest { def.createCompilationUnit("module-info.java", buf.toString(), false, null); IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import annots.*;\n"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/PropertiesFileQuickAssistTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/PropertiesFileQuickAssistTest.java index b185c125cf..2d7fa76914 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/PropertiesFileQuickAssistTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/PropertiesFileQuickAssistTest.java @@ -200,7 +200,7 @@ public class PropertiesFileQuickAssistTest { buf.append("Test_1=Hello1\n"); buf.append("Test_2=Hello2\n"); IFile file= createPropertyFile(pack1, "Accessor.properties", buf.toString()); - + int offset= buf.toString().indexOf("est_1"); PropertiesAssistContext context= createAssistContext(file, offset, 0); List<ICompletionProposal> proposals= collectAssists(context); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest.java index 477d670e84..0513256e54 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest.java @@ -107,6 +107,7 @@ import org.junit.runners.Suite; ChangeNonStaticToStaticTest.class, MarkerResolutionTest.class, JavadocQuickFixTest.class, + JavadocQuickFixTest9.class, ConvertForLoopQuickFixTest.class, ConvertIterableLoopQuickFixTest.class, AdvancedQuickAssistTest.class, @@ -276,7 +277,7 @@ public class QuickFixTest { protected static final ArrayList<ICompletionProposal> collectAllCorrections(ICompilationUnit cu, CompilationUnit astRoot, int nProblems) throws CoreException { IProblem[] problems= astRoot.getProblems(); assertNumberOfProblems(nProblems, problems); - + ArrayList<ICompletionProposal> corrections= new ArrayList<>(); for (int i= 0; i < nProblems; i++) { corrections.addAll(collectCorrections(cu, problems[i], null)); @@ -447,7 +448,7 @@ public class QuickFixTest { } return previewContent; } - + private static String getSEFPreviewContent(SelfEncapsulateFieldProposal sefp) throws CoreException { ICompilationUnit compilationUnit= sefp.getField().getCompilationUnit(); TextFileChange change= sefp.getChange((IFile) compilationUnit.getResource()); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java index 5f0e1a9c04..3e504f13e1 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest18.java @@ -1516,7 +1516,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append("}\n"); assertEqualString(preview, buf.toString()); } - + // remove redundant @NonNull on field type @Test public void testRemoveRedundantNonNull() throws Exception { @@ -1559,7 +1559,7 @@ public class QuickFixTest18 extends QuickFixTest { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); JavaCore.setOptions(options); JavaProjectHelper.addLibrary(fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path())); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf; @@ -1623,7 +1623,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append(" i2.h(n1, n2);\n"); buf.append(" }\n"); buf.append("}"); - assertProposalPreviewEquals(buf.toString(), "Change method 'g(Number, Number)' to 'g(Boolean, Boolean)'", proposals1); + assertProposalPreviewEquals(buf.toString(), "Change method 'g(Number, Number)' to 'g(Boolean, Boolean)'", proposals1); buf= new StringBuffer(); buf.append("package test1;\n"); @@ -1648,7 +1648,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append(" i2.h(n1, n2);\n"); buf.append(" }\n"); buf.append("}"); - assertProposalPreviewEquals(buf.toString(), "Change method 'h(Number, Number)' to 'h(Boolean, Boolean)'", proposals2); + assertProposalPreviewEquals(buf.toString(), "Change method 'h(Number, Number)' to 'h(Boolean, Boolean)'", proposals2); } @Test public void testBug514580_avoidRedundantNonNullInTypeChange_field() throws Exception { @@ -1656,7 +1656,7 @@ public class QuickFixTest18 extends QuickFixTest { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); JavaCore.setOptions(options); JavaProjectHelper.addLibrary(fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path())); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf; @@ -1746,7 +1746,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append("\n"); buf.append(" }\n"); buf.append("}"); - assertProposalPreviewEquals(buf.toString(), "Change type of 'f1' to 'String'", proposals1); + assertProposalPreviewEquals(buf.toString(), "Change type of 'f1' to 'String'", proposals1); buf= new StringBuffer(); buf.append("package test1;\n"); @@ -1821,7 +1821,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append("\n"); buf.append(" }\n"); buf.append("}"); - assertProposalPreviewEquals(buf.toString(), "Change return type of 'g(..)' to 'Map<? extends Number, Integer>[]'", proposals1); + assertProposalPreviewEquals(buf.toString(), "Change return type of 'g(..)' to 'Map<? extends Number, Integer>[]'", proposals1); buf= new StringBuffer(); buf.append("package test1;\n"); @@ -1858,7 +1858,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append("\n"); buf.append(" }\n"); buf.append("}"); - assertProposalPreviewEquals(buf.toString(), "Change return type of 'g(..)' to 'Map<? extends Number, Integer>[]'", proposals2); + assertProposalPreviewEquals(buf.toString(), "Change return type of 'g(..)' to 'Map<? extends Number, Integer>[]'", proposals2); } @Test public void testBug514580_avoidRedundantNonNullInTypeChange_local() throws Exception { @@ -1866,7 +1866,7 @@ public class QuickFixTest18 extends QuickFixTest { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); JavaCore.setOptions(options); JavaProjectHelper.addLibrary(fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path())); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf; @@ -1954,7 +1954,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); buf.append(""); - assertProposalPreviewEquals(buf.toString(), "Change type of 'l1' to 'String'", proposals1); + assertProposalPreviewEquals(buf.toString(), "Change type of 'l1' to 'String'", proposals1); buf= new StringBuffer(); buf.append("package test1;\n"); @@ -1991,7 +1991,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); buf.append(""); - assertProposalPreviewEquals(buf.toString(), "Change type of 'l2' to 'String'", proposals2); + assertProposalPreviewEquals(buf.toString(), "Change type of 'l2' to 'String'", proposals2); buf= new StringBuffer(); buf.append("package test1;\n"); @@ -2027,7 +2027,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); buf.append(""); - assertProposalPreviewEquals(buf.toString(), "Change return type of 'h(..)' to 'Map<? extends Number, Integer>[]'", proposals1); + assertProposalPreviewEquals(buf.toString(), "Change return type of 'h(..)' to 'Map<? extends Number, Integer>[]'", proposals1); buf= new StringBuffer(); buf.append("package test1;\n"); @@ -2063,7 +2063,7 @@ public class QuickFixTest18 extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); buf.append(""); - assertProposalPreviewEquals(buf.toString(), "Change return type of 'h(..)' to 'Map<? extends Number, Integer>[]'", proposals2); + assertProposalPreviewEquals(buf.toString(), "Change return type of 'h(..)' to 'Map<? extends Number, Integer>[]'", proposals2); } // bug 420116 : create parameter quickfix should be offered diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest9.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest9.java index d0418786dc..f203491f3d 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest9.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/QuickFixTest9.java @@ -166,7 +166,7 @@ public class QuickFixTest9 extends QuickFixTest { proposals= collectCorrections(cu, astRoot, 2, 1); assertProposalExists(proposals, proposalStr); } - + @Test public void testAddModuleRequiresProposalForFullyQualifiedType() throws Exception { StringBuffer buf= new StringBuffer(); @@ -190,7 +190,7 @@ public class QuickFixTest9 extends QuickFixTest { assertProposalExists(proposals, proposalStr); } - + @Test public void testAddNewTypeProposals() throws Exception { StringBuilder buf= new StringBuilder(); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeAnnotationQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeAnnotationQuickFixTest.java index af6e666ed5..36ce3f5a99 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeAnnotationQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeAnnotationQuickFixTest.java @@ -134,10 +134,10 @@ public class TypeAnnotationQuickFixTest extends QuickFixTest { for (int p= 0; p < nProblems; p++) { ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, nProblems, p, null); assertCorrectLabels(proposals); - + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview= getPreviewContent(proposal); - + String expected= prefix + "public class Test {\n" + testCaseSpecificOutputs[p] + "\n" + @@ -310,7 +310,7 @@ public class TypeAnnotationQuickFixTest extends QuickFixTest { "@Nullable test.File f1a, f1b;", "test.@Nullable File f1a, f1b;"); } - + @Test public void testNormalAnnotationP4() throws Exception { runQuickFixTest( diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java index 91e9bdc305..75a1aaf48d 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java @@ -727,7 +727,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { tempOptions.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.WARNING); tempOptions.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.WARNING); fJProject1.setOptions(tempOptions); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf= new StringBuffer(); buf.append("package test1;\n"); @@ -738,14 +738,14 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 6); - + String[] expected= new String[2]; - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.*;\n"); @@ -765,11 +765,11 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); - - - + + + } finally { fJProject1.setOptions(options); } @@ -787,14 +787,14 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 1); - + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview1= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.util.*;\n"); @@ -804,9 +804,9 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 }); - + Accessor accessor= new Accessor(proposal, TypeChangeCorrectionProposal.class); ITypeBinding[] typeProposals= (ITypeBinding[]) accessor.get("fTypeProposals"); String[] typeNames= new String[typeProposals.length]; @@ -827,7 +827,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { }; assertArrayEquals(expectedNames, typeNames); } - + @Test public void testTypeMismatchInFieldDecl() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -879,15 +879,15 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 1); assertCorrectLabels(proposals); - + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview1= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -898,10 +898,10 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertEqualString(preview1, expected1); } - + @Test public void testTypeMismatchInAssignment() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -1427,7 +1427,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { @Test public void testMismatchingReturnTypeOnGenericMethod() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - + StringBuffer buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.lang.annotation.Annotation;\n"); @@ -1441,15 +1441,15 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 1); assertCorrectLabels(proposals); - + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview1= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.lang.annotation.Annotation;\n"); @@ -1463,7 +1463,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 }); } @@ -1475,7 +1475,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { JavaModelUtil.setComplianceOptions(options14, JavaCore.VERSION_1_4); fJProject1.setOptions(options14); IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - + StringBuffer buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.lang.reflect.AccessibleObject;\n"); @@ -1488,15 +1488,15 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); assertNumberOfProposals(proposals, 1); assertCorrectLabels(proposals); - + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview1= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("import java.lang.annotation.Annotation;\n"); @@ -1510,13 +1510,13 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertEqualStringsIgnoreOrder(new String[] { preview1 }, new String[] { expected1 }); } finally { fJProject1.setOptions(options); } } - + @Test public void testMismatchingReturnTypeParameterized() throws Exception { // test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=165913 @@ -1908,7 +1908,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); } - + @Test public void testMismatchingExceptionsOnBinaryParent() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -2217,7 +2217,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { assertExpectedExistInProposals(proposals, expected); } - + @Test public void testTypeMismatchInForEachProposalsListExtends() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); @@ -2234,13 +2234,13 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 1); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package pack;\n"); @@ -2255,10 +2255,10 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } - + @Test public void testTypeMismatchInForEachProposalsListSuper() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); @@ -2275,13 +2275,13 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 1); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package pack;\n"); @@ -2296,7 +2296,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } @@ -2354,13 +2354,13 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 3, 2); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 1); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package pack;\n"); @@ -2372,10 +2372,10 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } - + @Test public void testNullCheck() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); @@ -2425,7 +2425,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { assertExpectedExistInProposals(proposals, expected); } - + @Test public void testTypeMismatchObjectAndPrimitiveType() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); @@ -2449,7 +2449,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { ICompletionProposal proposal= proposals.get(0); assertTrue(proposal.getDisplayString().indexOf("Integer") != -1); - + String[] expected= new String[3]; buf= new StringBuffer(); buf.append("package pack;\n"); @@ -2489,7 +2489,7 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { assertExpectedExistInProposals(proposals, expected); } - + @Test public void testTypeMismatchPrimitiveTypes() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); @@ -2512,13 +2512,13 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { ICompletionProposal proposal= proposals.get(0); assertTrue(proposal.getDisplayString().indexOf("Integer") == -1); - + ICompletionProposal proposal2= proposals.get(1); assertTrue(proposal2.getDisplayString().indexOf("Integer") == -1); - + ICompletionProposal proposal3= proposals.get(2); assertTrue(proposal3.getDisplayString().indexOf("Integer") == -1); - + String[] expected= new String[3]; buf= new StringBuffer(); buf.append("package pack;\n"); @@ -2555,5 +2555,5 @@ public class TypeMismatchQuickFixTests extends QuickFixTest { assertExpectedExistInProposals(proposals, expected); } - + } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeParameterMismatchTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeParameterMismatchTest.java index 3d90b6c5f3..0f105ebb3c 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeParameterMismatchTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeParameterMismatchTest.java @@ -152,13 +152,13 @@ public class TypeParameterMismatchTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("A.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 2); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("import java.util.*;\n"); @@ -168,10 +168,10 @@ public class TypeParameterMismatchTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } - + } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java index 161d94938b..8139472346 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java @@ -658,15 +658,15 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu1=pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu1); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu1, astRoot); assertNumberOfProposals(proposals, 1); assertCorrectLabels(proposals); - + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview1= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -680,7 +680,7 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + assertEqualString(preview1, expected1); } @@ -1313,13 +1313,13 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 }); } - + @Test public void testMethodInAnonymous4() throws Exception { // bug 266032 IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf= new StringBuffer(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -1332,15 +1332,15 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu1); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu1, astRoot); assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); - + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview1= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -1356,10 +1356,10 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + proposal= (CUCorrectionProposal) proposals.get(1); String preview2= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -1372,7 +1372,7 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected2= buf.toString(); - + assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); } @@ -3061,7 +3061,7 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { "Create abstract method 'foo()' in type 'A'" }); } - + @Test public void testCreateAbstractMethodInAbstractParentWithAbstractClass() throws Exception { @@ -3602,7 +3602,7 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { public void testParameterMismatchMoreArguments4() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf= new StringBuffer(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -3612,15 +3612,15 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu1= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu1); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu1, astRoot); assertNumberOfProposals(proposals, 3); assertCorrectLabels(proposals); - + CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); String preview1= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -3630,10 +3630,10 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected1= buf.toString(); - + proposal= (CUCorrectionProposal) proposals.get(1); String preview2= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -3646,10 +3646,10 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected2= buf.toString(); - + proposal= (CUCorrectionProposal) proposals.get(2); String preview3= getPreviewContent(proposal); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class E {\n"); @@ -3659,8 +3659,8 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); String expected3= buf.toString(); - - + + assertEqualStringsIgnoreOrder(new String[] { preview1, preview2, preview3 }, new String[] { expected1, expected2, expected3 }); } @@ -5360,12 +5360,12 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { assertExpectedExistInProposals(proposals, expected); } - + @Test public void testStaticImportFavorite1() throws Exception { IPreferenceStore preferenceStore= PreferenceConstants.getPreferenceStore(); preferenceStore.setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, "java.lang.Math.*"); - try { + try { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack;\n"); @@ -5376,12 +5376,12 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); - + assertCorrectLabels(proposals); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package pack;\n"); @@ -5394,18 +5394,18 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } finally { preferenceStore.setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, ""); } } - + @Test public void testStaticImportFavorite2() throws Exception { IPreferenceStore preferenceStore= PreferenceConstants.getPreferenceStore(); preferenceStore.setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, "java.lang.Math.max"); - try { + try { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack;\n"); @@ -5416,12 +5416,12 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); - + assertCorrectLabels(proposals); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package pack;\n"); @@ -5432,7 +5432,7 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } finally { preferenceStore.setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, ""); @@ -5459,7 +5459,7 @@ public class UnresolvedMethodsQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); pack1.createCompilationUnit("A.java", buf.toString(), false, null); - + buf= new StringBuffer(); buf.append("package test2;\n"); buf.append("import test1.A;\n"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest18.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest18.java index bf8372cbbe..35ff5668d7 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest18.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest18.java @@ -411,7 +411,7 @@ public class UnresolvedMethodsQuickFixTest18 extends QuickFixTest { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); JavaCore.setOptions(options); JavaProjectHelper.addLibrary(fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path())); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf; @@ -476,7 +476,7 @@ public class UnresolvedMethodsQuickFixTest18 extends QuickFixTest { buf.append(" return null;\n"); buf.append(" }\n"); buf.append("}"); - assertProposalPreviewEquals(buf.toString(), "Create 'f()' in super type 'I1'", proposals); + assertProposalPreviewEquals(buf.toString(), "Create 'f()' in super type 'I1'", proposals); buf= new StringBuffer(); buf.append("package test1;\n"); @@ -504,7 +504,7 @@ public class UnresolvedMethodsQuickFixTest18 extends QuickFixTest { buf.append(" return null;\n"); buf.append(" }\n"); buf.append("}"); - assertProposalPreviewEquals(buf.toString(), "Create 'f()' in super type 'I2'", proposals); + assertProposalPreviewEquals(buf.toString(), "Create 'f()' in super type 'I2'", proposals); } @Test @@ -513,7 +513,7 @@ public class UnresolvedMethodsQuickFixTest18 extends QuickFixTest { options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); JavaCore.setOptions(options); JavaProjectHelper.addLibrary(fJProject1, new Path(Java18ProjectTestSetup.getJdtAnnotations20Path())); - + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); StringBuffer buf; @@ -582,7 +582,7 @@ public class UnresolvedMethodsQuickFixTest18 extends QuickFixTest { buf.append(" return x1 == x2;\n"); buf.append(" }\n"); buf.append("}"); - assertProposalPreviewEquals(buf.toString(), "Create method 'g(Number, Number)' in type 'I1'", proposals1); + assertProposalPreviewEquals(buf.toString(), "Create method 'g(Number, Number)' in type 'I1'", proposals1); buf= new StringBuffer(); buf.append("package test1;\n"); @@ -611,7 +611,7 @@ public class UnresolvedMethodsQuickFixTest18 extends QuickFixTest { buf.append(" return x1 == x2;\n"); buf.append(" }\n"); buf.append("}"); - assertProposalPreviewEquals(buf.toString(), "Create method 'g(Number, Number)' in type 'I2'", proposals2); + assertProposalPreviewEquals(buf.toString(), "Create method 'g(Number, Number)' in type 'I2'", proposals2); } @Test public void testBug528876() throws Exception { @@ -633,13 +633,13 @@ public class UnresolvedMethodsQuickFixTest18 extends QuickFixTest { buf.append("\n"); buf.append(""); ICompilationUnit cu= pack1.createCompilationUnit("Bla.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 1); - + buf= new StringBuffer(); buf.append("package pack;\n"); buf.append("import annots.*;\n"); @@ -656,7 +656,7 @@ public class UnresolvedMethodsQuickFixTest18 extends QuickFixTest { buf.append("}\n"); buf.append("\n"); buf.append(""); - + assertProposalPreviewEquals(buf.toString(), "Create attribute 'x()'", proposals); } finally { NullTestUtils.disableAnnotationBasedNullAnalysis(fSourceFolder); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedTypesQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedTypesQuickFixTest.java index 07a64b8588..1d1b1d7306 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedTypesQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedTypesQuickFixTest.java @@ -1049,10 +1049,10 @@ public class UnresolvedTypesQuickFixTest extends QuickFixTest { CompilationUnit astRoot= getASTRoot(cu); IProblem[] problems= astRoot.getProblems(); assertNumberOfProblems(2, problems); - + ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, problems[0], null); proposals.addAll(collectCorrections(cu, problems[1], null)); - + assertCorrectLabels(proposals); String[] expected= new String[3]; @@ -1523,11 +1523,11 @@ public class UnresolvedTypesQuickFixTest extends QuickFixTest { assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); } - + /** * Offers to raise visibility of method instead of class. * https://bugs.eclipse.org/bugs/show_bug.cgi?id=94755 - * + * * @throws Exception if anything goes wrong * @since 3.9 */ @@ -1537,7 +1537,7 @@ public class UnresolvedTypesQuickFixTest extends QuickFixTest { IPackageFragment pack2= fSourceFolder.createPackageFragment("test2", false, null); StringBuffer buf= new StringBuffer(); - + buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("class B {\n"); @@ -1599,13 +1599,13 @@ public class UnresolvedTypesQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 3, 1); - + assertCorrectLabels(proposals); assertNumberOfProposals(proposals, 6); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package pack;\n"); @@ -1619,7 +1619,7 @@ public class UnresolvedTypesQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } @Test diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedVariablesQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedVariablesQuickFixTest.java index fb8526ff9f..394e3ab139 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedVariablesQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedVariablesQuickFixTest.java @@ -1491,7 +1491,7 @@ public class UnresolvedVariablesQuickFixTest extends QuickFixTest { public void testStaticImportFavorite1() throws Exception { IPreferenceStore preferenceStore= PreferenceConstants.getPreferenceStore(); preferenceStore.setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, "java.lang.Math.*"); - try { + try { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); StringBuffer buf= new StringBuffer(); buf.append("package pack;\n"); @@ -1502,12 +1502,12 @@ public class UnresolvedVariablesQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); - + CompilationUnit astRoot= getASTRoot(cu); ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot); - + assertCorrectLabels(proposals); - + String[] expected= new String[1]; buf= new StringBuffer(); buf.append("package pack;\n"); @@ -1520,7 +1520,7 @@ public class UnresolvedVariablesQuickFixTest extends QuickFixTest { buf.append(" }\n"); buf.append("}\n"); expected[0]= buf.toString(); - + assertExpectedExistInProposals(proposals, expected); } finally { preferenceStore.setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, ""); @@ -2762,12 +2762,12 @@ public class UnresolvedVariablesQuickFixTest extends QuickFixTest { assertExpectedExistInProposals(proposals, expected); } - - + + /** * Wrong quick fixes when accessing protected field in subclass in different package. * https://bugs.eclipse.org/bugs/show_bug.cgi?id=280819#c2 - * + * * @throws Exception if anything goes wrong * @since 3.9 */ @@ -2775,7 +2775,7 @@ public class UnresolvedVariablesQuickFixTest extends QuickFixTest { public void testVarParameterAccess() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); IPackageFragment pack2= fSourceFolder.createPackageFragment("test2", false, null); - + StringBuffer buf= new StringBuffer(); buf.append("package test1;\n"); buf.append("public class Base {\n"); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/FileAdapterTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/FileAdapterTest.java index 01ff184ab9..cff4540697 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/FileAdapterTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/FileAdapterTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,9 +13,13 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.search; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.core.resources.IResource; @@ -23,27 +27,19 @@ import org.eclipse.search.ui.text.IFileMatchAdapter; import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.ui.tests.core.rules.JUnitSourceSetup; import org.eclipse.jdt.internal.ui.search.JavaSearchQuery; import org.eclipse.jdt.internal.ui.search.JavaSearchResult; /** */ -public class FileAdapterTest extends TestCase { - - private static final Class<FileAdapterTest> THIS= FileAdapterTest.class; - - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } +@RunWith(JUnit4.class) +public class FileAdapterTest { - public static Test setUpTest(Test test) { - return new JUnitSourceSetup(test); - } - - public FileAdapterTest(String name) { - super(name); - } + @Rule + public JUnitSourceSetup projectsetup = new JUnitSourceSetup(); + @Test public void testGetFile() throws Exception { JavaSearchQuery query= SearchTestHelper.runTypeRefQuery("junit.framework.Test"); JavaSearchResult result= (JavaSearchResult) query.getSearchResult(); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/NLSSearchTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/NLSSearchTest.java index 22af13caac..7db380ee78 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/NLSSearchTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/NLSSearchTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 IBM Corporation and others. + * Copyright (c) 2006, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -18,9 +18,12 @@ import java.io.InputStream; import java.io.Reader; import java.io.StringReader; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; @@ -43,29 +46,19 @@ import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.ui.tests.core.ProjectTestSetup; +import org.eclipse.jdt.ui.tests.core.rules.ProjectTestSetup; -public class NLSSearchTest extends TestCase { +@RunWith(JUnit4.class) +public class NLSSearchTest { - private static final Class<NLSSearchTest> THIS= NLSSearchTest.class; + @Rule + public ProjectTestSetup projectsetup = new ProjectTestSetup(); private IJavaProject fJProject1; private IPackageFragmentRoot fSourceFolder; - public NLSSearchTest(String name) { - super(name); - } - - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } - - public static Test setUpTest(Test test) { - return new ProjectTestSetup(test); - } - - @Override + @Before public void setUp() throws CoreException { fJProject1= ProjectTestSetup.getProject(); fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject1, "src"); @@ -78,8 +71,8 @@ public class NLSSearchTest extends TestCase { pack.createCompilationUnit("NLS.java", buf.toString(), false, null); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { JavaProjectHelper.clear(fJProject1, ProjectTestSetup.getDefaultClasspath()); ISearchResultViewPart searchResultView= NewSearchUI.getSearchResultView(); if (searchResultView != null) { @@ -100,6 +93,7 @@ public class NLSSearchTest extends TestCase { return file; } + @Test public void test01() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuilder buf= new StringBuilder(); @@ -117,6 +111,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 0); } + @Test public void test02() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -146,6 +141,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 0); } + @Test public void test03() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -177,6 +173,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Client_s1", (IFile)client.getCorrespondingResource(), false); } + @Test public void test04() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -208,6 +205,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertHasUnusedKey(accessor, propertiesFile, "Client_s1", propertiesFile, false); } + @Test public void test05() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -238,6 +236,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Client_s1", (IFile)accessor.getCorrespondingResource(), true); } + @Test public void test06() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -270,6 +269,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertHasDuplicateKey(accessor, propertiesFile, "Client_s1", propertiesFile); } + @Test public void testBug152604() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -299,6 +299,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 0); } + @Test public void testBug133810() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -337,6 +338,7 @@ public class NLSSearchTest extends TestCase { } } + @Test public void testBug185178() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -371,7 +373,8 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 0); } - + + @Test public void testBug247012_1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -412,6 +415,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 0); } + @Test public void testBug247012_2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -452,6 +456,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 1); } + @Test public void testBug247012_3() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -485,6 +490,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 0); } + @Test public void testBug247012_4() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -522,6 +528,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Main.undefined", (IFile)client.getCorrespondingResource(), false); } + @Test public void testBug295040() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -563,6 +570,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 0); } + @Test public void testBug306168_1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); @@ -601,6 +609,7 @@ public class NLSSearchTest extends TestCase { NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 0); } + @Test public void testBug306168_2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null); StringBuffer buf= new StringBuffer(); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/ParticipantTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/ParticipantTest.java index a03fd716af..2f7cedb07c 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/ParticipantTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/ParticipantTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,9 +13,15 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.search; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; @@ -26,6 +32,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.ui.search.IQueryParticipant; +import org.eclipse.jdt.ui.tests.core.rules.JUnitSourceSetup; import org.eclipse.jdt.internal.ui.search.JavaSearchQuery; import org.eclipse.jdt.internal.ui.search.JavaSearchResult; @@ -35,9 +42,11 @@ import org.eclipse.jdt.internal.ui.search.SearchParticipantsExtensionPoint; /** */ -public class ParticipantTest extends TestCase { +@RunWith(JUnit4.class) +public class ParticipantTest { - private static Class<ParticipantTest> THIS= ParticipantTest.class; + @Rule + public JUnitSourceSetup projectsetup = new JUnitSourceSetup(new TestExtensionPoint()); static class TestExtensionPoint extends SearchParticipantsExtensionPoint { @Override @@ -73,18 +82,7 @@ public class ParticipantTest extends TestCase { } } - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } - - public static Test setUpTest(Test test) { - return new JUnitSourceSetup(test, new TestExtensionPoint()); - } - - public ParticipantTest(String name) { - super(name); - } - + @Test public void testSimpleParticipant() throws Exception { JavaSearchQuery query= SearchTestHelper.runMethodRefQuery("frufru"); JavaSearchResult result= (JavaSearchResult) query.getSearchResult(); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchLeakTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchLeakTest.java index 3d71459c33..ecd16b6e4a 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchLeakTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchLeakTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,13 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.search; +import static org.junit.Assert.assertTrue; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + import org.eclipse.jdt.testplugin.util.DisplayHelper; import org.eclipse.swt.widgets.Display; @@ -25,13 +32,10 @@ import org.eclipse.search.ui.ISearchResultViewPart; import org.eclipse.search.ui.NewSearchUI; import org.eclipse.search.ui.text.FileTextSearchScope; -import junit.framework.Test; -import junit.framework.TestSuite; - import org.eclipse.search2.internal.ui.InternalSearchUI; import org.eclipse.jdt.ui.leaktest.LeakTestCase; -import org.eclipse.jdt.ui.leaktest.LeakTestSetup; +import org.eclipse.jdt.ui.tests.core.rules.LeakTestSetup; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.search.JavaSearchQuery; @@ -40,32 +44,13 @@ import org.eclipse.jdt.internal.ui.search.JavaSearchResult; /** * XXX: Every test in this class needs a delegate method in {@link SearchLeakTestWrapper}! */ +@RunWith(JUnit4.class) public class SearchLeakTest extends LeakTestCase { - private static final Class<SearchLeakTest> THIS= SearchLeakTest.class; - - public SearchLeakTest(String name) { - super(name); - } - - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } - - public static Test setUpTest(Test test) { - return new LeakTestSetup(new JUnitSourceSetup(test)); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } + @Rule + public LeakTestSetup projectsetup = new LeakTestSetup(); + @Test public void testRemoveSearchQueries() throws Exception { InternalSearchUI.getInstance().removeAllQueries(); JavaSearchQuery query1= SearchTestHelper.runMethodRefQuery("junit.framework.Test", "countTestCases", new String[0]); @@ -76,32 +61,34 @@ public class SearchLeakTest extends LeakTestCase { query2= null; assertInstanceCount(JavaSearchResult.class, 0); } - + + @Test public void testRemoveAllQueries() throws Exception { SearchTestHelper.runMethodRefQuery("junit.framework.Test", "countTestCases", new String[0]); SearchTestHelper.runMethodRefQuery("junit.framework.TestCase", "countTestCases", new String[0]); InternalSearchUI.getInstance().removeAllQueries(); assertInstanceCount(JavaSearchResult.class, 0); } - + + @Test public void testSearchResultEditorClose() throws Exception { assertInstanceCount(TextEditor.class, 0); - + FileTextSearchScope scope= FileTextSearchScope.newWorkspaceScope(null, false); FileSearchQuery query= new FileSearchQuery("projectDescription", false, false, scope); NewSearchUI.runQueryInForeground(null, query); ISearchResultViewPart view= NewSearchUI.getSearchResultView(); FileSearchPage page= (FileSearchPage) view.getActivePage(); - + DisplayHelper.sleep(Display.getDefault(), 2000); page.gotoNextMatch(); - + assertInstanceCount(TextEditor.class, 1); - + assertTrue(JavaPlugin.getActivePage().closeAllEditors(false)); - + assertInstanceCount(TextEditor.class, 0); - + NewSearchUI.removeQuery(query); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchLeakTestWrapper.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchLeakTestWrapper.java index 7cc1e73413..7a7112e05e 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchLeakTestWrapper.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchLeakTestWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 IBM Corporation and others. + * Copyright (c) 2007, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,11 +13,14 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.search; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; -import org.eclipse.jdt.ui.leaktest.LeakTestSetup; +import org.eclipse.jdt.ui.tests.core.rules.LeakTestSetup; /** @@ -27,46 +30,37 @@ import org.eclipse.jdt.ui.leaktest.LeakTestSetup; * * @since 3.4 */ -public class SearchLeakTestWrapper extends TestCase { +@RunWith(JUnit4.class) +public class SearchLeakTestWrapper { - private static final Class<SearchLeakTestWrapper> THIS= SearchLeakTestWrapper.class; + @Rule + public LeakTestSetup projectsetup = new LeakTestSetup(); SearchLeakTest fTest; - private String fName; - public SearchLeakTestWrapper(String name) { - super(name); - fName= name; - } - - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } - - public static Test setUpTest(Test test) { - return new LeakTestSetup(new JUnitSourceSetup(test)); - } - - @Override - protected void setUp() throws Exception { - fTest= new SearchLeakTest(fName); + @Before + public void setUp() throws Exception { + fTest= new SearchLeakTest(); fTest.setUp(); } - @Override - protected void tearDown() throws Exception { - fTest.tearDown(); + @After + public void tearDown() throws Exception { +// fTest.tearDown(); fTest= null; } + @Test public void testRemoveSearchQueries() throws Exception { fTest.testRemoveSearchQueries(); } + @Test public void testRemoveAllQueries() throws Exception { fTest.testRemoveAllQueries(); } + @Test public void testSearchResultEditorClose() throws Exception { fTest.testSearchResultEditorClose(); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchTest.java index 45401f8b24..2860591bef 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,18 +14,16 @@ package org.eclipse.jdt.ui.tests.search; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +@RunWith(Suite.class) +@Suite.SuiteClasses({ + WorkspaceReferenceTest.class, + TreeContentProviderTestWrapper.class, + ParticipantTest.class, + FileAdapterTest.class, + NLSSearchTest.class +}) public class SearchTest { - public static Test suite() { - TestSuite suite= new TestSuite(SearchTest.class.getName()); - //suite.addTestSuite(WorkspaceScopeTest.class); - suite.addTest(WorkspaceReferenceTest.suite()); - suite.addTest(TreeContentProviderTestWrapper.suite()); - suite.addTest(ParticipantTest.suite()); - suite.addTest(FileAdapterTest.suite()); - suite.addTest(NLSSearchTest.suite()); - return suite; - } } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchTestHelper.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchTestHelper.java index 1e8eb16ce4..7516d07934 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchTestHelper.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/SearchTestHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -23,6 +23,7 @@ import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.ui.search.ElementQuerySpecification; import org.eclipse.jdt.ui.search.PatternQuerySpecification; +import org.eclipse.jdt.ui.tests.core.rules.JUnitSourceSetup; import org.eclipse.jdt.internal.ui.search.JavaSearchQuery; import org.eclipse.jdt.internal.ui.search.JavaSearchResult; diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/TreeContentProviderTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/TreeContentProviderTest.java index 20adf400e4..5714bdd1ec 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/TreeContentProviderTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/TreeContentProviderTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,11 +14,16 @@ package org.eclipse.jdt.ui.tests.search; +import static org.junit.Assert.assertEquals; + import java.util.List; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.swt.events.TreeListener; import org.eclipse.swt.widgets.Control; @@ -37,27 +42,23 @@ import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.ui.tests.core.rules.JUnitSourceSetup; + import org.eclipse.jdt.internal.ui.search.JavaSearchResult; import org.eclipse.jdt.internal.ui.search.JavaSearchResultPage; import org.eclipse.jdt.internal.ui.search.LevelTreeContentProvider; /** */ -public class TreeContentProviderTest extends TestCase { +@RunWith(JUnit4.class) +public class TreeContentProviderTest { - private static final Class<TreeContentProviderTest> THIS= TreeContentProviderTest.class; + @Rule + public JUnitSourceSetup projectsetup = new JUnitSourceSetup(); private LevelTreeContentProvider fProvider; private JavaSearchResult fResult; - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } - - public static Test setUpTest(Test test) { - return new JUnitSourceSetup(test); - } - static class MockTreeViewer extends AbstractTreeViewer { @Override @@ -136,15 +137,8 @@ public class TreeContentProviderTest extends TestCase { } } - - public TreeContentProviderTest(String name) { - super(name); - // TODO Auto-generated constructor stub - } - - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fProvider= new LevelTreeContentProvider(new JavaSearchResultPage() { StructuredViewer fViewer= new MockTreeViewer(); @Override @@ -161,11 +155,11 @@ public class TreeContentProviderTest extends TestCase { fProvider.inputChanged(null, null, fResult); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { } + @Test public void testSimpleAdd() throws Exception { IMethod method= SearchTestHelper.getMethod("junit.framework.TestCase", "getName", new String[0]); addMatch(new Match(method, 0, 1)); @@ -191,6 +185,7 @@ public class TreeContentProviderTest extends TestCase { assertEquals(fProvider.getParent(project), null); } + @Test public void testRemove() throws Exception { IMethod method= SearchTestHelper.getMethod("junit.framework.TestCase", "getName", new String[0]); IType type= method.getDeclaringType(); @@ -211,6 +206,7 @@ public class TreeContentProviderTest extends TestCase { assertEquals(0, fProvider.getElements(fResult).length); } + @Test public void testRemoveParentFirst() throws Exception { IMethod method= SearchTestHelper.getMethod("junit.framework.TestCase", "getName", new String[0]); IType type= method.getDeclaringType(); @@ -234,6 +230,7 @@ public class TreeContentProviderTest extends TestCase { assertEquals(0, fProvider.getElements(fResult).length); } + @Test public void testRemoveParentLast() throws Exception { IMethod method= SearchTestHelper.getMethod("junit.framework.TestCase", "getName", new String[0]); IType type= method.getDeclaringType(); @@ -268,5 +265,4 @@ public class TreeContentProviderTest extends TestCase { fProvider.elementsChanged(new Object[] { match.getElement() }); } - } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/TreeContentProviderTestWrapper.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/TreeContentProviderTestWrapper.java index f2142f0329..b0eae0f847 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/TreeContentProviderTestWrapper.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/TreeContentProviderTestWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,9 +14,14 @@ package org.eclipse.jdt.ui.tests.search; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import org.eclipse.jdt.ui.tests.core.rules.JUnitSourceSetup; /** * This class is a wrapper for {@link org.eclipse.jdt.ui.tests.search.TreeContentProviderTest} @@ -25,54 +30,46 @@ import junit.framework.TestSuite; * * @since 3.1 */ -public class TreeContentProviderTestWrapper extends TestCase { - - private static final Class<TreeContentProviderTestWrapper> THIS= TreeContentProviderTestWrapper.class; +@RunWith(JUnit4.class) +public class TreeContentProviderTestWrapper { TreeContentProviderTest fTest; - private String fName; - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } - - public static Test setUpTest(Test test) { - return new JUnitSourceSetup(test); - } + @Rule + public JUnitSourceSetup projectsetup = new JUnitSourceSetup(); - public TreeContentProviderTestWrapper(String name) { - super(name); - fName= name; - } - - @Override - protected void setUp() throws Exception { - fTest= new TreeContentProviderTest(fName); + @Before + public void setUp() throws Exception { + fTest= new TreeContentProviderTest(); fTest.setUp(); } - /* * @see junit.framework.TestCase#tearDown() * @since 3.1 */ - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { fTest.tearDown(); fTest= null; } + + @Test public void testSimpleAdd() throws Exception { fTest.testSimpleAdd(); } + @Test public void testRemove() throws Exception { fTest.testRemove(); } + @Test public void testRemoveParentFirst() throws Exception { fTest.testRemoveParentFirst(); } + @Test public void testRemoveParentLast() throws Exception { fTest.testRemoveParentLast(); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/WorkspaceReferenceTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/WorkspaceReferenceTest.java index 9f1aab8dd7..1fc3f082e8 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/WorkspaceReferenceTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/WorkspaceReferenceTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,32 +13,29 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.search; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; -/** - */ -public class WorkspaceReferenceTest extends TestCase { +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; - private static final Class<WorkspaceReferenceTest> THIS= WorkspaceReferenceTest.class; - - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } +import org.eclipse.jdt.ui.tests.core.rules.JUnitSourceSetup; - public static Test setUpTest(Test test) { - return new JUnitSourceSetup(test); - } +/** + */ +@RunWith(JUnit4.class) +public class WorkspaceReferenceTest { - public WorkspaceReferenceTest(String name) { - super(name); - } + @Rule + public JUnitSourceSetup projectsetup = new JUnitSourceSetup(); + @Test public void testSimpleMethodRef() throws Exception { assertEquals(9, SearchTestHelper.countMethodRefs("junit.framework.Test", "countTestCases", new String[0])); } + @Test public void testFindOverridden() throws Exception { assertEquals(6, SearchTestHelper.countMethodRefs("junit.framework.TestCase", "countTestCases", new String[0])); } diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/WorkspaceScopeTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/WorkspaceScopeTest.java index ff465826d4..928efcc6b2 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/WorkspaceScopeTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/search/WorkspaceScopeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,7 +13,13 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.search; -import junit.framework.TestCase; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; @@ -33,19 +39,16 @@ import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory; -public class WorkspaceScopeTest extends TestCase { +@RunWith(JUnit4.class) +public class WorkspaceScopeTest { private IJavaProject fProject1; private IJavaProject fProject2; private IJavaProject fProject3; private IJavaProject fProject4; private ICompilationUnit fCompilationUnit; - public WorkspaceScopeTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { fProject1= createStandardProject("Test", "test"); //$NON-NLS-1$ //$NON-NLS-2$ IPackageFragment pkg= fProject1.findPackageFragment(new Path("/Test/src/test")); //$NON-NLS-1$ fCompilationUnit= pkg.createCompilationUnit("Test.java", getSource(), true, null); //$NON-NLS-1$ @@ -91,6 +94,7 @@ public class WorkspaceScopeTest extends TestCase { } + @Test public void testPrivateScope() throws JavaModelException { IType type= fCompilationUnit.findPrimaryType(); type.getMethod("privateMethod", new String[0]); //$NON-NLS-1$ @@ -112,6 +116,7 @@ public class WorkspaceScopeTest extends TestCase { return JavaSearchScopeFactory.getInstance().createWorkspaceScope(includeJRE); } + @Test public void testDefaultScope() throws JavaModelException { IType type= fCompilationUnit.findPrimaryType(); type.getMethod("defaultMethod", new String[0]); //$NON-NLS-1$ @@ -131,7 +136,7 @@ public class WorkspaceScopeTest extends TestCase { checkNoRoots(scope, fProject3); } - + @Test public void testPublicMethod() throws JavaModelException { IType type= fCompilationUnit.findPrimaryType(); type.getMethod("publicMethod", new String[0]); //$NON-NLS-1$ @@ -141,6 +146,7 @@ public class WorkspaceScopeTest extends TestCase { checkNoRoots(scope, fProject3); } + @Test public void testProtectedMethod() throws JavaModelException { IType type= fCompilationUnit.findPrimaryType(); type.getMethod("protectedMethod", new String[0]); //$NON-NLS-1$ @@ -182,6 +188,7 @@ public class WorkspaceScopeTest extends TestCase { } } + @Test public void testJREProtected() throws JavaModelException { IType object= fProject1.findType("java.lang.Object"); //$NON-NLS-1$ object.getMethod("clone", new String [0]); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/ui/internal/compatibility/InternalsNotRemovedTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/ui/internal/compatibility/InternalsNotRemovedTest.java index a374235a72..479fcf09eb 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/ui/internal/compatibility/InternalsNotRemovedTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/ui/internal/compatibility/InternalsNotRemovedTest.java @@ -18,7 +18,7 @@ import org.eclipse.text.tests.Accessor; /** * Ensures that internal code which is used by a product doesn't get removed. - * + * * @deprecated to hide deprecation warnings * @since 3.6 */ diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/ImporterTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/ImporterTest.java index 4c855fbead..fc745f82ce 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/ImporterTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/ImporterTest.java @@ -25,6 +25,9 @@ import java.util.zip.ZipException; import java.util.zip.ZipFile; import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.jdt.testplugin.JavaProjectHelper; @@ -43,16 +46,10 @@ import org.eclipse.ui.wizards.datatransfer.ProjectConfigurator; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class ImporterTest extends TestCase { - - public static Test suite() { - return new TestSuite(ImporterTest.class); - } +@RunWith(JUnit4.class) +public class ImporterTest{ + @Test public void testImportRawJavaProject() throws Exception { IProject project = null; try { diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewJavaProjectWizardTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewJavaProjectWizardTest.java index faa2099589..9e75b0e071 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewJavaProjectWizardTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewJavaProjectWizardTest.java @@ -13,9 +13,15 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.wizardapi; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.eclipse.core.runtime.IPath; @@ -36,12 +42,8 @@ import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.jdt.ui.PreferenceConstants; import org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPage; -public class NewJavaProjectWizardTest extends TestCase { - - - public static Test suite() { - return new TestSuite(NewJavaProjectWizardTest.class); - } +@RunWith(JUnit4.class) +public class NewJavaProjectWizardTest { private class TestNewJavaProjectWizardPage extends NewJavaProjectWizardPage { @@ -77,24 +79,16 @@ public class NewJavaProjectWizardTest extends TestCase { } - private static final String PROJECT_NAME = "DummyProject"; private static final String OTHER_PROJECT_NAME = "OtherProject"; - private TestNewJavaProjectWizardPage fWizardPage; - public NewJavaProjectWizardTest(String name) { - super(name); - } - /** * @see TestCase#setUp() */ - @Override - protected void setUp() throws Exception { - super.setUp(); - + @Before + public void setUp() throws Exception { IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IProject project= root.getProject(PROJECT_NAME); @@ -106,8 +100,8 @@ public class NewJavaProjectWizardTest extends TestCase { /** * @see TestCase#tearDown() */ - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IProject project= root.getProject(PROJECT_NAME); if (project.exists()) { @@ -119,7 +113,6 @@ public class NewJavaProjectWizardTest extends TestCase { project.delete(true, null); } - super.tearDown(); } private IPath getJREEntryPath() { @@ -142,6 +135,7 @@ public class NewJavaProjectWizardTest extends TestCase { assertEquals("h", classpath[1].getPath(), getJREEntryPath()); } + @Test public void testBasicSet() throws Exception { fWizardPage.initBuildPath(); IProject project= fWizardPage.getProjectHandle(); @@ -151,7 +145,7 @@ public class NewJavaProjectWizardTest extends TestCase { assertBasicBuildPath(project, outputLocation, classpath); } - + @Test public void testBasicCreate() throws Exception { IProject project= fWizardPage.getProjectHandle(); @@ -167,6 +161,7 @@ public class NewJavaProjectWizardTest extends TestCase { assertBasicBuildPath(jproj.getProject(), outputLocation, classpath); } + @Test public void testProjectChange() throws Exception { fWizardPage.initBuildPath(); IProject project= fWizardPage.getProjectHandle(); @@ -204,6 +199,7 @@ public class NewJavaProjectWizardTest extends TestCase { assertEquals("g", classpath[2].getPath(), getJREEntryPath()); } + @Test public void testUserSet() throws Exception { IProject project= fWizardPage.getProjectHandle(); @@ -231,6 +227,7 @@ public class NewJavaProjectWizardTest extends TestCase { assertBasicBuildPath(project, outputLocation1, classpath1); } + @Test public void testUserCreate() throws Exception { IProject project= fWizardPage.getProjectHandle(); @@ -256,6 +253,7 @@ public class NewJavaProjectWizardTest extends TestCase { assertUserBuildPath(jproj.getProject(), outputLocation, classpath); } + @Test public void testReadExisting() throws Exception { IProject project= fWizardPage.getProjectHandle(); @@ -285,6 +283,7 @@ public class NewJavaProjectWizardTest extends TestCase { assertUserBuildPath(project, outputLocation1, classpath1); } + @Test public void testExistingOverwrite() throws Exception { IProject project= fWizardPage.getProjectHandle(); @@ -310,7 +309,4 @@ public class NewJavaProjectWizardTest extends TestCase { IClasspathEntry[] classpath1= jproj.getRawClasspath(); assertUserBuildPath(project, outputLocation1, classpath1); } -} - - - +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest.java index a63b7b9ac6..479356aecf 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/wizardapi/NewTypeWizardTest.java @@ -16,10 +16,19 @@ package org.eclipse.jdt.ui.tests.wizardapi; +import static org.junit.Assert.assertEquals; + import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + import org.eclipse.jdt.testplugin.JavaProjectHelper; import org.eclipse.jdt.testplugin.StringAsserts; import org.eclipse.jdt.testplugin.TestOptions; @@ -42,7 +51,7 @@ import org.eclipse.jdt.internal.core.manipulation.CodeTemplateContextType; import org.eclipse.jdt.internal.core.manipulation.StubUtility; import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jdt.ui.tests.core.ProjectTestSetup; +import org.eclipse.jdt.ui.tests.core.rules.ProjectTestSetup; import org.eclipse.jdt.ui.wizards.NewAnnotationWizardPage; import org.eclipse.jdt.ui.wizards.NewClassWizardPage; import org.eclipse.jdt.ui.wizards.NewEnumWizardPage; @@ -52,33 +61,19 @@ import org.eclipse.jdt.ui.wizards.NewTypeWizardPage; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - /** * */ -public class NewTypeWizardTest extends TestCase { - private static final Class<NewTypeWizardTest> THIS= NewTypeWizardTest.class; - +@RunWith(JUnit4.class) +public class NewTypeWizardTest { private IJavaProject fJProject1; private IPackageFragmentRoot fSourceFolder; - public NewTypeWizardTest(String name) { - super(name); - } - - public static Test setUpTest(Test test) { - return new ProjectTestSetup(test); - } + @Rule + public ProjectTestSetup projectsetup = new ProjectTestSetup(); - public static Test suite() { - return setUpTest(new TestSuite(THIS)); - } - - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Hashtable<String, String> options= TestOptions.getDefaultOptions(); options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE); options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4"); @@ -108,11 +103,12 @@ public class NewTypeWizardTest extends TestCase { } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { JavaProjectHelper.clear(fJProject1, ProjectTestSetup.getDefaultClasspath()); } + @Test public void testCreateClass1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -152,6 +148,7 @@ public class NewTypeWizardTest extends TestCase { StringAsserts.assertEqualStringIgnoreDelim(actual, expected); } + @Test public void testCreateClass2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -193,7 +190,7 @@ public class NewTypeWizardTest extends TestCase { StringAsserts.assertEqualStringIgnoreDelim(actual, expected); } - + @Test public void testCreateClass3() throws Exception { IPackageFragment pack0= fSourceFolder.createPackageFragment("pack", false, null); @@ -252,6 +249,7 @@ public class NewTypeWizardTest extends TestCase { } + @Test public void testCreateClass4() throws Exception { IPackageFragment pack0= fSourceFolder.createPackageFragment("pack", false, null); @@ -317,7 +315,7 @@ public class NewTypeWizardTest extends TestCase { } - + @Test public void testCreateInnerClass1() throws Exception { IPackageFragment pack0= fSourceFolder.createPackageFragment("pack", false, null); @@ -371,8 +369,7 @@ public class NewTypeWizardTest extends TestCase { StringAsserts.assertEqualStringIgnoreDelim(actual, expected); } - - + @Test public void testCreateClassExtraImports1() throws Exception { String newFileTemplate= "${filecomment}\n${package_declaration}\n\nimport java.util.Map;\n\n${typecomment}\n${type_declaration}"; @@ -422,6 +419,7 @@ public class NewTypeWizardTest extends TestCase { } + @Test public void testCreateClassExtraImports2() throws Exception { IPackageFragment pack0= fSourceFolder.createPackageFragment("pack", false, null); @@ -487,6 +485,7 @@ public class NewTypeWizardTest extends TestCase { StringAsserts.assertEqualStringIgnoreDelim(actual, expected); } + @Test public void testCreateClassExtraImports3() throws Exception { IPackageFragment pack0= fSourceFolder.createPackageFragment("pack", false, null); @@ -558,7 +557,7 @@ public class NewTypeWizardTest extends TestCase { StringAsserts.assertEqualStringIgnoreDelim(actual, expected); } - + @Test public void testCreateInterface() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -598,6 +597,7 @@ public class NewTypeWizardTest extends TestCase { StringAsserts.assertEqualStringIgnoreDelim(actual, expected); } + @Test public void testCreateEnum() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -633,6 +633,7 @@ public class NewTypeWizardTest extends TestCase { StringAsserts.assertEqualStringIgnoreDelim(actual, expected); } + @Test public void testCreateAnnotation() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -668,6 +669,7 @@ public class NewTypeWizardTest extends TestCase { StringAsserts.assertEqualStringIgnoreDelim(actual, expected); } + public void typeBodyTest( NewTypeWizardPage wizardPage, String templateID, String templateBody, String expectedBody, String packageName, String typeName, String typeKeyword) throws Exception { StubUtility.setCodeTemplate(templateID, templateBody, null); @@ -719,6 +721,7 @@ public class NewTypeWizardTest extends TestCase { StringAsserts.assertEqualStringIgnoreDelim(actual, expected); } + @Test public void testCreateClassWithBody() throws Exception { typeBodyTest( new NewClassWizardPage(), @@ -730,6 +733,7 @@ public class NewTypeWizardTest extends TestCase { "class" ); } + @Test public void testCreateInterfaceWithBody() throws Exception { typeBodyTest( new NewInterfaceWizardPage(), @@ -741,6 +745,7 @@ public class NewTypeWizardTest extends TestCase { "interface" ); } + @Test public void testCreateEnumWithBody() throws Exception { typeBodyTest( new NewEnumWizardPage(), @@ -752,6 +757,7 @@ public class NewTypeWizardTest extends TestCase { "enum" ); } + @Test public void testCreateAnnotationWithBody() throws Exception { typeBodyTest( new NewAnnotationWizardPage(), @@ -763,6 +769,7 @@ public class NewTypeWizardTest extends TestCase { "@interface" ); } + @Test public void testAttemptCreateExistingClass() throws Exception { // Foo1.java and Foo2.java in test1 diff --git a/org.eclipse.jdt.ui/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jdt.ui/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.jdt.ui/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jdt.ui/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java index 67bb1bf1eb..dbb6daa12e 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/fix/CleanUpConstantsOptions.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018, 2019 IBM Corporation and others. + * Copyright (c) 2018, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -68,6 +68,7 @@ public class CleanUpConstantsOptions extends CleanUpConstants { options.setOption(CONVERT_FUNCTIONAL_INTERFACES, CleanUpOptions.FALSE); options.setOption(USE_LAMBDA, CleanUpOptions.TRUE); options.setOption(USE_ANONYMOUS_CLASS_CREATION, CleanUpOptions.FALSE); + options.setOption(SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF, CleanUpOptions.FALSE); //Unused Code options.setOption(REMOVE_UNUSED_CODE_IMPORTS, CleanUpOptions.TRUE); @@ -164,6 +165,7 @@ public class CleanUpConstantsOptions extends CleanUpConstants { options.setOption(CONVERT_FUNCTIONAL_INTERFACES, CleanUpOptions.FALSE); options.setOption(USE_LAMBDA, CleanUpOptions.TRUE); options.setOption(USE_ANONYMOUS_CLASS_CREATION, CleanUpOptions.FALSE); + options.setOption(SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF, CleanUpOptions.FALSE); //Unused Code options.setOption(REMOVE_UNUSED_CODE_IMPORTS, CleanUpOptions.FALSE); diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/ActualTypeResolver.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/ActualTypeResolver.java index 79474ab807..dfc5e8292a 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/ActualTypeResolver.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/ActualTypeResolver.java @@ -15,8 +15,6 @@ package org.eclipse.jdt.internal.corext.template.java; import java.util.List; -import org.eclipse.jdt.internal.corext.template.java.JavaContext; -import org.eclipse.jdt.internal.corext.template.java.JavaVariable; import org.eclipse.jdt.internal.corext.template.java.TypeResolver; import org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable; import org.eclipse.jface.text.templates.TemplateContext; diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/InnerExpressionResolver.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/InnerExpressionResolver.java index e9d8384469..6c77a2f224 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/InnerExpressionResolver.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/InnerExpressionResolver.java @@ -15,7 +15,6 @@ package org.eclipse.jdt.internal.corext.template.java; import java.util.List; -import org.eclipse.jdt.internal.corext.template.java.JavaVariable; import org.eclipse.jface.text.templates.SimpleTemplateVariableResolver; import org.eclipse.jface.text.templates.TemplateContext; import org.eclipse.jface.text.templates.TemplateVariable; diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaPostfixContextType.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaPostfixContextType.java index de341540ca..a604054a29 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaPostfixContextType.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/JavaPostfixContextType.java @@ -13,15 +13,13 @@ *******************************************************************************/ package org.eclipse.jdt.internal.corext.template.java; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.Position; + import org.eclipse.jdt.core.CompletionContext; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.internal.corext.template.java.AbstractJavaContextType; -import org.eclipse.jdt.internal.corext.template.java.CompilationUnitContext; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; - public class JavaPostfixContextType extends AbstractJavaContextType { public static final String ID_ALL= "postfix"; //$NON-NLS-1$ diff --git a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/NewFieldResolver.java b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/NewFieldResolver.java index a8ad22f8dc..1d81aff43f 100644 --- a/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/NewFieldResolver.java +++ b/org.eclipse.jdt.ui/core extension/org/eclipse/jdt/internal/corext/template/java/NewFieldResolver.java @@ -15,7 +15,6 @@ package org.eclipse.jdt.internal.corext.template.java; import java.util.List; -import org.eclipse.jdt.internal.corext.template.java.JavaVariable; import org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ChangeTypeRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ChangeTypeRefactoring.java index 25271b133c..31ea3dabd9 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ChangeTypeRefactoring.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/ChangeTypeRefactoring.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -57,6 +57,7 @@ import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.NodeFinder; import org.eclipse.jdt.core.dom.ParameterizedType; import org.eclipse.jdt.core.dom.QualifiedName; @@ -100,6 +101,7 @@ import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ConstraintCol import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ConstraintOperator; import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ConstraintVariable; import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ConstraintVariableFactory; +import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.DeclaringTypeVariable; import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ExpressionVariable; import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.FullConstraintCreator; import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ITypeConstraint; @@ -1224,12 +1226,13 @@ public class ChangeTypeRefactoring extends Refactoring { } private boolean isValidSimpleConstraint(ITypeBinding type, - Collection<ConstraintVariable> relevantVars, - SimpleTypeConstraint stc){ + Collection<ConstraintVariable> relevantVars, + SimpleTypeConstraint stc) { if (relevantVars.contains(stc.getLeft())) { // upper bound - if (!isSubTypeOf(type, findType(stc.getRight()))) { - return false; + if (isSubTypeOf(type, findType(stc.getRight()))) { + return true; } + return checkSuperTypeScope(type); } return true; } @@ -1252,6 +1255,43 @@ public class ChangeTypeRefactoring extends Refactoring { return false; } + private boolean checkSuperTypeScope(ITypeBinding superType) { + if ("java.lang.Object".equals(superType.getQualifiedName())) { //$NON-NLS-1$ + return false; // we'll never propose Object + } + + for (ITypeConstraint tc : fRelevantConstraints) { + if (tc.isSimpleTypeConstraint()) { + SimpleTypeConstraint stc= (SimpleTypeConstraint) tc; + + ITypeBinding typeBinding= stc.getRight().getBinding(); + boolean isMethodFromObject= "java.lang.Object".equals(typeBinding.getQualifiedName()); //$NON-NLS-1$ + if (isMethodFromObject) { + if (superType.isInterface() || Modifier.isAbstract(superType.getModifiers())) { + return false; + } + continue; + } + + if (stc.getRight() instanceof DeclaringTypeVariable) { + IBinding memberBinding= ((DeclaringTypeVariable) stc.getRight()).getMemberBinding(); + if (memberBinding instanceof IMethodBinding) { + IMethodBinding methodBinding= Bindings.findMethodInHierarchy(superType, memberBinding.getName(), (ITypeBinding[]) null); + if (methodBinding == null) { + if (!(superType.isInterface() && isMethodFromObject)) { + return false; + } + } + } + } else { + if (!isSubTypeOf(superType, typeBinding)) { + return false; + } + } + } + } + return true; + } private ITypeBinding findType(ConstraintVariable cv) { return cv.getBinding(); diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryWithResourcesAnalyzer.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryWithResourcesAnalyzer.java new file mode 100644 index 0000000000..eaf9914767 --- /dev/null +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryWithResourcesAnalyzer.java @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial version based on SurroundWithTryCatchAnalyzer + *******************************************************************************/ +package org.eclipse.jdt.internal.corext.refactoring.surround; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.IBinding; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.IVariableBinding; +import org.eclipse.jdt.core.dom.LambdaExpression; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.MethodReference; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.Type; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.eclipse.jdt.core.dom.VariableDeclarationStatement; + +import org.eclipse.jdt.internal.corext.dom.Bindings; +import org.eclipse.jdt.internal.corext.dom.Selection; +import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; +import org.eclipse.jdt.internal.corext.refactoring.util.SurroundWithAnalyzer; + +public class SurroundWithTryWithResourcesAnalyzer extends SurroundWithAnalyzer { + + private ITypeBinding[] fExceptions; + private ASTNode fEnclosingNode; + private CompilationUnit fCompilationUnit; + + public SurroundWithTryWithResourcesAnalyzer(ICompilationUnit unit, Selection selection) throws CoreException { + super(unit, selection, true); + } + + public ITypeBinding[] getExceptions(Selection selection) { + if (fEnclosingNode != null && !getStatus().hasFatalError()) { + fExceptions= ExceptionAnalyzer.perform(fEnclosingNode, selection, true); + if (fExceptions == null || fExceptions.length == 0) { + if (fEnclosingNode instanceof MethodReference) { + invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain); + } else { + List<ASTNode> autoClosableNodes= getCoveredAutoClosableNodes(); + if (autoClosableNodes.isEmpty()) { + fExceptions= new ITypeBinding[] { fCompilationUnit.getAST().resolveWellKnownType("java.lang.Exception") }; //$NON-NLS-1$ + } else { + fExceptions= new ITypeBinding[0]; + } + } + } + } + return fExceptions; + } + + public ITypeBinding[] getThrownExceptions() { + List<ITypeBinding> exceptions= new ArrayList<>(); + if (fEnclosingNode.getNodeType() == ASTNode.METHOD_DECLARATION) { + List<Type> thrownExceptions= ((MethodDeclaration) fEnclosingNode).thrownExceptionTypes(); + for (Iterator<Type> thrown= thrownExceptions.iterator(); thrown.hasNext();) { + ITypeBinding thrownException= thrown.next().resolveBinding(); + if (thrownException != null) { + exceptions.add(thrownException); + } + } + } else { + ITypeBinding typeBinding= null; + if (fEnclosingNode.getLocationInParent() == LambdaExpression.BODY_PROPERTY) { + typeBinding= ((LambdaExpression) fEnclosingNode.getParent()).resolveTypeBinding(); + } else if (fEnclosingNode instanceof MethodReference) { + typeBinding= ((MethodReference) fEnclosingNode).resolveTypeBinding(); + } + if (typeBinding != null) { + IMethodBinding methodBinding= typeBinding.getFunctionalInterfaceMethod(); + if (methodBinding != null) { + for (ITypeBinding thrownException : methodBinding.getExceptionTypes()) { + exceptions.add(thrownException); + } + } + } + } + return exceptions.toArray(new ITypeBinding[0]); + } + + public ASTNode getEnclosingNode() { + return fEnclosingNode; + } + + @Override + public void endVisit(CompilationUnit node) { + fEnclosingNode= null; + fCompilationUnit= node; + if (!getStatus().hasFatalError() && hasSelectedNodes()) + fEnclosingNode= SurroundWithAnalyzer.getEnclosingNode(getFirstSelectedNode()); + + super.endVisit(node); + } + + /** + * Return the first auto closable nodes. When a node that isn't Autoclosable is found the method + * returns. + * + * @return List of the first AutoClosable nodes found + */ + public List<ASTNode> getCoveredAutoClosableNodes() { + ASTNode[] astNodes= getSelectedNodes(); + List<ASTNode> autoClosableNodes= new ArrayList<>(); + for (ASTNode astNode : astNodes) { + if (isAutoClosable(astNode)) { + autoClosableNodes.add(astNode); + } else { + return autoClosableNodes; + } + } + return autoClosableNodes; + } + + private boolean isAutoClosable(ASTNode astNode) { + Map<SimpleName, IVariableBinding> simpleNames= getVariableStatementBinding(astNode); + for (Entry<SimpleName, IVariableBinding> entry : simpleNames.entrySet()) { + ITypeBinding typeBinding= null; + switch (entry.getKey().getParent().getNodeType()) { + case ASTNode.VARIABLE_DECLARATION_FRAGMENT: + case ASTNode.VARIABLE_DECLARATION_STATEMENT: + case ASTNode.ASSIGNMENT: + typeBinding= entry.getValue().getType(); + break; + default: + continue; + } + if (typeBinding == null) { + continue; + } + for (ITypeBinding superType : Bindings.getAllSuperTypes(typeBinding)) { + if (superType.getQualifiedName().equals("java.lang.AutoCloseable")) { //$NON-NLS-1$ + return true; + } + } + } + return false; + } + + public Map<SimpleName, IVariableBinding> getVariableStatementBinding(ASTNode astNode) { + Map<SimpleName, IVariableBinding> variableBindings= new HashMap<>(); + astNode.accept(new ASTVisitor() { + @Override + public boolean visit(VariableDeclarationStatement node) { + for (Object o : node.fragments()) { + if (o instanceof VariableDeclarationFragment) { + VariableDeclarationFragment vdf= (VariableDeclarationFragment) o; + SimpleName name= vdf.getName(); + IBinding binding= name.resolveBinding(); + if (binding instanceof IVariableBinding) { + variableBindings.put(name, (IVariableBinding) binding); + break; + } + } + } + return false; + } + }); + return variableBindings; + } + +} diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryWithResourcesRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryWithResourcesRefactoring.java new file mode 100644 index 0000000000..103000330c --- /dev/null +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryWithResourcesRefactoring.java @@ -0,0 +1,676 @@ +/******************************************************************************* + * Copyright (c) 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial code based on SurroundWithTryCatchRefactoring + *******************************************************************************/ +package org.eclipse.jdt.internal.corext.refactoring.surround; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; + +import org.eclipse.text.edits.MultiTextEdit; +import org.eclipse.text.edits.TextEdit; +import org.eclipse.text.edits.TextEditGroup; + +import org.eclipse.jface.text.ITextSelection; + +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.TextFileChange; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.Assignment; +import org.eclipse.jdt.core.dom.Block; +import org.eclipse.jdt.core.dom.CatchClause; +import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.eclipse.jdt.core.dom.IExtendedModifier; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.IVariableBinding; +import org.eclipse.jdt.core.dom.LambdaExpression; +import org.eclipse.jdt.core.dom.MethodReference; +import org.eclipse.jdt.core.dom.Modifier; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SingleVariableDeclaration; +import org.eclipse.jdt.core.dom.Statement; +import org.eclipse.jdt.core.dom.TryStatement; +import org.eclipse.jdt.core.dom.Type; +import org.eclipse.jdt.core.dom.UnionType; +import org.eclipse.jdt.core.dom.VariableDeclaration; +import org.eclipse.jdt.core.dom.VariableDeclarationExpression; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.eclipse.jdt.core.dom.VariableDeclarationStatement; +import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; +import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; +import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; +import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.TypeLocation; +import org.eclipse.jdt.core.dom.rewrite.ListRewrite; +import org.eclipse.jdt.core.refactoring.CompilationUnitChange; + +import org.eclipse.jdt.internal.core.manipulation.StubUtility; +import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving; +import org.eclipse.jdt.internal.core.manipulation.util.Strings; +import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; +import org.eclipse.jdt.internal.corext.dom.ASTNodes; +import org.eclipse.jdt.internal.corext.dom.CodeScopeBuilder; +import org.eclipse.jdt.internal.corext.dom.IASTSharedValues; +import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder; +import org.eclipse.jdt.internal.corext.dom.Selection; +import org.eclipse.jdt.internal.corext.fix.LinkedProposalModel; +import org.eclipse.jdt.internal.corext.refactoring.Checks; +import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; +import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser; +import org.eclipse.jdt.internal.corext.refactoring.util.ResourceUtil; + +import org.eclipse.jdt.internal.ui.text.correction.QuickAssistProcessor; + +/** + * Surround a set of statements with a try-with-resources block. + * + * Special case: + * + * URL url= file.toURL(); + * + * In this case the variable declaration statement gets convert into a + * declaration without initializer. So the body of the try/catch block + * only consists of new assignments. In this case we can't move the + * selected nodes (e.g. the declaration) into the try block. + */ +public class SurroundWithTryWithResourcesRefactoring extends Refactoring { + + public final String GROUP_EXC_TYPE= "exc_type"; //$NON-NLS-1$ + public final String GROUP_EXC_NAME= "exc_name"; //$NON-NLS-1$ + public final String GROUP_TRY_STATEMENT= "try_stmt"; //$NON-NLS-1$ + + private Selection fSelection; + private SurroundWithTryWithResourcesAnalyzer fAnalyzer; + private boolean fLeaveDirty; + + private ICompilationUnit fCUnit; + private CompilationUnit fRootNode; + private ASTRewrite fRewriter; + private ImportRewrite fImportRewrite; + private CodeScopeBuilder.Scope fScope; + private ASTNode[] fSelectedNodes; + private List<ASTNode> fAutoClosableNodes; + + private LinkedProposalModel fLinkedProposalModel; + + private SurroundWithTryWithResourcesRefactoring(ICompilationUnit cu, Selection selection) { + fCUnit= cu; + fSelection= selection; + fLeaveDirty= false; + } + + public static SurroundWithTryWithResourcesRefactoring create(ICompilationUnit cu, int offset, int length) { + return new SurroundWithTryWithResourcesRefactoring(cu, Selection.createFromStartLength(offset, length)); + } + + public static SurroundWithTryWithResourcesRefactoring create(ICompilationUnit cu, ITextSelection selection) { + return new SurroundWithTryWithResourcesRefactoring(cu, Selection.createFromStartLength(selection.getOffset(), selection.getLength())); + } + + public LinkedProposalModel getLinkedProposalModel() { + return fLinkedProposalModel; + } + + public void setLeaveDirty(boolean leaveDirty) { + fLeaveDirty= leaveDirty; + } + + public boolean stopExecution() { + if (fAnalyzer == null) + return true; + ITypeBinding[] exceptions= fAnalyzer.getExceptions(fAnalyzer.getSelection()); + List<ASTNode> autoClosableNodes= fAnalyzer.getCoveredAutoClosableNodes(); + return (exceptions == null || exceptions.length == 0) && (autoClosableNodes == null || autoClosableNodes.isEmpty()); + } + + /* non Java-doc + * @see IRefactoring#getName() + */ + @Override + public String getName() { + return RefactoringCoreMessages.SurroundWithTryWithResourcesRefactoring_name; + } + + public RefactoringStatus checkActivationBasics(CompilationUnit rootNode) throws CoreException { + RefactoringStatus result= new RefactoringStatus(); + fRootNode= rootNode; + + fAnalyzer= new SurroundWithTryWithResourcesAnalyzer(fCUnit, fSelection); + fRootNode.accept(fAnalyzer); + result.merge(fAnalyzer.getStatus()); + fAutoClosableNodes= fAnalyzer.getCoveredAutoClosableNodes(); + if (fAutoClosableNodes == null || fAutoClosableNodes.isEmpty()) { + result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.SurroundWithTryWithResourcesRefactoring_notAutoclosable)); + } + return result; + } + + + /* + * @see Refactoring#checkActivation(IProgressMonitor) + */ + @Override + public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { + CompilationUnit rootNode= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(fCUnit, true, pm); + return checkActivationBasics(rootNode); + } + + /* + * @see Refactoring#checkInput(IProgressMonitor) + */ + @Override + public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException { + return Checks.validateModifiesFiles( + ResourceUtil.getFiles(new ICompilationUnit[]{fCUnit}), + getValidationContext()); + } + + /* non Java-doc + * @see IRefactoring#createChange(IProgressMonitor) + */ + @Override + public Change createChange(IProgressMonitor pm) throws CoreException { + final String NN= ""; //$NON-NLS-1$ + if (pm == null) pm= new NullProgressMonitor(); + pm.beginTask(NN, 2); + try { + final CompilationUnitChange result= new CompilationUnitChange(getName(), fCUnit); + if (fLeaveDirty) + result.setSaveMode(TextFileChange.LEAVE_DIRTY); + MultiTextEdit root= new MultiTextEdit(); + result.setEdit(root); + fRewriter= ASTRewrite.create(fAnalyzer.getEnclosingBodyDeclaration().getAST()); + fImportRewrite= StubUtility.createImportRewrite(fRootNode, true); + + fLinkedProposalModel= new LinkedProposalModel(); + + fScope= CodeScopeBuilder.perform(fAnalyzer.getEnclosingBodyDeclaration(), fSelection). + findScope(fSelection.getOffset(), fSelection.getLength()); + fScope.setCursor(fSelection.getOffset()); + + fSelectedNodes= fAnalyzer.getSelectedNodes(); + + createTryWithResourcesStatement(fCUnit.getBuffer(), fCUnit.findRecommendedLineSeparator()); + + if (fImportRewrite.hasRecordedChanges()) { + TextEdit edit= fImportRewrite.rewriteImports(null); + root.addChild(edit); + result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] {edit} )); + } + TextEdit change= fRewriter.rewriteAST(); + root.addChild(change); + result.addTextEditGroup(new TextEditGroup(NN, new TextEdit[] {change} )); + return result; + } finally { + pm.done(); + } + } + + private AST getAST() { + return fRootNode.getAST(); + } + + private void createTryWithResourcesStatement(org.eclipse.jdt.core.IBuffer buffer, String lineDelimiter) throws CoreException { + List<Statement> result= new ArrayList<>(1); + TryStatement tryStatement= getAST().newTryStatement(); + ITypeBinding[] exceptions= fAnalyzer.getExceptions(fAnalyzer.getSelection()); + ImportRewriteContext context= new ContextSensitiveImportRewriteContext(fAnalyzer.getEnclosingBodyDeclaration(), fImportRewrite); + + CatchClause catchClause= getAST().newCatchClause(); + SingleVariableDeclaration decl= getAST().newSingleVariableDeclaration(); + String varName= StubUtility.getExceptionVariableName(fCUnit.getJavaProject()); + String name= fScope.createName(varName, false); + decl.setName(getAST().newSimpleName(name)); + + + List<ASTNode> variableDeclarations= getSpecialVariableDeclarationStatements(); + ListRewrite statements= fRewriter.getListRewrite(tryStatement.getBody(), Block.STATEMENTS_PROPERTY); + boolean selectedNodeRemoved= false; + ASTNode expressionStatement= null; + for (ASTNode node : fSelectedNodes) { + if (fAutoClosableNodes.contains(node)) { + continue; + } + if (node instanceof VariableDeclarationStatement && variableDeclarations.contains(node)) { + AST ast= getAST(); + VariableDeclarationStatement statement= (VariableDeclarationStatement)node; + // Create a copy and remove the initializer + VariableDeclarationStatement copy= (VariableDeclarationStatement)ASTNode.copySubtree(ast, statement); + List<IExtendedModifier> modifiers= copy.modifiers(); + for (Iterator<IExtendedModifier> iter= modifiers.iterator(); iter.hasNext();) { + IExtendedModifier modifier= iter.next(); + if (modifier.isModifier() && Modifier.isFinal(((Modifier)modifier).getKeyword().toFlagValue())) { + iter.remove(); + } + } + List<VariableDeclarationFragment> fragments= copy.fragments(); + for (Iterator<VariableDeclarationFragment> iter= fragments.iterator(); iter.hasNext();) { + VariableDeclarationFragment fragment= iter.next(); + fragment.setInitializer(null); + } + + // "var" type cannot have null initializer, so change to inferred type + if (ASTNodes.isVarType(statement, fRootNode)) { + ITypeBinding binding= statement.getType().resolveBinding(); + if (binding != null) { + Type varType= fImportRewrite.addImport(binding, getAST(), context, TypeLocation.LOCAL_VARIABLE); + copy.setType(varType); + } + } + + CompilationUnit root= (CompilationUnit)statement.getRoot(); + int extendedStart= root.getExtendedStartPosition(statement); + // we have a leading comment and the comment is covered by the selection + if (extendedStart != statement.getStartPosition() && extendedStart >= fSelection.getOffset()) { + String commentToken= buffer.getText(extendedStart, statement.getStartPosition() - extendedStart); + commentToken= Strings.trimTrailingTabsAndSpaces(commentToken); + Type type= statement.getType(); + String typeName= buffer.getText(type.getStartPosition(), type.getLength()); + copy.setType((Type)fRewriter.createStringPlaceholder(commentToken + typeName, type.getNodeType())); + } + result.add(copy); + // convert the fragments into expression statements + fragments= statement.fragments(); + if (!fragments.isEmpty()) { + List<ExpressionStatement> newExpressionStatements= new ArrayList<>(); + for (Iterator<VariableDeclarationFragment> iter= fragments.iterator(); iter.hasNext();) { + VariableDeclarationFragment fragment= iter.next(); + Expression initializer= fragment.getInitializer(); + if (initializer != null) { + Assignment assignment= ast.newAssignment(); + assignment.setLeftHandSide((Expression)fRewriter.createCopyTarget(fragment.getName())); + assignment.setRightHandSide((Expression)fRewriter.createCopyTarget(initializer)); + newExpressionStatements.add(ast.newExpressionStatement(assignment)); + } + } + if (!newExpressionStatements.isEmpty()) { + if (fSelectedNodes.length == 1) { + expressionStatement= fRewriter.createGroupNode(newExpressionStatements.toArray(new ASTNode[newExpressionStatements.size()])); + } else { + fRewriter.replace( + statement, + fRewriter.createGroupNode(newExpressionStatements.toArray(new ASTNode[newExpressionStatements.size()])), + null); + } + } else { + fRewriter.remove(statement, null); + selectedNodeRemoved= true; + } + } else { + fRewriter.remove(statement, null); + selectedNodeRemoved= true; + } + } + } + result.add(tryStatement); + ASTNode replacementNode; + if (result.size() == 1) { + replacementNode= result.get(0); + } else { + replacementNode= fRewriter.createGroupNode(result.toArray(new ASTNode[result.size()])); + } + + ASTNode node= fSelectedNodes[0]; + ASTNode parentStatement= ASTResolving.findAncestor(node, ASTNode.VARIABLE_DECLARATION_STATEMENT); + List<ASTNode> coveredStatements= new ArrayList<>(); + if (fSelectedNodes == null || fSelectedNodes.length == 0 && parentStatement != null + && (parentStatement instanceof VariableDeclarationStatement) + && (parentStatement instanceof ExpressionStatement)) { + coveredStatements.add(parentStatement); + } else { + for (ASTNode coveredNode : fSelectedNodes) { + Statement statement= ASTResolving.findParentStatement(coveredNode); + if (statement == null) { + continue; + } + if (!coveredStatements.contains(statement)) { + coveredStatements.add(statement); + } + } + } + + Selection nodesInRangeSelection= fAnalyzer.getSelection(); + List<ASTNode> nodesInRange= new ArrayList<>(); + if (!fAutoClosableNodes.isEmpty()) { + ASTNode parentBodyDeclaration= ASTResolving.findParentBodyDeclaration(node); + int start= fAutoClosableNodes.get(0).getStartPosition(); + ASTNode lastSelectedNode= fSelectedNodes[fSelectedNodes.length - 1]; + int end= lastSelectedNode.getStartPosition() + lastSelectedNode.getLength(); + + for (ASTNode astNode : fAutoClosableNodes) { + int endPosition= findEndPosition(astNode); + end= Math.max(end, endPosition); + } + + // recursive loop to find all nodes affected by wrapping in try block + nodesInRange= findNodesInRange(parentBodyDeclaration, start, end); + int oldEnd= end; + int newEnd= end; + while (true) { + newEnd= oldEnd; + for (ASTNode astNode : nodesInRange) { + int endPosition= findEndPosition(astNode); + newEnd= Math.max(newEnd, endPosition); + } + if (newEnd > oldEnd) { + oldEnd= newEnd; + nodesInRange= findNodesInRange(parentBodyDeclaration, start, newEnd); + continue; + } + break; + } + if (nodesInRange.size() > 0) { + // must recalculate exceptions as additional lines are now in try statement + ASTNode lastNode= nodesInRange.get(nodesInRange.size() - 1); + nodesInRangeSelection= Selection.createFromStartEnd(start, lastNode.getStartPosition() + lastNode.getLength()); + exceptions= fAnalyzer.getExceptions(nodesInRangeSelection); + } + nodesInRange.removeAll(fAutoClosableNodes); + nodesInRange.removeAll(Arrays.asList(fSelectedNodes)); + } + + // add required resource statements + CompilationUnit cu= (CompilationUnit)fSelectedNodes[0].getRoot(); + AST ast= fSelectedNodes[0].getAST(); + Set<String> resourceNameList= new HashSet<>(); + List<ITypeBinding> allExceptions= new ArrayList<>(Arrays.asList(exceptions)); + for (ASTNode coveredNode : fAutoClosableNodes) { + ASTNode findAncestor= ASTResolving.findAncestor(coveredNode, ASTNode.VARIABLE_DECLARATION_STATEMENT); + if (findAncestor == null) { + findAncestor= ASTResolving.findAncestor(coveredNode, ASTNode.ASSIGNMENT); + } + if (findAncestor instanceof VariableDeclarationStatement) { + VariableDeclarationStatement vds= (VariableDeclarationStatement) findAncestor; + String commentToken= null; + int extendedStatementStart= cu.getExtendedStartPosition(vds); + if(vds.getStartPosition() > extendedStatementStart) { + commentToken= buffer.getText(extendedStatementStart, vds.getStartPosition() - extendedStatementStart); + } + Type type= vds.getType(); + ITypeBinding typeBinding= type.resolveBinding(); + if (typeBinding != null) { + IMethodBinding close= findAutocloseMethod(typeBinding); + if (close != null) { + ITypeBinding[] thrownExceptions= fAnalyzer.getThrownExceptions(); + for (ITypeBinding exceptionType : close.getExceptionTypes()) { + if (!allExceptions.contains(exceptionType)) { + boolean isThrown= false; + for (ITypeBinding thrownException : thrownExceptions) { + if (exceptionType.isAssignmentCompatible(thrownException)) { + isThrown= true; + break; + } + } + if (!isThrown) { + allExceptions.add(exceptionType); + } + } + } + } + } + String typeName= buffer.getText(type.getStartPosition(), type.getLength()); + + for (Object object : vds.fragments()) { + VariableDeclarationFragment variableDeclarationFragment= (VariableDeclarationFragment) object; + VariableDeclarationFragment newVariableDeclarationFragment= ast.newVariableDeclarationFragment(); + SimpleName vdsName= variableDeclarationFragment.getName(); + + if(commentToken == null) { + int extendedStart= cu.getExtendedStartPosition(variableDeclarationFragment); + commentToken= buffer.getText(extendedStart, variableDeclarationFragment.getStartPosition() - extendedStart); + } + commentToken= Strings.trimTrailingTabsAndSpaces(commentToken); + commentToken += commentToken.isEmpty() ? "" : " "; //$NON-NLS-1$ //$NON-NLS-2$ + + newVariableDeclarationFragment.setName(ast.newSimpleName(vdsName.getIdentifier())); + Expression newExpression= null; + Expression initializer= variableDeclarationFragment.getInitializer(); + if (initializer == null) { + fRewriter.remove(coveredNode, null); + continue; + } else { + newExpression= (Expression) fRewriter.createMoveTarget(initializer); + } + resourceNameList.add(vdsName.getIdentifier()); + newVariableDeclarationFragment.setInitializer(newExpression); + VariableDeclarationExpression newVariableDeclarationExpression= ast.newVariableDeclarationExpression(newVariableDeclarationFragment); + newVariableDeclarationExpression.setType( + (Type) fRewriter.createStringPlaceholder(commentToken + typeName, type.getNodeType())); + tryStatement.resources().add(newVariableDeclarationExpression); + commentToken= null; + } +// String commentToken2= ""; //$NON-NLS-1$ +// int extendedStart= cu.getExtendedStartPosition(vds); +// int extendedLength= cu.getExtendedLength(vds); +// int endCommentLength= extendedLength - (vds.getStartPosition() - extendedStart) - vds.getLength(); +// if (endCommentLength > 0) { +// commentToken2= buffer.getText(vds.getStartPosition() + vds.getLength(), +// endCommentLength); +// commentToken2= Strings.trimLeadingTabsAndSpaces(commentToken2); +// } + } + } + + List<ITypeBinding> filteredExceptions= filterSubtypeExceptions(allExceptions); + if (allExceptions.size() > 0) { + UnionType unionType= getAST().newUnionType(); + List<Type> types= unionType.types(); + int i=0; + for (ITypeBinding exception : filteredExceptions) { + Type type= fImportRewrite.addImport(exception, getAST(), context, TypeLocation.EXCEPTION); + types.add(type); + fLinkedProposalModel.getPositionGroup(GROUP_EXC_TYPE + i, true).addPosition(fRewriter.track(type), i == 0); + i++; + } + + decl.setType(unionType); + catchClause.setException(decl); + fLinkedProposalModel.getPositionGroup(GROUP_EXC_NAME + 0, true).addPosition(fRewriter.track(decl.getName()), false); + Statement st= getCatchBody("Exception", name, lineDelimiter); //$NON-NLS-1$ + if (st != null) { + catchClause.getBody().statements().add(st); + } + tryStatement.catchClauses().add(catchClause); + } + + + if (fSelectedNodes.length == 1 && fAutoClosableNodes.isEmpty()) { + ASTNode selectedNode= fSelectedNodes[0]; + + if (selectedNode instanceof MethodReference) { + MethodReference methodReference= (MethodReference) selectedNode; + IMethodBinding functionalMethod= QuickAssistProcessor.getFunctionalMethodForMethodReference(methodReference); + // functionalMethod is non-null and non-generic. See ExceptionAnalyzer.handleMethodReference(MethodReference node). + Assert.isTrue(functionalMethod != null && !functionalMethod.isGenericMethod()); + LambdaExpression lambda= QuickAssistProcessor.convertMethodRefernceToLambda(methodReference, functionalMethod, fRootNode, fRewriter, null, true); + ASTNode statementInBlock= (ASTNode) ((Block) lambda.getBody()).statements().get(0); + fRewriter.replace(statementInBlock, replacementNode, null); + statements.insertLast(statementInBlock, null); + return; + } + + LambdaExpression enclosingLambda= ASTResolving.findEnclosingLambdaExpression(selectedNode); + if (enclosingLambda != null && selectedNode.getLocationInParent() == LambdaExpression.BODY_PROPERTY && enclosingLambda.resolveMethodBinding() != null) { + QuickAssistProcessor.changeLambdaBodyToBlock(enclosingLambda, getAST(), fRewriter); + Block blockBody= (Block) fRewriter.get(enclosingLambda, LambdaExpression.BODY_PROPERTY); + ASTNode statementInBlock= (ASTNode) blockBody.statements().get(0); + fRewriter.replace(statementInBlock, replacementNode, null); + statements.insertLast(statementInBlock, null); + return; + } + + if (expressionStatement != null) { + statements.insertLast(expressionStatement, null); + } else { + if (!selectedNodeRemoved) + statements.insertLast(fRewriter.createMoveTarget(selectedNode), null); + } + fRewriter.replace(selectedNode, replacementNode, null); + } else { + ListRewrite source= fRewriter.getListRewrite( + fSelectedNodes[0].getParent(), + (ChildListPropertyDescriptor)fSelectedNodes[0].getLocationInParent()); + List<ASTNode> nodes= new ArrayList<>(Arrays.asList(fSelectedNodes)); + if (!nodesInRange.isEmpty()) { + nodes.addAll(nodesInRange); + } + int index= fAutoClosableNodes.size(); + if (index < nodes.size()) { + ASTNode toMove= source.createMoveTarget(nodes.get(index), nodes.get(nodes.size() - 1), + index == 0 ? replacementNode : null, null); + statements.insertLast(toMove, null); + } + if (index > 0) { + source.replace(fAutoClosableNodes.get(0), replacementNode, null); + for (int i= 1; i < index; ++i) { + source.remove(fAutoClosableNodes.get(i), null); + } + } + } + + } + + private IMethodBinding findAutocloseMethod(ITypeBinding type) { + while (type != null) { + IMethodBinding[] methods= type.getDeclaredMethods(); + for (IMethodBinding method : methods) { + if (method.getName().equals("close") && method.getParameterTypes().length == 0) { //$NON-NLS-1$ + return method; + } + } + type= type.getSuperclass(); + } + return null; + } + + private int findEndPosition(ASTNode node) { + int end= node.getStartPosition() + node.getLength(); + Map<SimpleName, IVariableBinding> nodeSimpleNameBindings= fAnalyzer.getVariableStatementBinding(node); + List<SimpleName> nodeNames= new ArrayList<>(nodeSimpleNameBindings.keySet()); + if (nodeNames.isEmpty()) { + return -1; + } + SimpleName nodeSimpleName= nodeNames.get(0); + SimpleName[] coveredNodeBindings= LinkedNodeFinder.findByNode(node.getRoot(), nodeSimpleName); + if (coveredNodeBindings.length == 0) { + return -1; + } + for (ASTNode astNode : coveredNodeBindings) { + end= Math.max(end, (astNode.getStartPosition() + astNode.getLength())); + } + return end; + } + + // find all nodes (statements) that are within the start/end positions + private List<ASTNode> findNodesInRange(ASTNode astNode, final int start, final int end) { + List<ASTNode> nodesInRange= new ArrayList<>(); + astNode.accept(new ASTVisitor() { + int pre= start; + + @Override + public void preVisit(ASTNode preNode) { + pre= preNode.getStartPosition(); + super.preVisit(preNode); + } + + @Override + public void postVisit(ASTNode postNode) { + int post= postNode.getStartPosition() + postNode.getLength(); + if (pre >= start && post <= end) { + Statement statement= ASTResolving.findParentStatement(postNode); + loop: while (statement != null) { + if (statement.getParent() instanceof Statement) { + Statement pStatement= (Statement) statement.getParent(); + switch (pStatement.getNodeType()) { + case ASTNode.BLOCK: + if (pStatement.getParent().getNodeType() != ASTNode.METHOD_DECLARATION) { + statement= pStatement; + continue; + } else { + break loop; + } + case ASTNode.METHOD_DECLARATION: + break loop; + default: + break; + } + statement= pStatement; + } else { + break; + } + } + if (statement != null && !nodesInRange.contains(statement)) { + nodesInRange.add(statement); + } + } + super.postVisit(postNode); + } + }); + return nodesInRange; + } + + private List<ITypeBinding> filterSubtypeExceptions(List<ITypeBinding> exceptions) { + List<ITypeBinding> filteredExceptions= new ArrayList<>(); + filteredExceptions.addAll(exceptions); + + for (Iterator<ITypeBinding> subtypeIterator= filteredExceptions.iterator(); subtypeIterator.hasNext();) { + ITypeBinding iTypeBinding= subtypeIterator.next(); + for (Iterator<ITypeBinding> supertypeIterator= filteredExceptions.iterator(); supertypeIterator.hasNext();) { + ITypeBinding superTypeBinding= supertypeIterator.next(); + if (!iTypeBinding.equals(superTypeBinding) && iTypeBinding.isSubTypeCompatible(superTypeBinding)) { + subtypeIterator.remove(); + break; + } + } + } + return filteredExceptions; + } + + private List<ASTNode> getSpecialVariableDeclarationStatements() { + List<ASTNode> result= new ArrayList<>(3); + for (VariableDeclaration local : fAnalyzer.getAffectedLocals()) { + ASTNode parent= local.getParent(); + if (parent instanceof VariableDeclarationStatement && !result.contains(parent)) + result.add(parent); + } + return result; + + } + + private Statement getCatchBody(String type, String name, String lineSeparator) throws CoreException { + String s= StubUtility.getCatchBodyContent(fCUnit, type, name, fSelectedNodes[0], lineSeparator); + if (s == null) { + return null; + } else { + return (Statement)fRewriter.createStringPlaceholder(s, ASTNode.RETURN_STATEMENT); + } + } +} diff --git a/org.eclipse.jdt.ui/dictionaries/en_GB.dictionary b/org.eclipse.jdt.ui/dictionaries/en_GB.dictionary index 312cd4b8e1..2981e1fad2 100644 --- a/org.eclipse.jdt.ui/dictionaries/en_GB.dictionary +++ b/org.eclipse.jdt.ui/dictionaries/en_GB.dictionary @@ -29712,6 +29712,7 @@ paleness paler pales palest +palette palfrey paling pall diff --git a/org.eclipse.jdt.ui/dictionaries/en_US.dictionary b/org.eclipse.jdt.ui/dictionaries/en_US.dictionary index 3010a7cd7c..178ef0cfc8 100644 --- a/org.eclipse.jdt.ui/dictionaries/en_US.dictionary +++ b/org.eclipse.jdt.ui/dictionaries/en_US.dictionary @@ -29711,6 +29711,7 @@ paleness paler pales palest +palette palfrey paling pall diff --git a/org.eclipse.jdt.ui/plugin.properties b/org.eclipse.jdt.ui/plugin.properties index f96f7af11d..e3492b1764 100644 --- a/org.eclipse.jdt.ui/plugin.properties +++ b/org.eclipse.jdt.ui/plugin.properties @@ -124,7 +124,7 @@ preferenceKeywords.todo=Java case sensitive task tag todo xxx fix fixme compiler preferenceKeywords.javaeditor=Java java editor quick assist appearance navigation colors light bulb smart caret positioning highlight matching bracket foreground background show selected only save action participant clean up preferenceKeywords.javaeditorproperty= Java java editor save action participant clean up -preferenceKeywords.contentassist=Java editor content code assist complete completion insert overwrite single proposal common prefix automatically import fill argument name guess alphabetical hide discouraged reference forbidden auto activation trigger Javadoc camel camelcase category categories separate specific timeout type types word hippie template static members favorites postfix chain asynchronous +preferenceKeywords.contentassist=Java editor content code assist complete completion insert overwrite single proposal common prefix automatically import fill argument name guess alphabetical hide discouraged reference forbidden auto activation trigger Javadoc camel camelcase category categories separate specific timeout type types word hippie template static members favorites postfix chain asynchronous subword preferenceKeywords.hover=pop-up Java editor hover popup sticky annotation roll over key modifier combined variable problem externalized externalize string source preferenceKeywords.syntaxcoloring=Java editor colors semantic coloring highlighting Javadoc html links tags multi line single line comment task tag method invocation static field annotation autoboxing unboxing boxing constant deprecated field keywords local variable operators brackets strings type variable inherited method declaration preferenceKeywords.templates=Java editor templates snippet macros @@ -752,6 +752,9 @@ ActionDefinition.surroundWith.tryCatch.description= Surround the selected text w ActionDefinition.surroundWith.tryMultiCatch.name= Surround with try/multi-catch Block ActionDefinition.surroundWith.tryMultiCatch.description= Surround the selected text with a try/multi-catch block +ActionDefinition.surroundWith.tryWithResources.name= Surround with try-with-resources Block +ActionDefinition.surroundWith.tryWithResources.description= Surround the selected text with a try-with-resources block + ActionDefinition.surroundWith.quickMenu.name= Surround With Quick Menu ActionDefinition.surroundWith.quickMenu.description= Shows the Surround With quick menu diff --git a/org.eclipse.jdt.ui/plugin.xml b/org.eclipse.jdt.ui/plugin.xml index 276bdb3c1a..f02c04fee3 100644 --- a/org.eclipse.jdt.ui/plugin.xml +++ b/org.eclipse.jdt.ui/plugin.xml @@ -3749,6 +3749,12 @@ id="org.eclipse.jdt.ui.edit.text.java.surround.with.try.multicatch"> </command> <command + name="%ActionDefinition.surroundWith.tryWithResources.name" + description="%ActionDefinition.surroundWith.tryWithResources.description" + categoryId="org.eclipse.jdt.ui.category.source" + id="org.eclipse.jdt.ui.edit.text.java.surround.with.try.with.resources"> + </command> + <command name="%ActionDefinition.cleanUp.name" description="%ActionDefinition.cleanUp.description" categoryId="org.eclipse.jdt.ui.category.source" @@ -7072,9 +7078,14 @@ runAfter="org.eclipse.jdt.ui.cleanup.lambda"> </cleanUp> <cleanUp + class="org.eclipse.jdt.internal.ui.fix.LambdaExpressionAndMethodRefCleanUp" + id="org.eclipse.jdt.ui.cleanup.lambda_and_method_ref" + runAfter="org.eclipse.jdt.ui.cleanup.expressions"> + </cleanUp> + <cleanUp class="org.eclipse.jdt.internal.ui.fix.NumberSuffixCleanUp" id="org.eclipse.jdt.ui.cleanup.number_suffix" - runAfter="org.eclipse.jdt.ui.cleanup.expressions"> + runAfter="org.eclipse.jdt.ui.cleanup.lambda_and_method_ref"> </cleanUp> <cleanUp class="org.eclipse.jdt.internal.ui.fix.UnusedCodeCleanUp" diff --git a/org.eclipse.jdt.ui/templates/default-postfixtemplates.xml b/org.eclipse.jdt.ui/templates/default-postfixtemplates.xml index 671d560eb4..fe563d7d20 100644 --- a/org.eclipse.jdt.ui/templates/default-postfixtemplates.xml +++ b/org.eclipse.jdt.ui/templates/default-postfixtemplates.xml @@ -2,7 +2,7 @@ <!-- /******************************************************************************* - * Copyright (c) 2019 Nicolaj Hoess. + * Copyright (c) 2019, 2020 Nicolaj Hoess. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -18,70 +18,70 @@ <templates> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.beg" context="postfix" deleted="false" description="Sets the cursor to the begin of the expression" enabled="true" name="beg">${}${inner_expression}${cursor}</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.beg" context="postfix" deleted="false" description="%PostfixTemplates.beg" enabled="true" name="beg">${}${inner_expression}${cursor}</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.cast" context="postfix" deleted="false" description="Casts the expression to a new type" enabled="true" name="cast">((${})${inner_expression})${cursor}</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.cast" context="postfix" deleted="false" description="%PostfixTemplates.cast" enabled="true" name="cast">((${})${inner_expression})${cursor}</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.dowhile" context="postfix" deleted="false" description="Creates a do-while loop" enabled="true" name="dowhile">do { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.dowhile" context="postfix" deleted="false" description="%PostfixTemplates.dowhile" enabled="true" name="dowhile">do { ${cursor} } while (${i:inner_expression(boolean)});</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.else" context="postfix" deleted="false" description="Creates a negated if statement" enabled="true" name="else">if (!${i:inner_expression(boolean)}${}) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.else" context="postfix" deleted="false" description="%PostfixTemplates.else" enabled="true" name="else">if (!${i:inner_expression(boolean)}${}) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.for" context="postfix" deleted="false" description="Creates a for statement" enabled="true" name="for">for (${type:newActualType(i)} ${n:newName(i)} : ${i:inner_expression(java.util.Collection,array)}) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.for" context="postfix" deleted="false" description="%PostfixTemplates.for" enabled="true" name="for">for (${type:newActualType(i)} ${n:newName(i)} : ${i:inner_expression(java.util.Collection,array)}) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.fori" context="postfix" deleted="false" description="Creates a for statement which iterates over an array" enabled="true" name="fori">for (int ${index} = 0; i < ${i:inner_expression(array)}.length; ${index}++) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.fori" context="postfix" deleted="false" description="%PostfixTemplates.fori" enabled="true" name="fori">for (int ${index} = 0; i < ${i:inner_expression(array)}.length; ${index}++) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.foriub" context="postfix" deleted="false" description="Creates an indexed for statement which uses the given integer as upper bound" enabled="true" name="fori">for (int ${index} = 0; i < ${i:inner_expression(int)}; ${index}++) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.foriub" context="postfix" deleted="false" description="%PostfixTemplates.foriub" enabled="true" name="foriub">for (int ${index} = 0; i < ${i:inner_expression(int)}; ${index}++) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.forrlb" context="postfix" deleted="false" description="Creates an indexed for statement which uses the given integer - 1 as starting value (counting backwards)" enabled="true" name="forr">for (int ${index} = ${i:inner_expression(int)} - 1; i >= 0 ; ${index}--) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.forrlb" context="postfix" deleted="false" description="%PostfixTemplates.forrlb" enabled="true" name="forrlb">for (int ${index} = ${i:inner_expression(int)} - 1; i >= 0 ; ${index}--) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.forr" context="postfix" deleted="false" description="Creates a for statement which iterates over an array in reverse order" enabled="true" name="forr">for (int ${index} = ${i:inner_expression(array)}.length - 1; i >= 0; ${index}--) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.forr" context="postfix" deleted="false" description="%PostfixTemplates.forr" enabled="true" name="forr">for (int ${index} = ${i:inner_expression(array)}.length - 1; i >= 0; ${index}--) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.nnull" context="postfix" deleted="false" description="Creates an if statement and checks it the expression does not resolve to null" enabled="true" name="nnull">if (${i:inner_expression(java.lang.Object,array)} != null) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.nnull" context="postfix" deleted="false" description="%PostfixTemplates.nnull" enabled="true" name="nnull">if (${i:inner_expression(java.lang.Object,array)} != null) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.null" context="postfix" deleted="false" description="Creates an if statement which checks the expression if it resolves to null" enabled="true" name="null">if (${i:inner_expression(java.lang.Object,array)} == null) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.null" context="postfix" deleted="false" description="%PostfixTemplates.null" enabled="true" name="null">if (${i:inner_expression(java.lang.Object,array)} == null) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.sif" context="postfix" deleted="false" description="Creates a short if statement" enabled="true" name="sif">((${i:inner_expression(boolean)}) ? ${} : ${cursor})</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.sif" context="postfix" deleted="false" description="%PostfixTemplates.sif" enabled="true" name="sif">((${i:inner_expression(boolean)}) ? ${} : ${cursor})</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.snnull" context="postfix" deleted="false" description="Creates an if statement which checks if the expression resolves not to null" enabled="true" name="snnull">(${i:inner_expression(java.lang.Object,array)} != null) ? ${inner_expression}${} : ${cursor}</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.snnull" context="postfix" deleted="false" description="%PostfixTemplates.snnull" enabled="true" name="snnull">(${i:inner_expression(java.lang.Object,array)} != null) ? ${inner_expression}${} : ${cursor}</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.snull" context="postfix" deleted="false" description="Creates a short if statement which checks for null" enabled="true" name="snull">(${i:inner_expression(java.lang.Object,array)} == null) ? ${} : ${inner_expression}${cursor}</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.snull" context="postfix" deleted="false" description="%PostfixTemplates.snull" enabled="true" name="snull">(${i:inner_expression(java.lang.Object,array)} == null) ? ${} : ${inner_expression}${cursor}</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.sysout" context="postfix" deleted="false" description="Sends the affected string to a System.out.println(..) call" enabled="true" name="sysout">System.out.println(${i:inner_expression(java.lang.String)}${});${cursor}</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.sysout" context="postfix" deleted="false" description="%PostfixTemplates.sysout" enabled="true" name="sysout">System.out.println(${i:inner_expression(java.lang.String)}${});${cursor}</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.throw" context="postfix" deleted="false" description="Throws the given Exception" enabled="true" name="throw">throw ${true:inner_expression(java.lang.Throwable)};</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.throw" context="postfix" deleted="false" description="%PostfixTemplates.throw" enabled="true" name="throw">throw ${true:inner_expression(java.lang.Throwable)};</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.var" context="postfix" deleted="false" description="Creates a new variable" enabled="true" name="var">${field:newType(inner_expression)} ${var:newName(inner_expression)} = ${inner_expression};${cursor}</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.var" context="postfix" deleted="false" description="%PostfixTemplates.var" enabled="true" name="var">${field:newType(inner_expression)} ${var:newName(inner_expression)} = ${inner_expression};${cursor}</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.while" context="postfix" deleted="false" description="Creates a while loop" enabled="true" name="while">while (${i:inner_expression(boolean)}) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.while" context="postfix" deleted="false" description="%PostfixTemplates.while" enabled="true" name="while">while (${i:inner_expression(boolean)}) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.withinregion" context="postfix" deleted="false" description="Creates an if statement which checks if a given numeric variable is within a region" enabled="true" name="withinregion">if (${i:inner_expression(float,int,double,long)} >= ${lower_bound} && ${inner_expression} <= ${upper_bound}) { + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.withinregion" context="postfix" deleted="false" description="%PostfixTemplates.withinregion" enabled="true" name="withinregion">if (${i:inner_expression(float,int,double,long)} >= ${lower_bound} && ${inner_expression} <= ${upper_bound}) { ${cursor} }</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.field" context="postfix" deleted="false" description="Creates a new field" enabled="true" name="field">${field:newField(i)} = ${i:inner_expression};${cursor}</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.field" context="postfix" deleted="false" description="%PostfixTemplates.field" enabled="true" name="field">${field:newField(i)} = ${i:inner_expression};${cursor}</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.constpriv" context="postfix" deleted="false" description="Creates a new private constant" enabled="true" name="constpriv">${n:newField(i, false, true, true, true)}${i:inner_expression(novalue)}${cursor}</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.constpriv" context="postfix" deleted="false" description="%PostfixTemplates.constpriv" enabled="true" name="constpriv">${n:newField(i, false, true, true, true)}${i:inner_expression(novalue)}${cursor}</template> - <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.constpub" context="postfix" deleted="false" description="Creates a new public constant" enabled="true" name="constpub">${n:newField(i, true, true, true, true)}${i:inner_expression(novalue)}${cursor}</template> + <template autoinsert="true" id="org.eclipse.jdt.postfixcompletion.constpub" context="postfix" deleted="false" description="%PostfixTemplates.constpub" enabled="true" name="constpub">${n:newField(i, true, true, true, true)}${i:inner_expression(novalue)}${cursor}</template> -</templates>
\ No newline at end of file +</templates> diff --git a/org.eclipse.jdt.ui/templates/default-templates.properties b/org.eclipse.jdt.ui/templates/default-templates.properties index 1b55a1822c..cb78e3c483 100644 --- a/org.eclipse.jdt.ui/templates/default-templates.properties +++ b/org.eclipse.jdt.ui/templates/default-templates.properties @@ -130,6 +130,28 @@ CodeTemplateContextType.validate.unknownvariable=Variable ''{0}'' is unknown. CodeTemplateContextType.validate.missingvariable=Variable ''{0}'' is required. CodeTemplateContextType.validate.invalidcomment=Pattern is not a valid Java comment. +PostfixTemplates.beg=Sets the cursor to the begin of the expression +PostfixTemplates.cast=Casts the expression to a new type +PostfixTemplates.dowhile=Creates a do-while loop +PostfixTemplates.else=Creates a negated if statement +PostfixTemplates.for=Creates a for statement +PostfixTemplates.fori=Creates a for statement which iterates over an array +PostfixTemplates.foriub=Creates an indexed for statement which uses the given integer as upper bound +PostfixTemplates.forrlb=Creates an indexed for statement which uses the given integer - 1 as starting value (counting backwards) +PostfixTemplates.forr=Creates a for statement which iterates over an array in reverse order +PostfixTemplates.nnull=Creates an if statement and checks if the expression does not resolve to null +PostfixTemplates.null=Creates an if statement which checks if expression resolves to null +PostfixTemplates.sif=Creates a short if statement +PostfixTemplates.snnull=Creates an if statement which checks if the expression does not resolve to null +PostfixTemplates.snull=Creates a short if statement which checks for null +PostfixTemplates.sysout=Sends the affected string to a System.out.println(..) call +PostfixTemplates.throw=Throws the given Exception +PostfixTemplates.var=Creates a new variable +PostfixTemplates.while=Creates a while loop +PostfixTemplates.withinregion=Creates an if statement which checks if a given numeric variable is within a region +PostfixTemplates.field=Creates a new field +PostfixTemplates.constpriv=Creates a new private constant +PostfixTemplates.constpub=Creates a new public constant # strings in default templates CodeTemplates.constructorcomment=Comment for created constructors diff --git a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringMessages.java b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringMessages.java index f280048eee..696cce3988 100644 --- a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringMessages.java +++ b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/RefactoringMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -979,6 +979,14 @@ public final class RefactoringMessages extends NLS { public static String SurroundWithTryMultiCatchAction_not17; + public static String SurroundWithTryResourcesAction_label; + + public static String SurroundWithTryResourcesAction_exception; + + public static String SurroundWithTryResourcesAction_not18; + + public static String SurroundWithTryResourcesAction_dialog_title; + public static String UseSupertypeAction_to_activate; public static String UseSupertypeAction_use_Supertype; diff --git a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/refactoringui.properties b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/refactoringui.properties index 4094497c67..cf6f074c02 100644 --- a/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/refactoringui.properties +++ b/org.eclipse.jdt.ui/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/refactoringui.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2019 IBM Corporation and others. +# Copyright (c) 2000, 2020 IBM Corporation and others. # # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 @@ -38,6 +38,10 @@ SurroundWithTryCatchAction_dialog_title=Surround with try/catch SurroundWithTryMultiCatchAction_dialog_title=Surround with try/multi-catch SurroundWithTryMultiCatchAction_not17=Project ''{0}'' cannot be processed since its compiler source level is below 1.7. SurroundWithTryCatchAction_exception=An unexpected exception occurred. See the error log for more details. +SurroundWithTryResourcesAction_label=Surround with try-with-resources Block +SurroundWithTryResourcesAction_dialog_title=Surround with try-with-resources +SurroundWithTryResourcesAction_not18=Project ''{0}'' cannot be processed since its compiler source level is below 1.8. +SurroundWithTryResourcesAction_exception=An unexpected exception occurred. See the error log for more details. RefactoringGroup_modify_Parameters_label=&Change Method Signature... RefactoringGroup_pull_Up_label=Pull &Up... @@ -463,15 +467,15 @@ UseSupertypeWizard_10=No updates are possible for the supertypes DeleteWizard_1=Delete DeleteWizard_2=An unexpected exception occurred. See the error log for more details. -DeleteWizard_3=Are you sure you want to delete linked {0}?\nOnly the workspace link will be deleted. Link target will remain unchanged. -DeleteWizard_4=Are you sure you want to delete {0}? -DeleteWizard_5=Are you sure you want to delete linked {0}?\nOnly the workspace link will be deleted. Link target will remain unchanged. -DeleteWizard_6=Are you sure you want to delete linked {0}?\nOnly the workspace link will be deleted. Link target will remain unchanged.\n\nNote that all subelements of the selected linked packages and package fragment roots will be removed from the workspace. -DeleteWizard_7=Are you sure you want to delete linked {0}?\nOnly the workspace link will be deleted. Link target will remain unchanged. -DeleteWizard_8=Are you sure you want to delete {0}? -DeleteWizard_9=Are you sure you want to delete these {0} elements? -DeleteWizard_10=Are you sure you want to delete these {0} elements?\n\nSelection contains linked resources.\nOnly the workspace links will be deleted. Link targets will remain unchanged. -DeleteWizard_11=Are you sure you want to delete these {0} elements?\n\nSelection contains linked packages.\nOnly the workspace links will be deleted. Link targets will remain unchanged.\n\nNote that all subelements of linked packages and package fragment roots will be removed from the workspace. +DeleteWizard_3=Delete linked {0}?\nOnly the workspace link will be deleted. Link target will remain unchanged. +DeleteWizard_4=Delete {0}? +DeleteWizard_5=Delete linked {0}?\nOnly the workspace link will be deleted. Link target will remain unchanged. +DeleteWizard_6=Delete linked {0}?\nOnly the workspace link will be deleted. Link target will remain unchanged.\n\nNote that all subelements of the selected linked packages and package fragment roots will be removed from the workspace. +DeleteWizard_7=Delete linked {0}?\nOnly the workspace link will be deleted. Link target will remain unchanged. +DeleteWizard_8=Delete {0}? +DeleteWizard_9=Delete these {0} elements? +DeleteWizard_10=Delete these {0} elements?\n\nSelection contains linked resources.\nOnly the workspace links will be deleted. Link targets will remain unchanged. +DeleteWizard_11=Delete these {0} elements?\n\nSelection contains linked packages.\nOnly the workspace links will be deleted. Link targets will remain unchanged.\n\nNote that all subelements of linked packages and package fragment roots will be removed from the workspace. DeleteWizard_12_singular=The selected element does not exist anymore and cannot be deleted. DeleteWizard_12_plural=The {0} selected elements do not exist anymore and cannot be deleted. DeleteWizard_also_delete_sub_packages=Delete &subpackages of selected packages diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/IJavaHelpContextIds.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/IJavaHelpContextIds.java index 79e6ffdbee..c63322249a 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/IJavaHelpContextIds.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/IJavaHelpContextIds.java @@ -201,6 +201,7 @@ public interface IJavaHelpContextIds { public static final String SELF_ENCAPSULATE_ACTION= PREFIX + "self_encapsulate_action"; //$NON-NLS-1$ public static final String SHOW_IN_NAVIGATOR_VIEW_ACTION= PREFIX + "show_in_navigator_action"; //$NON-NLS-1$ public static final String SURROUND_WITH_TRY_CATCH_ACTION= PREFIX + "surround_with_try_catch_action"; //$NON-NLS-1$ + public static final String SURROUND_WITH_TRY_WITH_RESOURCES_ACTION= PREFIX + "surround_with_try_with_resources_action"; //$NON-NLS-1$ public static final String OPEN_RESOURCE_ACTION= PREFIX + "open_resource_action"; //$NON-NLS-1$ public static final String SELECT_WORKING_SET_ACTION= PREFIX + "select_working_set_action"; //$NON-NLS-1$ public static final String STRUCTURED_SELECTION_HISTORY_ACTION= PREFIX + "structured_selection_history_action"; //$NON-NLS-1$ diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java index d569efbf2f..cdceeece58 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,9 +14,12 @@ package org.eclipse.jdt.internal.ui; import java.io.IOException; +import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.Set; +import java.util.StringTokenizer; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -39,6 +42,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.resources.IFile; @@ -203,6 +207,8 @@ public class JavaPlugin extends AbstractUIPlugin implements DebugOptionsListener private WorkingCopyManager fWorkingCopyManager; + private static final String CODE_ASSIST_MIGRATED= "code_assist_migrated"; //$NON-NLS-1$ + /** * @deprecated to avoid deprecation warning */ @@ -431,6 +437,7 @@ public class JavaPlugin extends AbstractUIPlugin implements DebugOptionsListener JavaManipulation.setCodeTemplateStore(getCodeTemplateStore()); JavaManipulation.setCodeTemplateContextRegistry(getCodeTemplateContextRegistry()); + disableNewCodeAssistCategoryPreferences(); } private void createOrUpdateWorkingSet(String name, String oldname, String label, final String id) { @@ -1026,4 +1033,80 @@ public class JavaPlugin extends AbstractUIPlugin implements DebugOptionsListener DEBUG_TYPE_CONSTRAINTS= options.getBooleanOption("org.eclipse.jdt.ui/debug/TypeConstraints", false); //$NON-NLS-1$ DEBUG_RESULT_COLLECTOR= options.getBooleanOption("org.eclipse.jdt.ui/debug/ResultCollector", false); //$NON-NLS-1$ } + + /** + * Add only 'initializeCodeAssistCategoryDisabled(String)' calls here for + * proposal category id of *NEW* features meant to be disabled by deafult. + * + * Eg. initializeCodeAssistCategoryDisabled("org.eclipse.jdt.ui.javaPostfixProposalCategory"); //$NON-NLS-1$ + * + * The call must be added here in addition to setting default disablement in + * {@link PreferenceConstants} CODEASSIST_EXCLUDED_CATEGORIES and CODEASSIST_CATEGORY_ORDER. + * This will only work correctly for newly added proposal categories for a given release. + */ + private static void disableNewCodeAssistCategoryPreferences() { + // Eg. initializeCodeAssistCategoryDisabled("org.eclipse.jdt.ui.javaPostfixProposalCategory"); //$NON-NLS-1$ + } + + /** + * Disable (by default) the given category id for both the default content + * assist list (CODEASSIST_EXCLUDED_CATEGORIES) and the cycling content + * assist list (CODEASSIST_CATEGORY_ORDER) + * + * @param id The category id for the proposal feature to disable by default + */ + @SuppressWarnings("unused") + private static void initializeCodeAssistCategoryDisabled(String id) { + // If preference migrated, nothing to do + if (isCodeAssistMigrated(id)) { + return; + } + + String currPrefExcludedValue= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES); + Set<String> disabled= new HashSet<>(); + StringTokenizer tok= new StringTokenizer(currPrefExcludedValue, "\0"); //$NON-NLS-1$ + while (tok.hasMoreTokens()) { + disabled.add(tok.nextToken()); + } + + // preference not migrated, and not in user preferences + if (!disabled.isEmpty() && !disabled.contains(id)) { + String newPrefExcludedValue= currPrefExcludedValue + id + "\0"; //$NON-NLS-1$ + PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES, newPrefExcludedValue); + + // retrieve the id=rank to add from CODEASSIST_CATEGORY_ORDER from the default preferences + String defPrefOrderValue= PreferenceConstants.getPreferenceStore().getDefaultString(PreferenceConstants.CODEASSIST_CATEGORY_ORDER); + tok= new StringTokenizer(defPrefOrderValue, "\0"); //$NON-NLS-1$ + while (tok.hasMoreTokens()) { + StringTokenizer inner= new StringTokenizer(tok.nextToken(), ":"); //$NON-NLS-1$ + String key= inner.nextToken(); + int rank= Integer.parseInt(inner.nextToken()); + if (id.equals(key)) { + String currPrefOrderValue= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.CODEASSIST_CATEGORY_ORDER); + String newPreferenceOrderValue= currPrefOrderValue + id + ":" + rank + "\0"; //$NON-NLS-1$ //$NON-NLS-2$ + PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.CODEASSIST_CATEGORY_ORDER, newPreferenceOrderValue); + } + } + } + + // set as migrated + setCodeAssistMigrated(id); + } + + private static boolean isCodeAssistMigrated(String id) { + String key= CODE_ASSIST_MIGRATED + "_" + id; //$NON-NLS-1$ + boolean res= Platform.getPreferencesService().getBoolean(JavaPlugin.getPluginId(), key, false, null); + return res; + } + + private static void setCodeAssistMigrated(String id) { + String key= CODE_ASSIST_MIGRATED + "_" + id; //$NON-NLS-1$ + IEclipsePreferences preferences= InstanceScope.INSTANCE.getNode(JavaPlugin.getPluginId()); + preferences.putBoolean(key, true); + try { + preferences.flush(); + } catch (BackingStoreException e) { + JavaPlugin.log(e); + } + } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java index aa0ccf8073..eb582dad37 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java @@ -391,6 +391,7 @@ public final class ActionMessages extends NLS { public static String SurroundWithTemplateMenuAction_NoneApplicable; public static String SurroundWithTemplateMenuAction_SurroundWithTemplateSubMenuName; public static String SurroundWithTemplateMenuAction_SurroundWithTryCatchActionName; + public static String SurroundWithTemplateMenuAction_SurroundWithTryWithResourcesActionName; public static String SurroundWithTemplateMenuAction_SurroundWithTryMultiCatchActionName; public static String ToggleLinkingAction_label; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties index ffdec0453b..e88cca391d 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties @@ -468,6 +468,7 @@ CopyQualifiedNameAction_NoElementToQualify=No Element to qualify found in select SurroundWithTemplateMenuAction_SurroundWithTemplateSubMenuName=Surround &With SurroundWithTemplateMenuAction_SurroundWithTryCatchActionName=Tr&y/catch Block +SurroundWithTemplateMenuAction_SurroundWithTryWithResourcesActionName=Try-&with-resources Block SurroundWithTemplateMenuAction_SurroundWithTryMultiCatchActionName=T&ry/multi-catch Block SurroundWithTemplateMenuAction_ConfigureTemplatesActionName=&Configure Templates... SurroundWithTemplateMenuAction_NoneApplicable=(no template applicable) diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java index 5aba9a760b..c2a8d1d21a 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithActionGroup.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -29,6 +29,7 @@ import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds; import org.eclipse.jdt.ui.actions.JdtActionConstants; import org.eclipse.jdt.ui.actions.SurroundWithTryCatchAction; import org.eclipse.jdt.ui.actions.SurroundWithTryMultiCatchAction; +import org.eclipse.jdt.ui.actions.SurroundWithTryWithResourcesAction; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; @@ -38,6 +39,7 @@ public class SurroundWithActionGroup extends ActionGroup { private CompilationUnitEditor fEditor; private SurroundWithTryCatchAction fSurroundWithTryCatchAction; private SurroundWithTryMultiCatchAction fSurroundWithTryMultiCatchAction; + private SurroundWithTryWithResourcesAction fSurroundWithTryWithResourcesAction; private final String fGroup; public SurroundWithActionGroup(CompilationUnitEditor editor, String group) { @@ -45,12 +47,14 @@ public class SurroundWithActionGroup extends ActionGroup { fGroup= group; fSurroundWithTryCatchAction= createSurroundWithTryCatchAction(fEditor); fSurroundWithTryMultiCatchAction= createSurroundWithTryMultiCatchAction(fEditor); + fSurroundWithTryWithResourcesAction= createSurroundWithTryWithResourcesAction(fEditor); } @Override public void fillActionBars(IActionBars actionBar) { actionBar.setGlobalActionHandler(JdtActionConstants.SURROUND_WITH_TRY_CATCH, fSurroundWithTryCatchAction); actionBar.setGlobalActionHandler(JdtActionConstants.SURROUND_WITH_TRY_MULTI_CATCH, fSurroundWithTryMultiCatchAction); + actionBar.setGlobalActionHandler(JdtActionConstants.SURROUND_WITH_TRY_WITH_RESOURCES, fSurroundWithTryWithResourcesAction); } /** @@ -81,7 +85,8 @@ public class SurroundWithActionGroup extends ActionGroup { @Override public void menuAboutToShow(IMenuManager manager) { manager.removeAll(); - SurroundWithTemplateMenuAction.fillMenu(manager, fEditor, fSurroundWithTryCatchAction, fSurroundWithTryMultiCatchAction); + SurroundWithTemplateMenuAction.fillMenu(manager, fEditor, fSurroundWithTryCatchAction, + fSurroundWithTryMultiCatchAction, fSurroundWithTryWithResourcesAction); } }); } @@ -95,6 +100,15 @@ public class SurroundWithActionGroup extends ActionGroup { return result; } + static SurroundWithTryWithResourcesAction createSurroundWithTryWithResourcesAction(CompilationUnitEditor editor) { + SurroundWithTryWithResourcesAction result= new SurroundWithTryWithResourcesAction(editor); + result.setText(ActionMessages.SurroundWithTemplateMenuAction_SurroundWithTryWithResourcesActionName); + result.setImageDescriptor(JavaPluginImages.getDescriptor(JavaPluginImages.IMG_CORRECTION_CHANGE)); + result.setActionDefinitionId(IJavaEditorActionDefinitionIds.SURROUND_WITH_TRY_WITH_RESOURCES); + editor.setAction("SurroundWithTryWithResources", result); //$NON-NLS-1$ + return result; + } + static SurroundWithTryMultiCatchAction createSurroundWithTryMultiCatchAction(CompilationUnitEditor editor) { SurroundWithTryMultiCatchAction result= new SurroundWithTryMultiCatchAction(editor); result.setText(ActionMessages.SurroundWithTemplateMenuAction_SurroundWithTryMultiCatchActionName); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithTemplateMenuAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithTemplateMenuAction.java index 0c731b21b9..70819201b1 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithTemplateMenuAction.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/SurroundWithTemplateMenuAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -62,6 +62,7 @@ import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jdt.ui.actions.SurroundWithTryCatchAction; import org.eclipse.jdt.ui.actions.SurroundWithTryMultiCatchAction; +import org.eclipse.jdt.ui.actions.SurroundWithTryWithResourcesAction; import org.eclipse.jdt.ui.text.IJavaPartitions; import org.eclipse.jdt.ui.text.java.IInvocationContext; import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; @@ -169,14 +170,17 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD return fMenu; } - public static void fillMenu(IMenuManager menu, CompilationUnitEditor editor, SurroundWithTryCatchAction surroundWithTryCatchAction, SurroundWithTryMultiCatchAction surroundWithTryMultiCatchAction) { + public static void fillMenu(IMenuManager menu, CompilationUnitEditor editor, SurroundWithTryCatchAction surroundWithTryCatchAction, + SurroundWithTryMultiCatchAction surroundWithTryMultiCatchAction, SurroundWithTryWithResourcesAction surroundWithTryWithResourcesAction) { IAction[] actions= getTemplateActions(editor); surroundWithTryCatchAction.update(editor.getSelectionProvider().getSelection()); boolean addSurroundWithTryCatchAction= surroundWithTryCatchAction.isEnabled() && !isInJavadoc(editor); boolean addSurroundWithTryMultiCatchAction= surroundWithTryMultiCatchAction.isEnabled() && !isInJavadoc(editor); + boolean addSurroundWithTryWithResourcesAction= surroundWithTryWithResourcesAction.isEnabled() && !isInJavadoc(editor); - if ((actions == null || actions.length == 0) && (!addSurroundWithTryCatchAction && !addSurroundWithTryMultiCatchAction)) { + if ((actions == null || actions.length == 0) && + (!addSurroundWithTryCatchAction && !addSurroundWithTryMultiCatchAction && !addSurroundWithTryWithResourcesAction)) { menu.add(NONE_APPLICABLE_ACTION); } else { if (addSurroundWithTryCatchAction) @@ -185,6 +189,10 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD if (addSurroundWithTryMultiCatchAction) menu.add(surroundWithTryMultiCatchAction); + if (addSurroundWithTryWithResourcesAction) { + menu.add(surroundWithTryWithResourcesAction); + } + menu.add(new Separator(TEMPLATE_GROUP)); for (int i= 0; actions != null && i < actions.length; i++) menu.add(actions[i]); @@ -233,7 +241,8 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD protected void fillMenu(IMenuManager menu) { SurroundWithTryCatchAction surroundWithTryCatch= SurroundWithActionGroup.createSurroundWithTryCatchAction(editor); SurroundWithTryMultiCatchAction surroundWithTryMultiCatch= SurroundWithActionGroup.createSurroundWithTryMultiCatchAction(editor); - SurroundWithTemplateMenuAction.fillMenu(menu, editor, surroundWithTryCatch, surroundWithTryMultiCatch); + SurroundWithTryWithResourcesAction surroundWithTryWithResources= SurroundWithActionGroup.createSurroundWithTryWithResourcesAction(editor); + SurroundWithTemplateMenuAction.fillMenu(menu, editor, surroundWithTryCatch, surroundWithTryMultiCatch, surroundWithTryWithResources); } }.createMenu(); } @@ -269,10 +278,13 @@ public class SurroundWithTemplateMenuAction implements IWorkbenchWindowPulldownD if (addSurroundWith) { SurroundWithTryCatchAction surroundWithTryCatch= SurroundWithActionGroup.createSurroundWithTryCatchAction(editor); SurroundWithTryMultiCatchAction surroundWithTryMultiCatch= SurroundWithActionGroup.createSurroundWithTryMultiCatchAction(editor); + SurroundWithTryWithResourcesAction surroundWithTryWithResources= SurroundWithActionGroup.createSurroundWithTryWithResourcesAction(editor); ActionContributionItem surroundWithTryCatchItem= new ActionContributionItem(surroundWithTryCatch); ActionContributionItem surroundWithTryMultiCatchItem= new ActionContributionItem(surroundWithTryMultiCatch); + ActionContributionItem surroundWithTryWithResourcesItem= new ActionContributionItem(surroundWithTryWithResources); surroundWithTryCatchItem.fill(menu, -1); + surroundWithTryWithResourcesItem.fill(menu, -1); surroundWithTryMultiCatchItem.fill(menu, -1); } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/LambdaExpressionAndMethodRefCleanUp.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/LambdaExpressionAndMethodRefCleanUp.java new file mode 100644 index 0000000000..3fcdde4118 --- /dev/null +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/LambdaExpressionAndMethodRefCleanUp.java @@ -0,0 +1,475 @@ +/******************************************************************************* + * Copyright (c) 2020 Fabrice TIERCELIN and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Fabrice TIERCELIN - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.ui.fix; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.Block; +import org.eclipse.jdt.core.dom.ClassInstanceCreation; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.CreationReference; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.ExpressionMethodReference; +import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; +import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; +import org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext; +import org.eclipse.jdt.core.dom.FieldAccess; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.LambdaExpression; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.Modifier; +import org.eclipse.jdt.core.dom.NumberLiteral; +import org.eclipse.jdt.core.dom.ReturnStatement; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.Statement; +import org.eclipse.jdt.core.dom.StringLiteral; +import org.eclipse.jdt.core.dom.SuperFieldAccess; +import org.eclipse.jdt.core.dom.SuperMethodInvocation; +import org.eclipse.jdt.core.dom.SuperMethodReference; +import org.eclipse.jdt.core.dom.ThisExpression; +import org.eclipse.jdt.core.dom.Type; +import org.eclipse.jdt.core.dom.TypeMethodReference; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; + +import org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext; +import org.eclipse.jdt.internal.corext.dom.ASTNodeFactory; +import org.eclipse.jdt.internal.corext.dom.ASTNodes; +import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFix; +import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFix.CompilationUnitRewriteOperation; +import org.eclipse.jdt.internal.corext.fix.LinkedProposalModel; +import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite; +import org.eclipse.jdt.internal.corext.util.JavaModelUtil; + +import org.eclipse.jdt.ui.cleanup.CleanUpRequirements; +import org.eclipse.jdt.ui.cleanup.ICleanUpFix; +import org.eclipse.jdt.ui.text.java.IProblemLocation; + +/** + * A fix that simplifies the lambda expression and the method reference syntax: + * <ul> + * <li>Parenthesis are not needed for a single untyped parameter,</li> + * <li>Return statement is not needed for a single expression,</li> + * <li>Brackets are not needed for a single statement,</li> + * <li>A lambda expression can be replaced by a creation or a method reference in some cases.</li> + * </ul> + */ +public class LambdaExpressionAndMethodRefCleanUp extends AbstractMultiFix { + public LambdaExpressionAndMethodRefCleanUp() { + this(Collections.emptyMap()); + } + + public LambdaExpressionAndMethodRefCleanUp(Map<String, String> options) { + super(options); + } + + @Override + public CleanUpRequirements getRequirements() { + boolean requireAST= isEnabled(CleanUpConstants.SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF); + Map<String, String> requiredOptions= null; + return new CleanUpRequirements(requireAST, false, false, requiredOptions); + } + + @Override + public String[] getStepDescriptions() { + if (isEnabled(CleanUpConstants.SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF)) { + return new String[] { MultiFixMessages.LambdaExpressionAndMethodRefCleanUp_description }; + } + return new String[0]; + } + + @SuppressWarnings("nls") + @Override + public String getPreview() { + StringBuilder bld= new StringBuilder(); + bld.append("\n"); + + if (isEnabled(CleanUpConstants.SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF)) { + bld.append("someString -> someString.trim().toLowerCase();\n"); + bld.append("someString -> someString.trim().toLowerCase();\n"); + bld.append("someString -> (someString.trim().toLowerCase() + \"bar\");\n"); + bld.append("ArrayList::new;\n"); + bld.append("Date::getTime;\n"); + } else { + bld.append("(someString) -> someString.trim().toLowerCase();\n"); + bld.append("someString -> {return someString.trim().toLowerCase();};\n"); + bld.append("someString -> {return someString.trim().toLowerCase() + \"bar\";};\n"); + bld.append("() -> new ArrayList<>();\n"); + bld.append("date -> date.getTime();\n"); + } + + return bld.toString(); + } + + @Override + protected ICleanUpFix createFix(CompilationUnit unit) throws CoreException { + if (!isEnabled(CleanUpConstants.SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF) || !JavaModelUtil.is18OrHigher(unit.getJavaElement().getJavaProject())) { + return null; + } + + final List<CompilationUnitRewriteOperation> rewriteOperations= new ArrayList<>(); + + unit.accept(new ASTVisitor() { + @Override + public boolean visit(final LambdaExpression node) { + if (node.hasParentheses() && node.parameters().size() == 1 + && node.parameters().get(0) instanceof VariableDeclarationFragment) { + rewriteOperations.add(new RemoveParamParenthesesOperation(node)); + return false; + } else if (node.getBody() instanceof Block) { + List<Statement> statements= ((Block) node.getBody()).statements(); + + if (statements.size() == 1 && statements.get(0) instanceof ReturnStatement) { + rewriteOperations.add(new RemoveReturnAndBracketsOperation(node, statements)); + return false; + } + } else if (node.getBody() instanceof ClassInstanceCreation) { + ClassInstanceCreation ci= (ClassInstanceCreation) node.getBody(); + + List<Expression> arguments= ci.arguments(); + if (node.parameters().size() == arguments.size() && areSameIdentifiers(node, arguments)) { + rewriteOperations.add(new ReplaceByCreationReferenceOperation(node, ci)); + return false; + } + } else if (node.getBody() instanceof SuperMethodInvocation) { + SuperMethodInvocation smi= (SuperMethodInvocation) node.getBody(); + List<Expression> arguments= smi.arguments(); + + if (node.parameters().size() == arguments.size() && areSameIdentifiers(node, arguments)) { + rewriteOperations.add(new ReplaceBySuperMethodReferenceOperation(node, smi)); + return false; + } + } else if (node.getBody() instanceof MethodInvocation) { + MethodInvocation methodInvocation= (MethodInvocation) node.getBody(); + Expression calledExpression= methodInvocation.getExpression(); + List<Expression> arguments= methodInvocation.arguments(); + + if (node.parameters().size() == arguments.size()) { + if (!areSameIdentifiers(node, arguments)) { + return true; + } + + IMethodBinding methodBinding= methodInvocation.resolveMethodBinding(); + + if (Boolean.TRUE.equals(ASTNodes.isStatic(methodInvocation))) { + if (methodBinding == null || methodBinding.getDeclaringClass() == null) { + return true; + } + + ITypeBinding calledType= methodBinding.getDeclaringClass(); + + if (!arguments.isEmpty()) { + String[] remainingParams= new String[arguments.size() - 1]; + + for (int i= 0; i < arguments.size() - 1; i++) { + ITypeBinding resolveTypeBinding= arguments.get(i + 1).resolveTypeBinding(); + + if (resolveTypeBinding == null) { + return true; + } + + remainingParams[i]= resolveTypeBinding.getQualifiedName(); + } + + for (IMethodBinding declaredMethodBinding : calledType.getDeclaredMethods()) { + if ((declaredMethodBinding.getModifiers() & Modifier.STATIC) == 0 && ASTNodes.usesGivenSignature(declaredMethodBinding, + calledType.getQualifiedName(), methodInvocation.getName().getIdentifier(), remainingParams)) { + return true; + } + } + } + + rewriteOperations.add(new ReplaceByTypeReferenceOperation(node, methodInvocation, calledType)); + return false; + } + + if (calledExpression instanceof StringLiteral || calledExpression instanceof NumberLiteral + || calledExpression instanceof ThisExpression) { + rewriteOperations.add(new ReplaceByMethodReferenceOperation(node, methodInvocation)); + return false; + } else if (calledExpression instanceof FieldAccess) { + FieldAccess fieldAccess= (FieldAccess) calledExpression; + + if (fieldAccess.resolveFieldBinding() != null && fieldAccess.resolveFieldBinding().isEffectivelyFinal()) { + rewriteOperations.add(new ReplaceByMethodReferenceOperation(node, methodInvocation)); + return false; + } + } else if (calledExpression instanceof SuperFieldAccess) { + SuperFieldAccess fieldAccess= (SuperFieldAccess) calledExpression; + + if (fieldAccess.resolveFieldBinding() != null && fieldAccess.resolveFieldBinding().isEffectivelyFinal()) { + rewriteOperations.add(new ReplaceByMethodReferenceOperation(node, methodInvocation)); + return false; + } + } + } else if (calledExpression instanceof SimpleName && node.parameters().size() == arguments.size() + 1) { + SimpleName calledObject= (SimpleName) calledExpression; + + if (isSameIdentifier(node, 0, calledObject)) { + for (int i= 0; i < arguments.size(); i++) { + ASTNode expression= ASTNodes.getUnparenthesedExpression(arguments.get(i)); + + if (!(expression instanceof SimpleName) || !isSameIdentifier(node, i + 1, (SimpleName) expression)) { + return true; + } + } + + ITypeBinding clazz= null; + if (calledExpression.resolveTypeBinding() != null) { + clazz= calledExpression.resolveTypeBinding(); + } else if (methodInvocation.resolveMethodBinding() != null && methodInvocation.resolveMethodBinding().getDeclaringClass() != null) { + clazz= methodInvocation.resolveMethodBinding().getDeclaringClass(); + } else { + return true; + } + + String[] cumulativeParams= new String[arguments.size() + 1]; + cumulativeParams[0]= clazz.getQualifiedName(); + + for (int i= 0; i < arguments.size(); i++) { + ITypeBinding resolveTypeBinding= arguments.get(i).resolveTypeBinding(); + + if (resolveTypeBinding == null) { + return true; + } + + cumulativeParams[i + 1]= resolveTypeBinding.getQualifiedName(); + } + + for (IMethodBinding declaredMethodBinding : clazz.getDeclaredMethods()) { + if ((declaredMethodBinding.getModifiers() & Modifier.STATIC) > 0 && ASTNodes.usesGivenSignature(declaredMethodBinding, + clazz.getQualifiedName(), methodInvocation.getName().getIdentifier(), cumulativeParams)) { + return true; + } + } + + rewriteOperations.add(new ReplaceByTypeReferenceOperation(node, methodInvocation, clazz)); + return false; + } + } + } + + return true; + } + + /** + * In order to make parameters implicit, those ones should be the same in the same + * order. + * + * @param node the lambda expression + * @param arguments The arguments in the expression + * @return true if the parameters are obvious + */ + private boolean areSameIdentifiers(LambdaExpression node, List<Expression> arguments) { + for (int i= 0; i < node.parameters().size(); i++) { + Expression expression= ASTNodes.getUnparenthesedExpression(arguments.get(i)); + + if (!(expression instanceof SimpleName) || !isSameIdentifier(node, i, (SimpleName) expression)) { + return false; + } + } + + return true; + } + + private boolean isSameIdentifier(final LambdaExpression node, final int i, final SimpleName argument) { + Object param0= node.parameters().get(i); + + if (param0 instanceof VariableDeclarationFragment) { + VariableDeclarationFragment vdf= (VariableDeclarationFragment) param0; + return vdf.getName().getIdentifier().equals(argument.getIdentifier()); + } + + return false; + } + }); + + if (rewriteOperations.isEmpty()) { + return null; + } + + return new CompilationUnitRewriteOperationsFix(MultiFixMessages.LambdaExpressionAndMethodRefCleanUp_description, unit, + rewriteOperations.toArray(new CompilationUnitRewriteOperation[rewriteOperations.size()])); + } + + @Override + public boolean canFix(ICompilationUnit compilationUnit, IProblemLocation problem) { + return false; + } + + @Override + protected ICleanUpFix createFix(CompilationUnit unit, IProblemLocation[] problems) throws CoreException { + return null; + } + + private static class RemoveParamParenthesesOperation extends CompilationUnitRewriteOperation { + private final LambdaExpression node; + + public RemoveParamParenthesesOperation(final LambdaExpression node) { + this.node= node; + } + + @Override + public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModel linkedModel) throws CoreException { + ASTRewrite rewrite= cuRewrite.getASTRewrite(); + AST ast= cuRewrite.getRoot().getAST(); + + LambdaExpression copyOfLambdaExpression= ast.newLambdaExpression(); + ASTNode copyOfParameter= rewrite.createCopyTarget((ASTNode) node.parameters().get(0)); + copyOfLambdaExpression.parameters().add(copyOfParameter); + copyOfLambdaExpression.setBody(rewrite.createCopyTarget(node.getBody())); + copyOfLambdaExpression.setParentheses(false); + rewrite.replace(node, copyOfLambdaExpression, null); + } + } + + private static class RemoveReturnAndBracketsOperation extends CompilationUnitRewriteOperation { + private final LambdaExpression node; + + private final List<Statement> statements; + + public RemoveReturnAndBracketsOperation(final LambdaExpression node, final List<Statement> statements) { + this.node= node; + this.statements= statements; + } + + @Override + public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModel linkedModel) throws CoreException { + ASTRewrite rewrite= cuRewrite.getASTRewrite(); + AST ast= cuRewrite.getRoot().getAST(); + + ReturnStatement returnStatement= (ReturnStatement) statements.get(0); + Expression copyOfExpression= (Expression) rewrite.createCopyTarget(returnStatement.getExpression()); + rewrite.replace(node.getBody(), ASTNodeFactory.parenthesizeIfNeeded(ast, copyOfExpression), null); + } + } + + private static class ReplaceByCreationReferenceOperation extends CompilationUnitRewriteOperation { + private final LambdaExpression node; + + private final ClassInstanceCreation classInstanceCreation; + + public ReplaceByCreationReferenceOperation(final LambdaExpression node, final ClassInstanceCreation classInstanceCreation) { + this.node= node; + this.classInstanceCreation= classInstanceCreation; + } + + @Override + public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModel linkedModel) throws CoreException { + ASTRewrite rewrite= cuRewrite.getASTRewrite(); + AST ast= cuRewrite.getRoot().getAST(); + + CreationReference creationRef= ast.newCreationReference(); + creationRef.setType(copyType(cuRewrite, ast, classInstanceCreation, classInstanceCreation.resolveTypeBinding())); + rewrite.replace(node, creationRef, null); + } + } + + private static class ReplaceBySuperMethodReferenceOperation extends CompilationUnitRewriteOperation { + private final LambdaExpression node; + + private final SuperMethodInvocation superMethodInvocation; + + public ReplaceBySuperMethodReferenceOperation(final LambdaExpression node, final SuperMethodInvocation superMethodInvocation) { + this.node= node; + this.superMethodInvocation= superMethodInvocation; + } + + @Override + public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModel linkedModel) throws CoreException { + ASTRewrite rewrite= cuRewrite.getASTRewrite(); + AST ast= cuRewrite.getRoot().getAST(); + + SuperMethodReference creationRef= ast.newSuperMethodReference(); + creationRef.setName((SimpleName) rewrite.createCopyTarget(superMethodInvocation.getName())); + rewrite.replace(node, creationRef, null); + } + } + + private static class ReplaceByTypeReferenceOperation extends CompilationUnitRewriteOperation { + private final LambdaExpression node; + private final MethodInvocation methodInvocation; + + private final ITypeBinding type; + + public ReplaceByTypeReferenceOperation(LambdaExpression node, MethodInvocation methodInvocation, ITypeBinding type) { + this.node= node; + this.methodInvocation= methodInvocation; + this.type= type; + } + + @Override + public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModel linkedModel) throws CoreException { + ASTRewrite rewrite= cuRewrite.getASTRewrite(); + AST ast= cuRewrite.getRoot().getAST(); + + TypeMethodReference typeMethodRef= ast.newTypeMethodReference(); + + typeMethodRef.setType(copyType(cuRewrite, ast, methodInvocation, type)); + typeMethodRef.setName((SimpleName) rewrite.createCopyTarget(methodInvocation.getName())); + rewrite.replace(node, typeMethodRef, null); + } + } + + private static class ReplaceByMethodReferenceOperation extends CompilationUnitRewriteOperation { + private final LambdaExpression node; + + private final MethodInvocation methodInvocation; + + public ReplaceByMethodReferenceOperation(LambdaExpression node, MethodInvocation methodInvocation) { + this.node= node; + this.methodInvocation= methodInvocation; + } + + @Override + public void rewriteAST(final CompilationUnitRewrite cuRewrite, final LinkedProposalModel linkedModel) throws CoreException { + ASTRewrite rewrite= cuRewrite.getASTRewrite(); + AST ast= cuRewrite.getRoot().getAST(); + ExpressionMethodReference typeMethodRef= ast.newExpressionMethodReference(); + + if (methodInvocation.getExpression() != null) { + typeMethodRef.setExpression((Expression) rewrite.createCopyTarget(methodInvocation.getExpression())); + } else { + typeMethodRef.setExpression(ast.newThisExpression()); + } + + typeMethodRef.setName((SimpleName) rewrite.createCopyTarget(methodInvocation.getName())); + rewrite.replace(node, typeMethodRef, null); + } + } + + private static Type copyType(final CompilationUnitRewrite cuRewrite, final AST ast, final ASTNode node, final ITypeBinding typeBinding) { + ImportRewrite importRewrite= cuRewrite.getImportRewrite(); + ImportRewriteContext importContext= new ContextSensitiveImportRewriteContext(node, importRewrite); + ITypeBinding modifiedType; + + if (typeBinding.getTypeParameters().length == 0) { + modifiedType= typeBinding.getErasure(); + } else { + modifiedType= typeBinding; + } + + return ASTNodeFactory.newCreationType(ast, modifiedType, importRewrite, importContext); + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MapMethodCleanUp.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MapMethodCleanUp.java index 7490ad2485..549c959efb 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MapMethodCleanUp.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/fix/MapMethodCleanUp.java @@ -29,6 +29,7 @@ import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.Expression; import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.ThisExpression; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.internal.corext.dom.ASTNodes; @@ -114,7 +115,7 @@ public class MapMethodCleanUp extends AbstractMultiFix { public boolean visit(MethodInvocation mi) { MethodInvocation miExpression= ASTNodes.as(mi.getExpression(), MethodInvocation.class); - if (miExpression != null) { + if (miExpression != null && miExpression.getExpression() != null && ASTNodes.as(miExpression.getExpression(), ThisExpression.class) == null) { String subAggregateClass; if (ASTNodes.usesGivenSignature(miExpression, Map.class.getCanonicalName(), "keySet")) { //$NON-NLS-1$ diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaOutlinePage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaOutlinePage.java index d8511bd629..763774137c 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaOutlinePage.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaOutlinePage.java @@ -21,7 +21,6 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Vector; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.BusyIndicator; @@ -285,17 +284,15 @@ public class JavaOutlinePage extends Page implements IContentOutlinePage, IAdapt if (!initializers) return children; - Vector<IJavaElement> v= new Vector<>(); + ArrayList<IJavaElement> v= new ArrayList<>(); for (IJavaElement child : children) { if (matches(child)) { continue; } - v.addElement(child); + v.add(child); } - IJavaElement[] result= new IJavaElement[v.size()]; - v.copyInto(result); - return result; + return v.toArray(new IJavaElement[v.size()]); } @Override diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/navigator/JavaNavigatorContentProvider.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/navigator/JavaNavigatorContentProvider.java index 6ebf0e2dc0..ee2ba04d65 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/navigator/JavaNavigatorContentProvider.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/navigator/JavaNavigatorContentProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2018 IBM Corporation and others. + * Copyright (c) 2003, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -263,8 +263,8 @@ public class JavaNavigatorContentProvider extends Object parent = modification.getParent(); // As of 3.3, we no longer re-parent additions to IProject. if (parent instanceof IContainer) { - IJavaElement element = JavaCore.create((IContainer) parent); - if (element != null && element.exists()) { + IJavaElement element = convert((IContainer) parent); + if (element != null) { // we don't convert the root if( !(element instanceof IJavaModel) && !(element instanceof IJavaProject)) modification.setParent(element); @@ -275,6 +275,18 @@ public class JavaNavigatorContentProvider extends return false; } + private static IJavaElement convert(IResource resource) { + IJavaProject javaProject= JavaCore.create(resource.getProject()); + if (javaProject == null) { + return null; + } + IJavaElement javaElement= JavaCore.create(resource, javaProject); + if (javaElement == null || !javaElement.exists()) { + return null; + } + return javaElement; + } + /** * Converts the shape modification to use Java elements. * @@ -291,8 +303,8 @@ public class JavaNavigatorContentProvider extends Object child = childrenItr.next(); // only convert IFolders and IFiles if (child instanceof IFolder || child instanceof IFile) { - IJavaElement newChild = JavaCore.create((IResource) child); - if (newChild != null && newChild.exists()) { + IJavaElement newChild = convert((IResource) child); + if (newChild != null) { IJavaProject javaProject= newChild.getJavaProject(); if (javaProject != null && javaProject.isOnClasspath(newChild)) { childrenItr.remove(); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CodeAssistConfigurationBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CodeAssistConfigurationBlock.java index 71bed2ae96..2b0b22fe51 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CodeAssistConfigurationBlock.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CodeAssistConfigurationBlock.java @@ -82,6 +82,7 @@ class CodeAssistConfigurationBlock extends OptionsConfigurationBlock { private static final Key PREF_CODEASSIST_DEPRECATION_CHECK= getJDTCoreKey(JavaCore.CODEASSIST_DEPRECATION_CHECK); private static final Key PREF_CODEASSIST_CAMEL_CASE_MATCH= getJDTCoreKey(JavaCore.CODEASSIST_CAMEL_CASE_MATCH); private static final Key PREF_CODEASSIST_SUBSTRING_MATCH= getJDTCoreKey(JavaCore.CODEASSIST_SUBSTRING_MATCH); + private static final Key PREF_CODEASSIST_SUBWORD_MATCH= getJDTCoreKey(JavaCore.CODEASSIST_SUBWORD_MATCH); private static Key[] getAllKeys() { return new Key[] { @@ -102,6 +103,7 @@ class CodeAssistConfigurationBlock extends OptionsConfigurationBlock { PREF_CODEASSIST_DEPRECATION_CHECK, PREF_CODEASSIST_CAMEL_CASE_MATCH, PREF_CODEASSIST_SUBSTRING_MATCH, + PREF_CODEASSIST_SUBWORD_MATCH, PREF_CODEASSIST_DISABLE_COMPLETION_PROPOSAL_TRIGGER_CHARS }; } @@ -285,6 +287,9 @@ class CodeAssistConfigurationBlock extends OptionsConfigurationBlock { label= PreferencesMessages.CodeAssistConfigurationBlock_matchSubstring_label; addCheckBox(composite, label, PREF_CODEASSIST_SUBSTRING_MATCH, enabledDisabled, 0); + label= PreferencesMessages.CodeAssistConfigurationBlock_matchSubword_label; + addCheckBox(composite, label, PREF_CODEASSIST_SUBWORD_MATCH, enabledDisabled, 0); + label= PreferencesMessages.JavaEditorPreferencePage_showOnlyProposalsVisibleInTheInvocationContext; addCheckBox(composite, label, PREF_CODEASSIST_SHOW_VISIBLE_PROPOSALS, trueFalse, 0); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java index 014e645b93..ac88af8642 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java @@ -835,6 +835,7 @@ public final class PreferencesMessages extends NLS { public static String JavaBasePreferencePage_do_not_hide_dialog_message; public static String CodeAssistConfigurationBlock_matchCamelCase_label; public static String CodeAssistConfigurationBlock_matchSubstring_label; + public static String CodeAssistConfigurationBlock_matchSubword_label; public static String ComplianceConfigurationBlock_version16; public static String ComplianceConfigurationBlock_version17; public static String ComplianceConfigurationBlock_version18; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties index 1be6cb6594..55ce00a0db 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties @@ -935,6 +935,7 @@ CodeAssistConfigurationBlock_insertionSection_title=Insertion CodeAssistConfigurationBlock_sortingSection_title=Sorting and Filtering CodeAssistConfigurationBlock_matchCamelCase_label=Show ca&mel case matches CodeAssistConfigurationBlock_matchSubstring_label=Show su&bstring matches +CodeAssistConfigurationBlock_matchSubword_label=Show subword mat&ches CodeAssistConfigurationBlock_autoactivationSection_title=Auto Activation # do not translate the href argument (org.eclipse.jdt.ui.preferences.ProblemSeveritiesPreferencePage) TypeFilterPreferencePage_restricted_link=Type references with <a href="org.eclipse.jdt.ui.preferences.ProblemSeveritiesPreferencePage">access restrictions</a>: diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java index 7b6d1565c5..e2bb67676a 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -76,6 +76,7 @@ public class CleanUpMessages extends NLS { public static String CodeStyleTabPage_CheckboxName_ConvertFunctionalInterfaces; public static String CodeStyleTabPage_RadioName_UseLambdaWherePossible; public static String CodeStyleTabPage_RadioName_UseAnonymous; + public static String CodeStyleTabPage_CheckboxName_SimplifyLambdaExpressionAndMethodRefSyntax; public static String ContributedCleanUpTabPage_ErrorPage_message; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties index 58c0a9be90..f9e3770a19 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CleanUpMessages.properties @@ -55,6 +55,7 @@ CodeStyleTabPage_CheckboxName_UseParentheses=Use parent&heses in expressions CodeStyleTabPage_GroupName_FunctionalInterfaces=Functional interface instances CodeStyleTabPage_CheckboxName_ConvertFunctionalInterfaces=Con&vert functional interface instances CodeStyleTabPage_RadioName_UseLambdaWherePossible=Use lambda where possible +CodeStyleTabPage_CheckboxName_SimplifyLambdaExpressionAndMethodRefSyntax=Simplify &lambda expression and method reference syntax CodeStyleTabPage_RadioName_UseAnonymous=Use anonymous class ContributedCleanUpTabPage_ErrorPage_message=An error occurred while creating this page. See the error log for details diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java index f6ecb53041..d49586b02f 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/cleanup/CodeStyleTabPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -24,6 +24,7 @@ import org.eclipse.jdt.internal.ui.fix.AbstractCleanUp; import org.eclipse.jdt.internal.ui.fix.ControlStatementsCleanUp; import org.eclipse.jdt.internal.ui.fix.ConvertLoopCleanUp; import org.eclipse.jdt.internal.ui.fix.ExpressionsCleanUp; +import org.eclipse.jdt.internal.ui.fix.LambdaExpressionAndMethodRefCleanUp; import org.eclipse.jdt.internal.ui.fix.LambdaExpressionsCleanUp; import org.eclipse.jdt.internal.ui.fix.NumberSuffixCleanUp; import org.eclipse.jdt.internal.ui.fix.VariableDeclarationCleanUp; @@ -39,16 +40,17 @@ public final class CodeStyleTabPage extends AbstractCleanUpTabPage { new ExpressionsCleanUp(values), new NumberSuffixCleanUp(values), new VariableDeclarationCleanUp(values), - new LambdaExpressionsCleanUp(values) - }; - } + new LambdaExpressionsCleanUp(values), + new LambdaExpressionAndMethodRefCleanUp(values) + }; + } - @Override + @Override protected void doCreatePreferences(Composite composite, int numColumns) { Group controlGroup= createGroup(numColumns, composite, CleanUpMessages.CodeStyleTabPage_GroupName_ControlStatments); - final CheckboxPreference useBlockPref= createCheckboxPref(controlGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_UseBlocks, CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS, CleanUpModifyDialog.FALSE_TRUE); - intent(controlGroup); + final CheckboxPreference useBlockPref= createCheckboxPref(controlGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_UseBlocks, CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS, CleanUpModifyDialog.FALSE_TRUE); + intent(controlGroup); final RadioPreference useBlockAlwaysPref= createRadioPref(controlGroup, numColumns - 1, CleanUpMessages.CodeStyleTabPage_RadioName_AlwaysUseBlocks, CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_ALWAYS, CleanUpModifyDialog.FALSE_TRUE); intent(controlGroup); final RadioPreference useBlockJDTStylePref= createRadioPref(controlGroup, numColumns - 1, CleanUpMessages.CodeStyleTabPage_RadioName_UseBlocksSpecial, CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NO_FOR_RETURN_AND_THROW, CleanUpModifyDialog.FALSE_TRUE); @@ -56,12 +58,12 @@ public final class CodeStyleTabPage extends AbstractCleanUpTabPage { final RadioPreference useBlockNeverPref= createRadioPref(controlGroup, numColumns - 1, CleanUpMessages.CodeStyleTabPage_RadioName_NeverUseBlocks, CleanUpConstants.CONTROL_STATMENTS_USE_BLOCKS_NEVER, CleanUpModifyDialog.FALSE_TRUE); registerSlavePreference(useBlockPref, new RadioPreference[] {useBlockAlwaysPref, useBlockJDTStylePref, useBlockNeverPref}); - CheckboxPreference convertLoop= createCheckboxPref(controlGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_ConvertForLoopToEnhanced, CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpModifyDialog.FALSE_TRUE); - registerPreference(convertLoop); + CheckboxPreference convertLoop= createCheckboxPref(controlGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_ConvertForLoopToEnhanced, CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED, CleanUpModifyDialog.FALSE_TRUE); + registerPreference(convertLoop); - Group expressionsGroup= createGroup(numColumns, composite, CleanUpMessages.CodeStyleTabPage_GroupName_Expressions); + Group expressionsGroup= createGroup(numColumns, composite, CleanUpMessages.CodeStyleTabPage_GroupName_Expressions); - final CheckboxPreference useParenthesesPref= createCheckboxPref(expressionsGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_UseParentheses, CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpModifyDialog.FALSE_TRUE); + final CheckboxPreference useParenthesesPref= createCheckboxPref(expressionsGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_UseParentheses, CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpModifyDialog.FALSE_TRUE); intent(expressionsGroup); final RadioPreference useParenthesesAlwaysPref= createRadioPref(expressionsGroup, 1, CleanUpMessages.CodeStyleTabPage_RadioName_AlwaysUseParantheses, CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS, CleanUpModifyDialog.FALSE_TRUE); final RadioPreference useParenthesesNeverPref= createRadioPref(expressionsGroup, 1, CleanUpMessages.CodeStyleTabPage_RadioName_NeverUseParantheses, CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpModifyDialog.FALSE_TRUE); @@ -75,7 +77,7 @@ public final class CodeStyleTabPage extends AbstractCleanUpTabPage { Group variableGroup= createGroup(numColumns, composite, CleanUpMessages.CodeStyleTabPage_GroupName_VariableDeclarations); - final CheckboxPreference useFinalPref= createCheckboxPref(variableGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_UseFinal, CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL, CleanUpModifyDialog.FALSE_TRUE); + final CheckboxPreference useFinalPref= createCheckboxPref(variableGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_UseFinal, CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL, CleanUpModifyDialog.FALSE_TRUE); intent(variableGroup); final CheckboxPreference useFinalFieldsPref= createCheckboxPref(variableGroup, 1, CleanUpMessages.CodeStyleTabPage_CheckboxName_UseFinalForFields, CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PRIVATE_FIELDS, CleanUpModifyDialog.FALSE_TRUE); final CheckboxPreference useFinalParametersPref= createCheckboxPref(variableGroup, 1, CleanUpMessages.CodeStyleTabPage_CheckboxName_UseFinalForParameters, CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PARAMETERS, CleanUpModifyDialog.FALSE_TRUE); @@ -89,5 +91,8 @@ public final class CodeStyleTabPage extends AbstractCleanUpTabPage { RadioPreference useLambdaPref= createRadioPref(functionalInterfacesGroup, 1, CleanUpMessages.CodeStyleTabPage_RadioName_UseLambdaWherePossible, CleanUpConstants.USE_LAMBDA, CleanUpModifyDialog.FALSE_TRUE); RadioPreference useAnonymousPref= createRadioPref(functionalInterfacesGroup, 1, CleanUpMessages.CodeStyleTabPage_RadioName_UseAnonymous, CleanUpConstants.USE_ANONYMOUS_CLASS_CREATION, CleanUpModifyDialog.FALSE_TRUE); registerSlavePreference(convertFunctionalInterfaces, new RadioPreference[] { useLambdaPref, useAnonymousPref }); + + CheckboxPreference simplifyLambdaExpressionAndMethodRef= createCheckboxPref(functionalInterfacesGroup, numColumns, CleanUpMessages.CodeStyleTabPage_CheckboxName_SimplifyLambdaExpressionAndMethodRefSyntax, CleanUpConstants.SIMPLIFY_LAMBDA_EXPRESSION_AND_METHOD_REF, CleanUpModifyDialog.FALSE_TRUE); + registerPreference(simplifyLambdaExpressionAndMethodRef); } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java index cce8d0a724..72f1f80d2f 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/IProposalRelevance.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2019 IBM Corporation and others. + * Copyright (c) 2012, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -278,6 +278,7 @@ public interface IProposalRelevance { public static final int ADD_JAVADOC_FIELD= 1; public static final int ADD_JAVADOC_TYPE= 1; public static final int ADD_JAVADOC_METHOD= 1; + public static final int ADD_JAVADOC_MODULE= 1; public static final int EXTRACT_METHOD_ERROR= 1; public static final int EXTRACT_CONSTANT_ERROR= 1; public static final int LINKED_NAMES_ASSIST_ERROR= 1; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/JavadocTagsSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/JavadocTagsSubProcessor.java index 9725f6a026..ae5c4ff7b6 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/JavadocTagsSubProcessor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/JavadocTagsSubProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -10,6 +10,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Red Hat Inc. - add module-info support *******************************************************************************/ package org.eclipse.jdt.internal.ui.text.correction; @@ -38,6 +39,7 @@ import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.IProblem; @@ -45,15 +47,21 @@ import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; import org.eclipse.jdt.core.dom.BodyDeclaration; +import org.eclipse.jdt.core.dom.Comment; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.EnumConstantDeclaration; import org.eclipse.jdt.core.dom.FieldDeclaration; import org.eclipse.jdt.core.dom.IBinding; import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.IModuleBinding; import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.Javadoc; import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.ModuleDeclaration; +import org.eclipse.jdt.core.dom.ModuleDirective; import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.core.dom.PrimitiveType; +import org.eclipse.jdt.core.dom.ProvidesDirective; import org.eclipse.jdt.core.dom.SimpleName; import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor; @@ -62,16 +70,19 @@ import org.eclipse.jdt.core.dom.TextElement; import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.TypeParameter; +import org.eclipse.jdt.core.dom.UsesDirective; import org.eclipse.jdt.core.dom.VariableDeclaration; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; import org.eclipse.jdt.core.dom.rewrite.ListRewrite; import org.eclipse.jdt.core.manipulation.CodeGeneration; -import org.eclipse.jdt.internal.corext.dom.ASTNodes; -import org.eclipse.jdt.internal.corext.dom.Bindings; +import org.eclipse.jdt.internal.core.manipulation.StubUtility; import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving; import org.eclipse.jdt.internal.core.manipulation.util.Strings; +import org.eclipse.jdt.internal.corext.dom.ASTNodes; +import org.eclipse.jdt.internal.corext.dom.Bindings; +import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.ui.text.java.IInvocationContext; import org.eclipse.jdt.ui.text.java.IProblemLocation; @@ -82,6 +93,7 @@ import org.eclipse.jdt.ui.text.java.correction.ICommandAccess; import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.JavaUIStatus; import org.eclipse.jdt.internal.ui.text.correction.proposals.LinkedCorrectionProposal; +import org.eclipse.jdt.internal.ui.text.correction.proposals.ReplaceCorrectionProposal; /** * @@ -121,22 +133,187 @@ public class JavadocTagsSubProcessor { } } + private static final class AddMissingModuleJavadocTagProposal extends CUCorrectionProposal { + + private final ModuleDeclaration fDecl; // MethodDecl or TypeDecl or ModuleDecl + private final ASTNode fMissingNode; + + public AddMissingModuleJavadocTagProposal(String label, ICompilationUnit cu, ModuleDeclaration decl, ASTNode missingNode, int relevance) { + super(label, cu, null, relevance, JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVADOCTAG)); + fDecl= decl; + fMissingNode= missingNode; + } + + @Override + protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException { + try { + Javadoc javadoc= null; + int insertPosition= -1; + String lineDelimiter= TextUtilities.getDefaultLineDelimiter(document); + final IJavaProject project= getCompilationUnit().getJavaProject(); + CompilationUnit cu= (CompilationUnit)fDecl.getParent(); + Name name= fDecl.getName(); + List<Comment> comments= cu.getCommentList(); + for (int i= 0; i < comments.size(); ++i) { + Comment comment= comments.get(i); + if (comment instanceof Javadoc + && comment.getStartPosition() + comment.getLength() < name.getStartPosition()) { + javadoc= (Javadoc)comment; + } + } + if (javadoc == null) { + return; + } + String comment= ""; //$NON-NLS-1$ + insertPosition= findInsertPosition(javadoc, fMissingNode, document, lineDelimiter); + + if (fMissingNode instanceof UsesDirective) { + UsesDirective directive= (UsesDirective)fMissingNode; + comment+= " * " + TagElement.TAG_USES + //$NON-NLS-1$ + " " + directive.getName().getFullyQualifiedName().toString() + lineDelimiter; //$NON-NLS-1$ + } else if (fMissingNode instanceof ProvidesDirective) { + ProvidesDirective directive= (ProvidesDirective)fMissingNode; + comment+= " * " + TagElement.TAG_PROVIDES + //$NON-NLS-1$ + " " + directive.getName().getFullyQualifiedName().toString() + lineDelimiter; //$NON-NLS-1$ + } + IRegion region= document.getLineInformationOfOffset(insertPosition); + + String lineContent= document.get(region.getOffset(), region.getLength()); + String indentString= Strings.getIndentString(lineContent, project); + String str= Strings.changeIndent(comment, 0, project, indentString, lineDelimiter); + InsertEdit edit= new InsertEdit(insertPosition, str); + rootEdit.addChild(edit); + } catch (BadLocationException e) { + throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e)); + } + } + + public static int findInsertPosition(Javadoc javadoc, @SuppressWarnings("unused") ASTNode node, IDocument document, String lineDelimiter) throws BadLocationException { + int position= -1; + List<TagElement> tags= javadoc.tags(); + TagElement lastTag= null; + // Put new tag after last @provides tag if found + for (TagElement tag : tags) { + String name= tag.getTagName(); + if (TagElement.TAG_PROVIDES.equals(name)) { + lastTag= tag; + } + } + if (lastTag == null) { + // otherwise add before first @uses tag + for (TagElement tag : tags) { + String name= tag.getTagName(); + if (TagElement.TAG_USES.equals(name)) { + IRegion region= document.getLineInformationOfOffset(tag.getStartPosition()); + return region.getOffset(); + } + } + } + // otherwise put after last tag + if (lastTag == null && !tags.isEmpty()) { + lastTag= tags.get(tags.size() - 1); + } + if (lastTag != null) { + IRegion region= document.getLineInformationOfOffset(lastTag.getStartPosition()); + position= region.getOffset() + region.getLength() + lineDelimiter.length(); + } else { + // otherwise put after javadoc comment start + IRegion region= document.getLineInformationOfOffset(javadoc.getStartPosition()); + position= region.getOffset() + region.getLength() + lineDelimiter.length(); + } + return position; + } + + } + + private static final class AddAllMissingModuleJavadocTagsProposal extends CUCorrectionProposal { + + private final ModuleDeclaration fDecl; // MethodDecl or TypeDecl or ModuleDecl + private final ASTNode fMissingNode; + + public AddAllMissingModuleJavadocTagsProposal(String label, ICompilationUnit cu, ModuleDeclaration decl, ASTNode missingNode, int relevance) { + super(label, cu, null, relevance, JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVADOCTAG)); + fDecl= decl; + fMissingNode= missingNode; + } + + @Override + protected void addEdits(IDocument document, TextEdit rootEdit) throws CoreException { + try { + Javadoc javadoc= null; + int insertPosition= -1; + String lineDelimiter= TextUtilities.getDefaultLineDelimiter(document); + final IJavaProject project= getCompilationUnit().getJavaProject(); + CompilationUnit cu= (CompilationUnit)fDecl.getParent(); + Name moduleName= fDecl.getName(); + List<Comment> comments= cu.getCommentList(); + for (int i= 0; i < comments.size(); ++i) { + Comment comment= comments.get(i); + if (comment instanceof Javadoc + && comment.getStartPosition() + comment.getLength() < moduleName.getStartPosition()) { + javadoc= (Javadoc)comment; + } + } + if (javadoc == null) { + return; + } + String comment= ""; //$NON-NLS-1$ + insertPosition= AddMissingModuleJavadocTagProposal.findInsertPosition(javadoc, fMissingNode, document, lineDelimiter); + + List<ModuleDirective> moduleStatements= fDecl.moduleStatements(); + for (int i= moduleStatements.size() - 1; i >= 0 ; i--) { + ModuleDirective directive= moduleStatements.get(i); + String name; + if (directive instanceof ProvidesDirective) { + name= ((ProvidesDirective)directive).getName().getFullyQualifiedName().toString(); + if (findTag(javadoc, TagElement.TAG_PROVIDES, name) == null) { + comment+= " * " + TagElement.TAG_PROVIDES + //$NON-NLS-1$ + " " + name + lineDelimiter; //$NON-NLS-1$ + } + } + } + + for (int i= moduleStatements.size() - 1; i >= 0 ; i--) { + ModuleDirective directive= moduleStatements.get(i); + String name; + if (directive instanceof UsesDirective) { + name= ((UsesDirective)directive).getName().getFullyQualifiedName().toString(); + if (findTag(javadoc, TagElement.TAG_USES, name) == null) { + comment+= " * " + TagElement.TAG_USES + //$NON-NLS-1$ + " " + name + lineDelimiter; //$NON-NLS-1$ + } + } + } + + IRegion region= document.getLineInformationOfOffset(insertPosition); + + String lineContent= document.get(region.getOffset(), region.getLength()); + String indentString= Strings.getIndentString(lineContent, project); + String str= Strings.changeIndent(comment, 0, project, indentString, lineDelimiter); + InsertEdit edit= new InsertEdit(insertPosition, str); + rootEdit.addChild(edit); + } catch (BadLocationException e) { + throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e)); + } + } + } + private static final class AddMissingJavadocTagProposal extends LinkedCorrectionProposal { - private final BodyDeclaration fBodyDecl; // MethodDecl or TypeDecl + private final ASTNode fDecl; // MethodDecl or TypeDecl private final ASTNode fMissingNode; - public AddMissingJavadocTagProposal(String label, ICompilationUnit cu, BodyDeclaration bodyDecl, ASTNode missingNode, int relevance) { + public AddMissingJavadocTagProposal(String label, ICompilationUnit cu, ASTNode decl, ASTNode missingNode, int relevance) { super(label, cu, null, relevance, JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVADOCTAG)); - fBodyDecl= bodyDecl; + fDecl= decl; fMissingNode= missingNode; } @Override protected ASTRewrite getRewrite() throws CoreException { - AST ast= fBodyDecl.getAST(); + AST ast= fDecl.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); - insertMissingJavadocTag(rewrite, fMissingNode, fBodyDecl); + insertMissingJavadocTag(rewrite, fMissingNode, (BodyDeclaration)fDecl); return rewrite; } @@ -221,20 +398,20 @@ public class JavadocTagsSubProcessor { private static final class AddAllMissingJavadocTagsProposal extends LinkedCorrectionProposal { - private final BodyDeclaration fBodyDecl; + private final ASTNode fDecl; - public AddAllMissingJavadocTagsProposal(String label, ICompilationUnit cu, BodyDeclaration bodyDecl, int relevance) { + public AddAllMissingJavadocTagsProposal(String label, ICompilationUnit cu, ASTNode decl, int relevance) { super(label, cu, null, relevance, JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVADOCTAG)); - fBodyDecl= bodyDecl; + fDecl= decl; } @Override protected ASTRewrite getRewrite() throws CoreException { - ASTRewrite rewrite= ASTRewrite.create(fBodyDecl.getAST()); - if (fBodyDecl instanceof MethodDeclaration) { - insertAllMissingMethodTags(rewrite, (MethodDeclaration) fBodyDecl); + ASTRewrite rewrite= ASTRewrite.create(fDecl.getAST()); + if (fDecl instanceof MethodDeclaration) { + insertAllMissingMethodTags(rewrite, (MethodDeclaration) fDecl); } else { - insertAllMissingTypeTags(rewrite, (TypeDeclaration) fBodyDecl); + insertAllMissingTypeTags(rewrite, (TypeDeclaration) fDecl); } return rewrite; } @@ -302,7 +479,7 @@ public class JavadocTagsSubProcessor { } } } - } + } private void insertAllMissingTypeTags(ASTRewrite rewriter, TypeDeclaration typeDecl) { AST ast= typeDecl.getAST(); @@ -336,46 +513,64 @@ public class JavadocTagsSubProcessor { public static void getMissingJavadocTagProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode node= problem.getCoveringNode(context.getASTRoot()); + ASTNode parentDeclaration= null; if (node == null) { return; } node= ASTNodes.getNormalizedNode(node); - - BodyDeclaration bodyDeclaration= ASTResolving.findParentBodyDeclaration(node); - if (bodyDeclaration == null) { - return; - } - Javadoc javadoc= bodyDeclaration.getJavadoc(); - if (javadoc == null) { - return; - } - String label; + StructuralPropertyDescriptor location= node.getLocationInParent(); - if (location == SingleVariableDeclaration.NAME_PROPERTY) { - label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description; - if (node.getParent().getLocationInParent() != MethodDeclaration.PARAMETERS_PROPERTY) { - return; // paranoia checks + if (location == ModuleDeclaration.MODULE_DIRECTIVES_PROPERTY) { + if (node instanceof UsesDirective) { + label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_usestag_description; + } else if (node instanceof ProvidesDirective) { + label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_providestag_description; + } else { + return; } - } else if (location == TypeParameter.NAME_PROPERTY) { - label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description; - StructuralPropertyDescriptor parentLocation= node.getParent().getLocationInParent(); - if (parentLocation != MethodDeclaration.TYPE_PARAMETERS_PROPERTY && parentLocation != TypeDeclaration.TYPE_PARAMETERS_PROPERTY) { - return; // paranoia checks - } - } else if (location == MethodDeclaration.RETURN_TYPE2_PROPERTY) { - label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_returntag_description; - } else if (location == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) { - label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_throwstag_description; + ModuleDeclaration moduleDecl= (ModuleDeclaration)node.getParent(); + CUCorrectionProposal proposal= new AddMissingModuleJavadocTagProposal(label, context.getCompilationUnit(), moduleDecl, node, IProposalRelevance.ADD_MISSING_TAG); + proposals.add(proposal); + + String label2= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_allmissing_description; + CUCorrectionProposal addAllMissing= new AddAllMissingModuleJavadocTagsProposal(label2, context.getCompilationUnit(), moduleDecl, node, IProposalRelevance.ADD_ALL_MISSING_TAGS); + proposals.add(addAllMissing); } else { - return; - } - ASTRewriteCorrectionProposal proposal= new AddMissingJavadocTagProposal(label, context.getCompilationUnit(), bodyDeclaration, node, IProposalRelevance.ADD_MISSING_TAG); - proposals.add(proposal); + parentDeclaration= ASTResolving.findParentBodyDeclaration(node); + if (parentDeclaration == null) { + return; + } + Javadoc javadoc= ((BodyDeclaration)parentDeclaration).getJavadoc(); + if (javadoc == null) { + return; + } - String label2= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_allmissing_description; - ASTRewriteCorrectionProposal addAllMissing= new AddAllMissingJavadocTagsProposal(label2, context.getCompilationUnit(), bodyDeclaration, IProposalRelevance.ADD_ALL_MISSING_TAGS); - proposals.add(addAllMissing); + if (location == SingleVariableDeclaration.NAME_PROPERTY) { + label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description; + if (node.getParent().getLocationInParent() != MethodDeclaration.PARAMETERS_PROPERTY) { + return; // paranoia checks + } + } else if (location == TypeParameter.NAME_PROPERTY) { + label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_paramtag_description; + StructuralPropertyDescriptor parentLocation= node.getParent().getLocationInParent(); + if (parentLocation != MethodDeclaration.TYPE_PARAMETERS_PROPERTY && parentLocation != TypeDeclaration.TYPE_PARAMETERS_PROPERTY) { + return; // paranoia checks + } + } else if (location == MethodDeclaration.RETURN_TYPE2_PROPERTY) { + label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_returntag_description; + } else if (location == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) { + label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_throwstag_description; + } else { + return; + } + ASTRewriteCorrectionProposal proposal= new AddMissingJavadocTagProposal(label, context.getCompilationUnit(), parentDeclaration, node, IProposalRelevance.ADD_MISSING_TAG); + proposals.add(proposal); + + String label2= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_allmissing_description; + ASTRewriteCorrectionProposal addAllMissing= new AddAllMissingJavadocTagsProposal(label2, context.getCompilationUnit(), parentDeclaration, IProposalRelevance.ADD_ALL_MISSING_TAGS); + proposals.add(addAllMissing); + } } public static void getUnusedAndUndocumentedParameterOrExceptionProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { @@ -423,66 +618,87 @@ public class JavadocTagsSubProcessor { if (node == null) { return; } - BodyDeclaration declaration= ASTResolving.findParentBodyDeclaration(node); - if (declaration == null) { - return; - } ICompilationUnit cu= context.getCompilationUnit(); - ITypeBinding binding= Bindings.getBindingOfParentType(declaration); - if (binding == null) { - return; - } - - if (declaration instanceof MethodDeclaration) { - MethodDeclaration methodDecl= (MethodDeclaration) declaration; - IMethodBinding methodBinding= methodDecl.resolveBinding(); - IMethodBinding overridden= null; - if (methodBinding != null) { - overridden= Bindings.findOverriddenMethod(methodBinding, true); - } + if (node instanceof ModuleDeclaration) { + ModuleDeclaration declaration= (ModuleDeclaration)node; + IModuleBinding binding= declaration.resolveBinding(); + if (binding == null) { + return; + } + List<String> usesNames= new ArrayList<>(); + for (ITypeBinding use : binding.getUses()) { + usesNames.add(use.getName()); + } + List<String> providesNames= new ArrayList<>(); + for (ITypeBinding provide : binding.getServices()) { + providesNames.add(provide.getName()); + } + String comment= CodeGeneration.getModuleComment(cu, declaration.getName().getFullyQualifiedName(), providesNames.toArray(new String[0]), usesNames.toArray(new String[0]), String.valueOf('\n')); + if (comment != null) { + String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_method_description; + proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_MODULE, declaration.getStartPosition(), comment)); + } + } else { + BodyDeclaration declaration= ASTResolving.findParentBodyDeclaration(node); + if (declaration == null) { + return; + } + ITypeBinding binding= Bindings.getBindingOfParentType(declaration); + if (binding == null) { + return; + } - String string= CodeGeneration.getMethodComment(cu, binding.getName(), methodDecl, overridden, String.valueOf('\n')); - if (string != null) { - String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_method_description; - proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_METHOD, declaration.getStartPosition(), string)); - } - } else if (declaration instanceof AbstractTypeDeclaration) { - String typeQualifiedName= Bindings.getTypeQualifiedName(binding); - String[] typeParamNames; - if (declaration instanceof TypeDeclaration) { - List<TypeParameter> typeParams= ((TypeDeclaration) declaration).typeParameters(); - typeParamNames= new String[typeParams.size()]; - for (int i= 0; i < typeParamNames.length; i++) { - typeParamNames[i]= (typeParams.get(i)).getName().getIdentifier(); - } - } else { - typeParamNames= new String[0]; - } - String string= CodeGeneration.getTypeComment(cu, typeQualifiedName, typeParamNames, String.valueOf('\n')); - if (string != null) { - String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_type_description; - proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_TYPE, declaration.getStartPosition(), string)); - } - } else if (declaration instanceof FieldDeclaration) { - String comment= "/**\n *\n */\n"; //$NON-NLS-1$ - List<VariableDeclarationFragment> fragments= ((FieldDeclaration)declaration).fragments(); - if (fragments != null && fragments.size() > 0) { - VariableDeclaration decl= fragments.get(0); - String fieldName= decl.getName().getIdentifier(); - String typeName= binding.getName(); - comment= CodeGeneration.getFieldComment(cu, typeName, fieldName, String.valueOf('\n')); - } - if (comment != null) { - String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_field_description; - proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_FIELD, declaration.getStartPosition(), comment)); - } - } else if (declaration instanceof EnumConstantDeclaration) { - EnumConstantDeclaration enumDecl= (EnumConstantDeclaration) declaration; - String id= enumDecl.getName().getIdentifier(); - String comment= CodeGeneration.getFieldComment(cu, binding.getName(), id, String.valueOf('\n')); - String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_enumconst_description; - proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_ENUM, declaration.getStartPosition(), comment)); - } + if (declaration instanceof MethodDeclaration) { + MethodDeclaration methodDecl= (MethodDeclaration) declaration; + IMethodBinding methodBinding= methodDecl.resolveBinding(); + IMethodBinding overridden= null; + if (methodBinding != null) { + overridden= Bindings.findOverriddenMethod(methodBinding, true); + } + + String string= CodeGeneration.getMethodComment(cu, binding.getName(), methodDecl, overridden, String.valueOf('\n')); + if (string != null) { + String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_method_description; + proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_METHOD, declaration.getStartPosition(), string)); + } + } else if (declaration instanceof AbstractTypeDeclaration) { + String typeQualifiedName= Bindings.getTypeQualifiedName(binding); + String[] typeParamNames; + if (declaration instanceof TypeDeclaration) { + List<TypeParameter> typeParams= ((TypeDeclaration) declaration).typeParameters(); + typeParamNames= new String[typeParams.size()]; + for (int i= 0; i < typeParamNames.length; i++) { + typeParamNames[i]= (typeParams.get(i)).getName().getIdentifier(); + } + } else { + typeParamNames= new String[0]; + } + String string= CodeGeneration.getTypeComment(cu, typeQualifiedName, typeParamNames, String.valueOf('\n')); + if (string != null) { + String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_type_description; + proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_TYPE, declaration.getStartPosition(), string)); + } + } else if (declaration instanceof FieldDeclaration) { + String comment= "/**\n *\n */\n"; //$NON-NLS-1$ + List<VariableDeclarationFragment> fragments= ((FieldDeclaration)declaration).fragments(); + if (fragments != null && fragments.size() > 0) { + VariableDeclaration decl= fragments.get(0); + String fieldName= decl.getName().getIdentifier(); + String typeName= binding.getName(); + comment= CodeGeneration.getFieldComment(cu, typeName, fieldName, String.valueOf('\n')); + } + if (comment != null) { + String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_field_description; + proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_FIELD, declaration.getStartPosition(), comment)); + } + } else if (declaration instanceof EnumConstantDeclaration) { + EnumConstantDeclaration enumDecl= (EnumConstantDeclaration) declaration; + String id= enumDecl.getName().getIdentifier(); + String comment= CodeGeneration.getFieldComment(cu, binding.getName(), id, String.valueOf('\n')); + String label= CorrectionMessages.JavadocTagsSubProcessor_addjavadoc_enumconst_description; + proposals.add(new AddJavadocCommentProposal(label, cu, IProposalRelevance.ADD_JAVADOC_ENUM, declaration.getStartPosition(), comment)); + } + } } public static Set<String> getPreviousTypeParamNames(List<TypeParameter> typeParams, ASTNode missingNode) { @@ -497,6 +713,30 @@ public class JavadocTagsSubProcessor { return previousNames; } + public static Set<String> getPreviousProvidesNames(List<ModuleDirective> directives, ASTNode missingNode) { + Set<String> previousNames= new HashSet<>(); + for (int i = 0; i < directives.size() && missingNode != directives.get(i); i++) { + ModuleDirective directive= directives.get(i); + if (directive instanceof ProvidesDirective) { + ProvidesDirective providesDirective= (ProvidesDirective)directive; + previousNames.add(providesDirective.getName().getFullyQualifiedName().toString()); + } + } + return previousNames; + } + + public static Set<String> getPreviousUsesNames(List<ModuleDirective> directives, ASTNode missingNode) { + Set<String> previousNames= new HashSet<>(); + for (int i = 0; i < directives.size() && missingNode != directives.get(i); i++) { + ModuleDirective directive= directives.get(i); + if (directive instanceof UsesDirective) { + UsesDirective usesDirective= (UsesDirective)directive; + previousNames.add(usesDirective.getName().getFullyQualifiedName().toString()); + } + } + return previousNames; + } + private static Set<String> getPreviousParamNames(List<SingleVariableDeclaration> params, ASTNode missingNode) { Set<String> previousNames= new HashSet<>(); for (int i = 0; i < params.size(); i++) { @@ -654,6 +894,10 @@ public class JavadocTagsSubProcessor { } else if (text.startsWith(String.valueOf('<')) && text.endsWith(String.valueOf('>')) && text.length() > 2) { return text.substring(1, text.length() - 1); } + } else if (first instanceof TextElement && (TagElement.TAG_USES.equals(curr.getTagName()) + || TagElement.TAG_PROVIDES.equals(curr.getTagName()))) { + String text= ((TextElement) first).getText(); + return text.trim(); } } return null; @@ -675,6 +919,60 @@ public class JavadocTagsSubProcessor { proposals.add(new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_TAG, image)); } + public static void getRemoveDuplicateModuleJavadocTagProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { + ASTNode node= problem.getCoveringNode(context.getASTRoot()); + if (node instanceof ModuleDeclaration) { + node= findModuleJavadocTag((ModuleDeclaration)node, problem); + if (node == null) { + return; + } + CompilationUnit cu= (CompilationUnit)((Javadoc)node.getParent()).getAlternateRoot(); + if (cu == null) { + return; + } + int line= cu.getLineNumber(problem.getOffset()); + IJavaElement javaElement= cu.getJavaElement(); + if (javaElement == null) { + return; + } + String lineDelimiter= StubUtility.getLineDelimiterUsed(javaElement); + int start= cu.getPosition(line, 0) - lineDelimiter.length(); + int column= cu.getColumnNumber(node.getStartPosition()); + int length= node.getLength() + column + lineDelimiter.length(); + String label= Messages.format(CorrectionMessages.JavadocTagsSubProcessor_removeduplicatetag_description, ((TextElement)((TagElement)node).fragments().get(0)).getText().trim()); + CUCorrectionProposal proposal= new ReplaceCorrectionProposal(label, context.getCompilationUnit(), start, length, + "", IProposalRelevance.REMOVE_TAG); //$NON-NLS-1$ + proposal.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE)); + proposals.add(proposal); + } + } + + @SuppressWarnings("rawtypes") + private static ASTNode findModuleJavadocTag(ModuleDeclaration decl, IProblemLocation problem) { + ASTNode result= null; + CompilationUnit cu= (CompilationUnit)decl.getParent(); + int problemLocationStart= problem.getOffset(); + Name moduleName= decl.getName(); + List comments= cu.getCommentList(); + for (int i= 0; i < comments.size(); ++i) { + Comment comment= (Comment)comments.get(i); + if (comment instanceof Javadoc + && comment.getStartPosition() + comment.getLength() < moduleName.getStartPosition()) { + Javadoc javadoc= (Javadoc)comment; + List tags= javadoc.tags(); + for (Object element : tags) { + TagElement tag= (TagElement)element; + if (problemLocationStart > tag.getStartPosition() + && problemLocationStart < tag.getStartPosition() + tag.getLength()) { + result= tag; + break; + } + } + } + } + return result; + } + public static void getInvalidQualificationProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode node= problem.getCoveringNode(context.getASTRoot()); if (!(node instanceof Name)) { diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java index 1092acbe14..3dff7df4f4 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -134,8 +134,10 @@ public class QuickFixProcessor implements IQuickFixProcessor { case IProblem.UnqualifiedFieldAccess: case IProblem.JavadocMissing: case IProblem.JavadocMissingParamTag: + case IProblem.JavadocMissingProvidesTag: case IProblem.JavadocMissingReturnTag: case IProblem.JavadocMissingThrowsTag: + case IProblem.JavadocMissingUsesTag: case IProblem.JavadocUndefinedType: case IProblem.JavadocAmbiguousType: case IProblem.JavadocNotVisibleType: @@ -143,6 +145,8 @@ public class QuickFixProcessor implements IQuickFixProcessor { case IProblem.JavadocDuplicateThrowsClassName: case IProblem.JavadocDuplicateReturnTag: case IProblem.JavadocDuplicateParamName: + case IProblem.JavadocDuplicateProvidesTag: + case IProblem.JavadocDuplicateUsesTag: case IProblem.JavadocInvalidParamName: case IProblem.JavadocUnexpectedTag: case IProblem.JavadocInvalidTag: @@ -592,6 +596,8 @@ public class QuickFixProcessor implements IQuickFixProcessor { case IProblem.JavadocMissingParamTag: case IProblem.JavadocMissingReturnTag: case IProblem.JavadocMissingThrowsTag: + case IProblem.JavadocMissingUsesTag: + case IProblem.JavadocMissingProvidesTag: JavadocTagsSubProcessor.getMissingJavadocTagProposals(context, problem, proposals); break; case IProblem.JavadocInvalidThrowsClassName: @@ -603,6 +609,10 @@ public class QuickFixProcessor implements IQuickFixProcessor { case IProblem.JavadocInvalidTag: JavadocTagsSubProcessor.getRemoveJavadocTagProposals(context, problem, proposals); break; + case IProblem.JavadocDuplicateProvidesTag: + case IProblem.JavadocDuplicateUsesTag: + JavadocTagsSubProcessor.getRemoveDuplicateModuleJavadocTagProposals(context, problem, proposals); + break; case IProblem.JavadocInvalidMemberTypeQualification: JavadocTagsSubProcessor.getInvalidQualificationProposals(context, problem, proposals); break; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java index 16555a64e8..3962f761c0 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java @@ -867,6 +867,9 @@ public abstract class AbstractJavaCompletionProposal implements IJavaCompletionP if (fPatternMatchRule == SearchPattern.R_SUBSTRING_MATCH) { return fRelevance - 500; } + if (fPatternMatchRule == SearchPattern.R_SUBWORD_MATCH) { + return fRelevance - 1000; + } return fRelevance; } @@ -941,6 +944,8 @@ public abstract class AbstractJavaCompletionProposal implements IJavaCompletionP return SearchPattern.R_CAMELCASE_MATCH; } else if (isSubstringMatching() && CharOperation.substringMatch(pattern.toCharArray(), string.toCharArray())) { return SearchPattern.R_SUBSTRING_MATCH; + } else if (isSubwordMatching() && CharOperation.subWordMatch(pattern.toCharArray(), string.toCharArray())) { + return SearchPattern.R_SUBWORD_MATCH; } else { return -1; } @@ -1004,6 +1009,11 @@ public abstract class AbstractJavaCompletionProposal implements IJavaCompletionP return JavaCore.ENABLED.equals(value); } + private boolean isSubwordMatching() { + String value= JavaCore.getOption(JavaCore.CODEASSIST_SUBWORD_MATCH); + return JavaCore.ENABLED.equals(value); + } + protected static boolean insertCompletion() { IPreferenceStore preference= JavaPlugin.getDefault().getPreferenceStore(); return preference.getBoolean(PreferenceConstants.CODEASSIST_INSERT_COMPLETION); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FillArgumentNamesCompletionProposalCollector.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FillArgumentNamesCompletionProposalCollector.java index 1bb53ce237..8a89dc7f91 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FillArgumentNamesCompletionProposalCollector.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/FillArgumentNamesCompletionProposalCollector.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,7 @@ package org.eclipse.jdt.internal.ui.text.java; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jdt.core.CompletionContext; import org.eclipse.jdt.core.CompletionProposal; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaProject; @@ -98,7 +99,9 @@ public final class FillArgumentNamesCompletionProposalCollector extends Completi char[] completion= typeProposal.getCompletion(); // don't add parameters for import-completions nor for proposals with an empty completion (e.g. inside the type argument list) - if (completion.length > 0 && (completion[completion.length - 1] == ';' || completion[completion.length - 1] == '.')) + if (completion.length > 0 && completion[completion.length - 1] == '.') + return super.createJavaCompletionProposal(typeProposal); + if (getInvocationContext().getCoreContext().getTokenLocation() == CompletionContext.TL_IN_IMPORT) return super.createJavaCompletionProposal(typeProposal); LazyJavaCompletionProposal newProposal= new LazyGenericTypeProposal(typeProposal, getInvocationContext()); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java index 5b0857b5a3..a98e3fb6f1 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java @@ -4118,8 +4118,11 @@ public class PreferenceConstants { store.setDefault(PreferenceConstants.CODEASSIST_FILL_ARGUMENT_NAMES, true); store.setDefault(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS, false); store.setDefault(PreferenceConstants.CODEASSIST_PREFIX_COMPLETION, false); + + // Be sure to add the newly introduced disabled categories to JavaPlugin.disableNewCodeAssistCategoryPreferences() store.setDefault(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES, "org.eclipse.jdt.ui.textProposalCategory\0org.eclipse.jdt.ui.javaTypeProposalCategory\0org.eclipse.jdt.ui.javaNoTypeProposalCategory\0org.eclipse.jdt.ui.javaChainProposalCategory\0org.eclipse.jdt.ui.javaPostfixProposalCategory\0"); //$NON-NLS-1$ store.setDefault(PreferenceConstants.CODEASSIST_CATEGORY_ORDER, "org.eclipse.jdt.ui.javaPostfixProposalCategory:65547\0org.eclipse.jdt.ui.javaChainProposalCategory:65546\0org.eclipse.jdt.ui.spellingProposalCategory:65545\0org.eclipse.jdt.ui.javaTypeProposalCategory:65540\0org.eclipse.jdt.ui.javaNoTypeProposalCategory:65539\0org.eclipse.jdt.ui.textProposalCategory:65541\0org.eclipse.jdt.ui.javaAllProposalCategory:65542\0org.eclipse.jdt.ui.templateProposalCategory:2\0org.eclipse.jdt.ui.swtProposalCategory:3\0"); //$NON-NLS-1$ + store.setDefault(PreferenceConstants.CODEASSIST_LRU_HISTORY, ""); //$NON-NLS-1$ store.setDefault(PreferenceConstants.CODEASSIST_SORTER, "org.eclipse.jdt.ui.RelevanceSorter"); //$NON-NLS-1$ store.setDefault(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, ""); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/IJavaEditorActionDefinitionIds.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/IJavaEditorActionDefinitionIds.java index 77528ce6fb..78e92108c4 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/IJavaEditorActionDefinitionIds.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/IJavaEditorActionDefinitionIds.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -233,6 +233,14 @@ public interface IJavaEditorActionDefinitionIds extends ITextEditorActionDefinit public static final String SURROUND_WITH_TRY_CATCH= "org.eclipse.jdt.ui.edit.text.java.surround.with.try.catch"; //$NON-NLS-1$ /** + * Action definition ID of the source -> surround with try-with-resources action + * (value <code>"org.eclipse.jdt.ui.edit.text.java.surround.with.try.with.resources"</code>). + * + * @since 3.21 + */ + public static final String SURROUND_WITH_TRY_WITH_RESOURCES= "org.eclipse.jdt.ui.edit.text.java.surround.with.try.with.resources"; //$NON-NLS-1$ + + /** * Action definition ID of the source -> surround with try/multi-catch action (value * <code>"org.eclipse.jdt.ui.edit.text.java.surround.with.try.multicatch"</code>). * diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/JdtActionConstants.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/JdtActionConstants.java index eead73cf8f..a5ffff04af 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/JdtActionConstants.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/JdtActionConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2019 IBM Corporation and others. + * Copyright (c) 2000, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -231,6 +231,14 @@ public class JdtActionConstants { public static final String SURROUND_WITH_TRY_MULTI_CATCH= "org.eclipse.jdt.ui.actions.SurroundWithTryMultiCatch"; //$NON-NLS-1$ /** + * Source menu: name of standard Surround with try-with-resources block global action (value + * <code>"org.eclipse.jdt.ui.actions.SurroundWithTryWithResources"</code>). + * + * @since 3.21 + */ + public static final String SURROUND_WITH_TRY_WITH_RESOURCES= "org.eclipse.jdt.ui.actions.SurroundWithTryWithResources"; //$NON-NLS-1$ + + /** * Source menu: name of standard Override Methods global action * (value <code>"org.eclipse.jdt.ui.actions.OverrideMethods"</code>). */ diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/SurroundWithTryWithResourcesAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/SurroundWithTryWithResourcesAction.java new file mode 100644 index 0000000000..d9ccd79d60 --- /dev/null +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/SurroundWithTryWithResourcesAction.java @@ -0,0 +1,154 @@ +/******************************************************************************* + * Copyright (c) 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - based on SurroundWithTryResourcesAction + *******************************************************************************/ +package org.eclipse.jdt.ui.actions; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; + +import org.eclipse.jface.dialogs.MessageDialog; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.ITextSelection; + +import org.eclipse.ui.PlatformUI; + +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.PerformChangeOperation; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.ISourceRange; + +import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels; +import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryWithResourcesRefactoring; +import org.eclipse.jdt.internal.corext.refactoring.util.JavaStatusContext; +import org.eclipse.jdt.internal.corext.util.JavaModelUtil; +import org.eclipse.jdt.internal.corext.util.Messages; + +import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; +import org.eclipse.jdt.internal.ui.JavaPlugin; +import org.eclipse.jdt.internal.ui.actions.ActionUtil; +import org.eclipse.jdt.internal.ui.actions.SelectionConverter; +import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter; +import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; +import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; +import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext; +import org.eclipse.jdt.internal.ui.util.ElementValidator; +import org.eclipse.jdt.internal.ui.util.ExceptionHandler; +import org.eclipse.jdt.internal.ui.viewsupport.LinkedProposalModelPresenter; + +/** + * Action to surround a set of statements with a try-with-resources/catch block. + * + * <p> + * This class may be instantiated; it is not intended to be subclassed. + * </p> + * + * @since 3.21 + * + * @noextend This class is not intended to be subclassed by clients. + */ +public class SurroundWithTryWithResourcesAction extends SelectionDispatchAction { + + CompilationUnitEditor fEditor; + + /** + * Note: This constructor is for internal use only. Clients should not call this constructor. + * @param editor the compilation unit editor + * + * @noreference This constructor is not intended to be referenced by clients. + */ + public SurroundWithTryWithResourcesAction(CompilationUnitEditor editor) { + super(editor.getEditorSite()); + setText(RefactoringMessages.SurroundWithTryResourcesAction_label); + fEditor= editor; + setEnabled(isApplicable()); + PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.SURROUND_WITH_TRY_WITH_RESOURCES_ACTION); + } + + @Override + public void run(ITextSelection selection) { + if (!ActionUtil.isEditable(fEditor)) + return; + ICompilationUnit cu= SelectionConverter.getInputAsCompilationUnit(fEditor); + + if (cu == null || !ElementValidator.checkValidateEdit(cu, getShell(), getDialogTitle())) + return; + + if (!JavaModelUtil.is18OrHigher(cu.getJavaProject())) { + String message= Messages.format(RefactoringMessages.SurroundWithTryResourcesAction_not18, BasicElementLabels.getJavaElementName(cu.getJavaProject().getElementName())); + MessageDialog.openInformation(JavaPlugin.getActiveWorkbenchShell(), getDialogTitle(), message); + return; + } + + SurroundWithTryWithResourcesRefactoring refactoring= createRefactoring(selection, cu); + + if (refactoring == null) + return; + try { + RefactoringStatus status= refactoring.checkInitialConditions(new NullProgressMonitor()); + if (status.hasFatalError()) { + RefactoringStatusEntry entry= status.getEntryMatchingSeverity(RefactoringStatus.FATAL); + MessageDialog.openInformation(getShell(), getDialogTitle(), entry.getMessage()); + if (entry.getContext() instanceof JavaStatusContext && fEditor != null) { + JavaStatusContext context= (JavaStatusContext)entry.getContext(); + ISourceRange range= context.getSourceRange(); + fEditor.setHighlightRange(range.getOffset(), range.getLength(), true); + } + return; + } + if (refactoring.stopExecution()) + return; + Change change= refactoring.createChange(new NullProgressMonitor()); + change.initializeValidationData(new NullProgressMonitor()); + PerformChangeOperation op= new PerformChangeOperation(change); + // must be fork == false since file buffers can't be manipulated in a different thread. + WorkbenchRunnableAdapter adapter= new WorkbenchRunnableAdapter(op); + PlatformUI.getWorkbench().getProgressService().runInUI( + new BusyIndicatorRunnableContext(), adapter, adapter.getSchedulingRule()); + + if (refactoring.getLinkedProposalModel().hasLinkedPositions()) + new LinkedProposalModelPresenter().enterLinkedMode(fEditor.getViewer(), fEditor, false, refactoring.getLinkedProposalModel()); + + } catch (CoreException e) { + ExceptionHandler.handle(e, getDialogTitle(), RefactoringMessages.SurroundWithTryResourcesAction_exception); + } catch (InvocationTargetException e) { + ExceptionHandler.handle(e, getDialogTitle(), RefactoringMessages.SurroundWithTryResourcesAction_exception); + } catch (InterruptedException e) { + // not cancelable + } catch (BadLocationException e) { + // ignore + } + } + + SurroundWithTryWithResourcesRefactoring createRefactoring(ITextSelection selection, ICompilationUnit cu) { + return SurroundWithTryWithResourcesRefactoring.create(cu, selection); + } + + @Override + public void selectionChanged(ITextSelection selection) { + setEnabled(selection.getLength() > 0 && isApplicable()); + } + + boolean isApplicable() { + return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null; + } + + String getDialogTitle() { + return RefactoringMessages.SurroundWithTryResourcesAction_dialog_title; + } +} diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java index c7eb638eff..82bafed546 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/wizards/NewJavaProjectWizardPageOne.java @@ -442,7 +442,7 @@ public class NewJavaProjectWizardPageOne extends WizardPage { break; } }, Display.getDefault()::asyncExec); - + CompletableFuture.runAsync(this::initializeJvmFields) .thenAcceptAsync((VOID) -> { if (fGroup.isDisposed()) { @@ -457,11 +457,11 @@ public class NewJavaProjectWizardPageOne extends WizardPage { notifyObservers(); }, Display.getDefault()::asyncExec); } - - + + private void initializeJvmFields () { fDefaultJVMLabel= getDefaultJVMLabel(); - + fInstalledJVMs= getWorkspaceJREs(); Arrays.sort(fInstalledJVMs, new Comparator<IVMInstall>() { @Override @@ -1041,7 +1041,7 @@ public class NewJavaProjectWizardPageOne extends WizardPage { setPageComplete(false); return; } - + if (fJREGroup.fUseEEJRE.isSelected() && fJREGroup.fEECombo.getItems().length == 0) { setPageComplete(false); return; @@ -1050,7 +1050,7 @@ public class NewJavaProjectWizardPageOne extends WizardPage { setPageComplete(false); return; } - + setPageComplete(true); setErrorMessage(null); diff --git a/org.eclipse.ltk.core.refactoring.tests/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.ltk.core.refactoring.tests/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.ltk.core.refactoring.tests/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.ltk.core.refactoring.tests/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/AllTests.java b/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/AllTests.java index 004de8171c..af1dcf809f 100644 --- a/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/AllTests.java +++ b/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/AllTests.java @@ -25,9 +25,9 @@ public class AllTests { public static Test suite() { TestSuite suite= new TestSuite(AllTests.class.getName()); - + suite.addTestSuite(RefactoringContextTest.class); - + suite.addTest(ParticipantTests.suite()); suite.addTest(RefactoringHistoryTests.suite()); suite.addTest(RefactoringScriptingTests.suite()); diff --git a/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/participants/CancelingParticipantTests.java b/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/participants/CancelingParticipantTests.java index 4cfcc30008..958d897892 100644 --- a/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/participants/CancelingParticipantTests.java +++ b/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/participants/CancelingParticipantTests.java @@ -55,7 +55,7 @@ public class CancelingParticipantTests extends TestCase { public String getName() { return "canceling participant"; } - + @Override public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException { if (fCancelStep == 0) { @@ -64,7 +64,7 @@ public class CancelingParticipantTests extends TestCase { } return new RefactoringStatus(); } - + @Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { if (fCancelStep == 1) { @@ -73,7 +73,7 @@ public class CancelingParticipantTests extends TestCase { } return new NullChange("1"); } - + @Override public Change createPreChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { if (fCancelStep == 2) { @@ -86,7 +86,7 @@ public class CancelingParticipantTests extends TestCase { private class TestProcessor extends RenameProcessor { private Object fElement= Boolean.TRUE; - + @Override public Object[] getElements() { return new Object[] { fElement }; @@ -124,7 +124,7 @@ public class CancelingParticipantTests extends TestCase { } private int fCancelStep; - + private ILogListener fLogListener; private List<IStatus> fLogEntries; @@ -144,60 +144,60 @@ public class CancelingParticipantTests extends TestCase { protected void tearDown() throws Exception { Platform.removeLogListener(fLogListener); } - + public void testCheckConditions() throws Exception { RenameRefactoring refactoring= new RenameRefactoring(new TestProcessor()); - + fCancelStep= 0; PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); NullProgressMonitor pm= new NullProgressMonitor(); - + boolean exception= false; try { ResourcesPlugin.getWorkspace().run(op, pm); } catch (OperationCanceledException e) { exception= true; } - + assertTrue(pm.isCanceled()); Assert.assertEquals(Collections.EMPTY_LIST.toString(), fLogEntries.toString()); Assert.assertTrue(exception); } - - + + public void testCreateChange() throws Exception { RenameRefactoring refactoring= new RenameRefactoring(new TestProcessor()); - + fCancelStep= 1; PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); NullProgressMonitor pm= new NullProgressMonitor(); - + boolean exception= false; try { ResourcesPlugin.getWorkspace().run(op, pm); } catch (OperationCanceledException e) { exception= true; } - + assertTrue(pm.isCanceled()); Assert.assertEquals(Collections.EMPTY_LIST.toString(), fLogEntries.toString()); Assert.assertTrue(exception); } - + public void testCreatePreChange() throws Exception { RenameRefactoring refactoring= new RenameRefactoring(new TestProcessor()); - + fCancelStep= 2; PerformRefactoringOperation op= new PerformRefactoringOperation(refactoring, CheckConditionsOperation.ALL_CONDITIONS); NullProgressMonitor pm= new NullProgressMonitor(); - + boolean exception= false; try { ResourcesPlugin.getWorkspace().run(op, pm); } catch (OperationCanceledException e) { exception= true; } - + assertTrue(pm.isCanceled()); Assert.assertEquals(Collections.EMPTY_LIST.toString(), fLogEntries.toString()); Assert.assertTrue(exception); diff --git a/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/participants/FailingParticipantTests.java b/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/participants/FailingParticipantTests.java index 778ca3a351..7deac2b297 100644 --- a/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/participants/FailingParticipantTests.java +++ b/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/participants/FailingParticipantTests.java @@ -52,7 +52,7 @@ public class FailingParticipantTests extends TestCase { protected void tearDown() throws Exception { Platform.removeLogListener(fLogListener); } - + private void resetLog() { fLogEntries= new ArrayList<>(); } diff --git a/org.eclipse.ltk.core.refactoring/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.ltk.core.refactoring/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.ltk.core.refactoring/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.ltk.core.refactoring/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/Change.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/Change.java index 623c98f2ab..5b76fc847c 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/Change.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/Change.java @@ -58,7 +58,7 @@ import org.eclipse.core.runtime.Platform; * Change change= createChange(); * try { * change.initializeValidationData(pm); - * + * * .... * * if (!change.isEnabled()) @@ -91,7 +91,7 @@ import org.eclipse.core.runtime.Platform; * <p> * Clients may subclass this class. * </p> - * + * * @since 3.0 */ public abstract class Change implements IAdaptable { diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/CompositeChange.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/CompositeChange.java index 34d88ff09d..0f5c8a3622 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/CompositeChange.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/CompositeChange.java @@ -435,7 +435,7 @@ public class CompositeChange extends Change { * <p> * This method is not intended to be overridden or extended. * </p> - * + * * @return the undo object containing all undo changes of those children that got successfully * executed while performing this change, or <code>null</code> if all changes were * executed successfully or if there's nothing to undo. diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/DocumentChange.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/DocumentChange.java index 9468cf12c6..72f01a4773 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/DocumentChange.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/DocumentChange.java @@ -106,12 +106,12 @@ public class DocumentChange extends TextChange { @Override protected UndoEdit performEdits(final IDocument document) throws BadLocationException, MalformedTreeException { ITextFileBufferManager fileBufferManager= FileBuffers.getTextFileBufferManager(); - + ITextFileBuffer fileBuffer= fileBufferManager.getTextFileBuffer(document); if (fileBuffer == null || ! fileBuffer.isSynchronizationContextRequested()) { return super.performEdits(document); } - + /** The lock for waiting for computation in the UI thread to complete. */ final Lock completionLock= new Lock(); final UndoEdit[] result= new UndoEdit[1]; @@ -131,7 +131,7 @@ public class DocumentChange extends TextChange { } } }; - + synchronized (completionLock) { fileBufferManager.execute(runnable); while (! completionLock.fDone) { @@ -141,14 +141,14 @@ public class DocumentChange extends TextChange { } } } - + if (exception[0] != null) { throw exception[0]; } - + return result[0]; } - + @Override protected Change createUndoChange(UndoEdit edit) { return new UndoDocumentChange(getName(), fDocument, edit); diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/MultiStateTextFileChange.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/MultiStateTextFileChange.java index c9ef44f0a0..25a2106453 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/MultiStateTextFileChange.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/MultiStateTextFileChange.java @@ -901,9 +901,9 @@ public class MultiStateTextFileChange extends TextEditBasedChange { performChangesInSynchronizationContext(document, undoList, preview); return; } - + ITextFileBufferManager fileBufferManager= FileBuffers.getTextFileBufferManager(); - + /** The lock for waiting for computation in the UI thread to complete. */ final Lock completionLock= new Lock(); final BadLocationException[] exception= new BadLocationException[1]; @@ -922,7 +922,7 @@ public class MultiStateTextFileChange extends TextEditBasedChange { } } }; - + synchronized (completionLock) { fileBufferManager.execute(runnable); while (! completionLock.fDone) { @@ -932,7 +932,7 @@ public class MultiStateTextFileChange extends TextEditBasedChange { } } } - + if (exception[0] != null) { throw exception[0]; } @@ -943,15 +943,15 @@ public class MultiStateTextFileChange extends TextEditBasedChange { try { if (document instanceof IDocumentExtension4) session= ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); - + for (final Iterator<ComposableBufferChange> iterator= fChanges.iterator(); iterator.hasNext();) { final ComposableBufferChange change= iterator.next(); - + final UndoEdit edit= createTextEditProcessor(change, document, undoList != null ? TextEdit.CREATE_UNDO : TextEdit.NONE, preview).performEdits(); if (undoList != null) undoList.addFirst(edit); } - + } finally { if (session != null) ((IDocumentExtension4) document).stopRewriteSession(session); diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformRefactoringHistoryOperation.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformRefactoringHistoryOperation.java index a4be4c07d0..1ee9a60ab2 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformRefactoringHistoryOperation.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformRefactoringHistoryOperation.java @@ -153,7 +153,7 @@ public class PerformRefactoringHistoryOperation implements IWorkspaceRunnable { * <p> * A caller of this method must ensure that {@link RefactoringContext#dispose()} is eventually called. * </p> - * + * * <p> * The default implementation delegates the task to the refactoring descriptor. * </p> diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformRefactoringOperation.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformRefactoringOperation.java index 9558546cf1..5f0495b2d8 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformRefactoringOperation.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/PerformRefactoringOperation.java @@ -57,7 +57,7 @@ public class PerformRefactoringOperation implements IWorkspaceRunnable { * @param refactoring the refactoring to perform * @param style the condition checking style as defined by * {@link CheckConditionsOperation} - * @see #PerformRefactoringOperation(RefactoringContext, int) + * @see #PerformRefactoringOperation(RefactoringContext, int) */ public PerformRefactoringOperation(Refactoring refactoring, int style) { Assert.isNotNull(refactoring); @@ -85,7 +85,7 @@ public class PerformRefactoringOperation implements IWorkspaceRunnable { fRefactoring= fRefactoringContext.getRefactoring(); fStyle= style; } - + /** * Return the refactoring status of the condition checking. * diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/Refactoring.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/Refactoring.java index c933e1f0ee..55f4753321 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/Refactoring.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/Refactoring.java @@ -63,7 +63,7 @@ import org.eclipse.core.runtime.SubProgressMonitor; * <p> * The class should be subclassed by clients wishing to implement new refactorings. * </p> - * + * * @see RefactoringContext * * @since 3.0 diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/RefactoringContext.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/RefactoringContext.java index 493578ef4e..4486b17d84 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/RefactoringContext.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/RefactoringContext.java @@ -33,7 +33,7 @@ public class RefactoringContext { /** * Creates a context for the given refactoring. - * + * * @param refactoring The refactoring associated with the context. Cannot be <code>null</code>. * @throws NullPointerException if refactoring is <code>null</code>. */ diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/RefactoringDescriptor.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/RefactoringDescriptor.java index 07d4e9a692..d393360ce0 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/RefactoringDescriptor.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/RefactoringDescriptor.java @@ -281,7 +281,7 @@ public abstract class RefactoringDescriptor implements Comparable<RefactoringDes return null; return new RefactoringContext(refactoring); } - + @Override public final boolean equals(final Object object) { if (object instanceof RefactoringDescriptor) { diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextChange.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextChange.java index 7e91a06ca6..09ad6a3b55 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextChange.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextChange.java @@ -238,10 +238,10 @@ public abstract class TextChange extends TextEditBasedChange { document= acquireDocument(new SubProgressMonitor(pm, 1)); UndoEdit undo= performEdits(document); - + commit(document, new SubProgressMonitor(pm, 1)); return createUndoChange(undo); - + } catch (BadLocationException e) { throw Changes.asCoreException(e); } catch (MalformedTreeException e) { @@ -255,7 +255,7 @@ public abstract class TextChange extends TextEditBasedChange { /** * Executes the text edits on the given document. * Subclasses that override this method should call <code>super.performEdits(document)</code>. - * + * * @param document the document * @return an object representing the undo of the executed edits * @exception MalformedTreeException is thrown if the edit tree isn't @@ -273,18 +273,18 @@ public abstract class TextChange extends TextEditBasedChange { session= ((IDocumentExtension4)document).startRewriteSession( DocumentRewriteSessionType.UNRESTRICTED); } - + LinkedModeModel.closeAllModels(document); TextEditProcessor processor= createTextEditProcessor(document, TextEdit.CREATE_UNDO, false); return processor.performEdits(); - + } finally { if (session != null) { ((IDocumentExtension4)document).stopRewriteSession(session); } } } - + //---- Method to access the current content of the text change --------- /** diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextFileChange.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextFileChange.java index b41a497908..4e2c5ed23b 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextFileChange.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/TextFileChange.java @@ -257,9 +257,9 @@ public class TextFileChange extends TextChange { if (! fBuffer.isSynchronizationContextRequested()) { return super.performEdits(document); } - + ITextFileBufferManager fileBufferManager= FileBuffers.getTextFileBufferManager(); - + /** The lock for waiting for computation in the UI thread to complete. */ final Lock completionLock= new Lock(); final UndoEdit[] result= new UndoEdit[1]; @@ -279,7 +279,7 @@ public class TextFileChange extends TextChange { } } }; - + synchronized (completionLock) { fileBufferManager.execute(runnable); while (! completionLock.fDone) { @@ -289,11 +289,11 @@ public class TextFileChange extends TextChange { } } } - + if (exception[0] != null) { throw exception[0]; } - + return result[0]; } diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/UndoTextFileChange.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/UndoTextFileChange.java index eacb44713a..028f0c643a 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/UndoTextFileChange.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/UndoTextFileChange.java @@ -218,9 +218,9 @@ public class UndoTextFileChange extends Change { if (! buffer.isSynchronizationContextRequested()) { return doPerformEdits(document, setContentStampSuccess); } - + ITextFileBufferManager fileBufferManager= FileBuffers.getTextFileBufferManager(); - + /** The lock for waiting for computation in the UI thread to complete. */ final Lock completionLock= new Lock(); final UndoEdit[] result= new UndoEdit[1]; @@ -246,7 +246,7 @@ public class UndoTextFileChange extends Change { } } }; - + synchronized (completionLock) { fileBufferManager.execute(runnable); while (! completionLock.fDone) { @@ -256,7 +256,7 @@ public class UndoTextFileChange extends Change { } } } - + if (badLocationException[0] != null) { throw badLocationException[0]; } else if (malformedTreeException[0] != null) { diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/participants/DeleteArguments.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/participants/DeleteArguments.java index 0be4a29cba..4c8132435a 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/participants/DeleteArguments.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/participants/DeleteArguments.java @@ -29,26 +29,26 @@ public class DeleteArguments extends RefactoringArguments { private boolean fDeleteProjectContents; /** - * Creates a new delete arguments object (deleteProjectContents is <code>false</code>). + * Creates a new delete arguments object (deleteProjectContents is <code>false</code>). */ public DeleteArguments() { this(false); } - + /** * Creates a new delete arguments object. - * + * * @param deleteProjectContents <code>true</code> if project contents will be deleted * @since 3.6 */ public DeleteArguments(boolean deleteProjectContents) { fDeleteProjectContents= deleteProjectContents; } - + /** * Returns whether project contents will be deleted as well. This method is not applicable for * file and folder deletions. - * + * * @return <code>true</code> if the refactoring will delete the project contents, * <code>false</code> if it only removes the reference from the workspace * @since 3.6 diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/participants/RenameArguments.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/participants/RenameArguments.java index f24490d1e5..4b5fd92d78 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/participants/RenameArguments.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/participants/RenameArguments.java @@ -22,7 +22,7 @@ import org.eclipse.core.runtime.Assert; * This class may be subclassed by refactoring processors wishing to provide special * rename arguments for special participants. * </p> - * + * * @since 3.0 */ public class RenameArguments extends RefactoringArguments { diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/resource/DeleteResourceChange.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/resource/DeleteResourceChange.java index f8a502e813..6e49b4e189 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/resource/DeleteResourceChange.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/core/refactoring/resource/DeleteResourceChange.java @@ -100,7 +100,7 @@ public class DeleteResourceChange extends ResourceChange { String label= Messages.format( RefactoringCoreMessages.DeleteResourceChange_name, BasicElementLabels.getPathLabel(path, false)); - + if (path.segmentCount() == 1) { IResource resource= getResource(); if (resource != null) { diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/BasicElementLabels.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/BasicElementLabels.java index 5dcd534cd0..a2e5b1bdd9 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/BasicElementLabels.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/BasicElementLabels.java @@ -32,7 +32,7 @@ public class BasicElementLabels { * User-readable string for separating post qualified names (e.g. " - "). */ public final static String CONCAT_STRING= RefactoringCoreMessages.BasicElementLabels_concat_string; - + private BasicElementLabels(){} /** diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/Lock.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/Lock.java index f6d4c81434..66e890d4dd 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/Lock.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/Lock.java @@ -15,7 +15,7 @@ package org.eclipse.ltk.internal.core.refactoring; /** * A simple lock object with a <em>done</em> flag. - * + * * @since 3.5 */ public class Lock { diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoDocumentChange.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoDocumentChange.java index 7ff9d31bcd..adc6441188 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoDocumentChange.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/UndoDocumentChange.java @@ -84,12 +84,12 @@ public class UndoDocumentChange extends Change { private UndoEdit performEdits() throws BadLocationException, MalformedTreeException { ITextFileBufferManager fileBufferManager= FileBuffers.getTextFileBufferManager(); - + ITextFileBuffer fileBuffer= fileBufferManager.getTextFileBuffer(fDocument); if (fileBuffer == null || ! fileBuffer.isSynchronizationContextRequested()) { return fUndo.apply(fDocument, TextEdit.CREATE_UNDO); } - + /** The lock for waiting for computation in the UI thread to complete. */ final Lock completionLock= new Lock(); final UndoEdit[] result= new UndoEdit[1]; @@ -109,7 +109,7 @@ public class UndoDocumentChange extends Change { } } }; - + synchronized (completionLock) { fileBufferManager.execute(runnable); while (! completionLock.fDone) { @@ -119,11 +119,11 @@ public class UndoDocumentChange extends Change { } } } - + if (exception[0] != null) { throw exception[0]; } - + return result[0]; } diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/DeleteResourcesProcessor.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/DeleteResourcesProcessor.java index 3c75a32eff..f757a2a759 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/DeleteResourcesProcessor.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/DeleteResourcesProcessor.java @@ -114,7 +114,7 @@ public class DeleteResourcesProcessor extends DeleteProcessor { if (!(Resources.containsOnlyProjects(fResources) || Resources.containsOnlyNonProjects(fResources))) { return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.DeleteResourcesProcessor_delete_error_mixed_types); } - + return new RefactoringStatus(); } @@ -127,7 +127,7 @@ public class DeleteResourcesProcessor extends DeleteProcessor { for (IResource resource : fResources) { if (!isSynchronizedExcludingLinkedResources(resource)) { String pathLabel= BasicElementLabels.getPathLabel(resource.getFullPath(), false); - + String locationLabel= null; IPath location= resource.getLocation(); if (location != null) { @@ -158,7 +158,7 @@ public class DeleteResourcesProcessor extends DeleteProcessor { } checkDirtyResources(result); - + ResourceChangeChecker checker= context.getChecker(ResourceChangeChecker.class); IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory(); for (IResource fResource : fResources) { @@ -179,7 +179,7 @@ public class DeleteResourcesProcessor extends DeleteProcessor { /** * Checks whether this resource and its descendents are considered to be in sync with the local * file system. The linked resources and their descendents are excluded from the check. - * + * * @param resource the resource to check * @return <code>true</code> if this resource and its descendents except linked resources are * synchronized, and <code>false</code> in all other cases diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/undostates/AbstractResourceUndoState.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/undostates/AbstractResourceUndoState.java index d633afd8b2..a7a02008c3 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/undostates/AbstractResourceUndoState.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/undostates/AbstractResourceUndoState.java @@ -99,7 +99,7 @@ abstract class AbstractResourceUndoState extends ResourceUndoState { /** * Restore any saved attributed of the specified resource. This method is called after the * existent resource represented by the receiver has been created. - * + * * @param resource the newly created resource * @throws CoreException if accessing the resource fails */ diff --git a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/undostates/ProjectUndoState.java b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/undostates/ProjectUndoState.java index 8a6a605b84..de662689e8 100644 --- a/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/undostates/ProjectUndoState.java +++ b/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/resource/undostates/ProjectUndoState.java @@ -107,8 +107,8 @@ public class ProjectUndoState extends ContainerUndoState { } monitor.done(); } - - + + @Override public String getName() { diff --git a/org.eclipse.ltk.ui.refactoring.tests/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.ltk.ui.refactoring.tests/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.ltk.ui.refactoring.tests/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.ltk.ui.refactoring.tests/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.ltk.ui.refactoring/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.ltk.ui.refactoring/.settings/org.eclipse.jdt.ui.prefs index b73bfac6f0..8343741ba2 100644 --- a/org.eclipse.ltk.ui.refactoring/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.ltk.ui.refactoring/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JDT UI Code Style Conventions formatter_settings_version=12 org.eclipse.jdt.ui.exception.name=e @@ -9,3 +10,69 @@ org.eclipse.jdt.ui.keywordthis=false org.eclipse.jdt.ui.ondemandthreshold=99 org.eclipse.jdt.ui.overrideannotation=true org.eclipse.jdt.ui.staticondemandthreshold=99 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +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=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +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.number_suffix=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.push_down_negation=false +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_modifiers=false +sp_cleanup.remove_redundant_semicolons=false +sp_cleanup.remove_redundant_type_arguments=false +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_array_creation=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +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.simplify_lambda_expression_and_method_ref=false +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_autoboxing=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_directly_map_method=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 +sp_cleanup.use_unboxing=false diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/PreviewWizardPage.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/PreviewWizardPage.java index 05c7b08eb5..5a1b157d47 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/PreviewWizardPage.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/PreviewWizardPage.java @@ -457,7 +457,7 @@ public class PreviewWizardPage extends RefactoringWizardPage implements IPreview tbm.update(true); final ToolBar toolBar= tbm.getControl(); - + // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=375354 : toolBar.getAccessible().addAccessibleListener(new AccessibleAdapter() { /* diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringStatusDialog.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringStatusDialog.java index 886f083d8f..1cf24579ed 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringStatusDialog.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringStatusDialog.java @@ -71,7 +71,7 @@ public class RefactoringStatusDialog extends Dialog { super.configureShell(newShell); newShell.setText(fWindowTitle); } - + @Override protected int getDialogBoundsStrategy() { return DIALOG_PERSISTSIZE; @@ -82,7 +82,7 @@ public class RefactoringStatusDialog extends Dialog { IDialogSettings settings= RefactoringUIPlugin.getDefault().getDialogSettings(); return DialogSettings.getOrCreateSection(settings, "RefactoringStatusDialog"); //$NON-NLS-1$ } - + @Override protected Control createDialogArea(Composite parent) { Composite result= (Composite) super.createDialogArea(parent); diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringWizardDialog2.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringWizardDialog2.java index cb246dc174..f192b6a542 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringWizardDialog2.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/RefactoringWizardDialog2.java @@ -239,16 +239,16 @@ public class RefactoringWizardDialog2 extends TrayDialog implements IWizardConta boolean previewPage= isPreviewPageActive(); boolean ok= fWizard.canFinish(); boolean canFlip= fCurrentPage.canFlipToNextPage(); - + Button defaultButton= null; - + Button previewButton= getButton(PREVIEW_ID); if (previewButton != null && !previewButton.isDisposed()) { String previewLabel= previewPage ? IDialogConstants.BACK_LABEL : RefactoringUIMessages.RefactoringWizardDialog2_buttons_preview_label; previewButton.setText(previewLabel); setButtonLayoutData(previewButton); getShell().layout(new Control[] { previewButton }); - + boolean enable= true; if (!previewPage) enable= canFlip; @@ -256,7 +256,7 @@ public class RefactoringWizardDialog2 extends TrayDialog implements IWizardConta if (enable) defaultButton= previewButton; } - + Button nextButton= getButton(IDialogConstants.NEXT_ID); if (nextButton != null && !nextButton.isDisposed()) { nextButton.setEnabled(!previewPage); @@ -265,18 +265,18 @@ public class RefactoringWizardDialog2 extends TrayDialog implements IWizardConta if (nextButton.isEnabled()) defaultButton= nextButton; } - + Button backButton= getButton(IDialogConstants.BACK_ID); if (backButton != null && !backButton.isDisposed()) backButton.setEnabled(!isFirstPage()); - + Button okButton= getButton(IDialogConstants.OK_ID); if (okButton != null && !okButton.isDisposed()) { okButton.setEnabled(ok); if (ok) defaultButton= okButton; } - + if (defaultButton != null) { defaultButton.getShell().setDefaultButton(defaultButton); } @@ -746,7 +746,7 @@ public class RefactoringWizardDialog2 extends TrayDialog implements IWizardConta return composite; } - + /* * @see org.eclipse.jface.dialogs.Dialog#setButtonLayoutData(org.eclipse.swt.widgets.Button) * @since 3.5 diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/UIPerformChangeOperation.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/UIPerformChangeOperation.java index 4884bc1e6e..6366bf00d6 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/UIPerformChangeOperation.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/UIPerformChangeOperation.java @@ -54,7 +54,7 @@ public class UIPerformChangeOperation extends PerformChangeOperation { final Throwable[] exception= new Throwable[1]; /** Cancel button to re-enable, or <code>null</code> to do nothing. */ final Button[] cancelToEnable= new Button[1]; - + final ISafeRunnable safeRunnable= new ISafeRunnable() { @Override public void run() { diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/actions/RenameResourceHandler.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/actions/RenameResourceHandler.java index 804b76ed76..668a7860d2 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/actions/RenameResourceHandler.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/actions/RenameResourceHandler.java @@ -65,8 +65,8 @@ public class RenameResourceHandler extends AbstractResourcesHandler { IResource resource= getCurrentResource((IStructuredSelection) sel); if (resource != null) { // A new name is required in order to compute whether the change is composite or not - String placeHolderNewName= resource.getName() + "a"; //$NON-NLS-1$ - RenameResourceWizard refactoringWizard= new RenameResourceWizard(resource, placeHolderNewName); + String placeHolderFileName = 'a' + resource.getName(); + RenameResourceWizard refactoringWizard= new RenameResourceWizard(resource, placeHolderFileName); Change change= getChange(refactoringWizard); return isCompositeChange(change); } diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/history/RefactoringHistoryProject.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/history/RefactoringHistoryProject.java index 1a305e5caf..0266aac333 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/history/RefactoringHistoryProject.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/history/RefactoringHistoryProject.java @@ -27,7 +27,7 @@ public final class RefactoringHistoryProject extends RefactoringHistoryNode { /** * Creates a new refactoring history project. - * + * * @param project the project */ public RefactoringHistoryProject(final String project) { diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/model/RefactoringDescriptorViewer.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/model/RefactoringDescriptorViewer.java index e4513196ff..cead52014d 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/model/RefactoringDescriptorViewer.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/model/RefactoringDescriptorViewer.java @@ -56,7 +56,7 @@ public class RefactoringDescriptorViewer extends Viewer { Assert.isNotNull(parent); fBrowser= new Browser(parent, style); fBrowser.setJavascriptEnabled(false); - + final Display display= parent.getDisplay(); fBrowser.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); fBrowser.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/util/SWTUtil.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/util/SWTUtil.java index f7ee839041..95b990b127 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/util/SWTUtil.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/util/SWTUtil.java @@ -54,7 +54,7 @@ public final class SWTUtil { * * @param control the control to add the accessibility support to * @param text the name - * + * * @since 3.5.100 */ public static void setAccessibilityText(Control control, final String text) { @@ -67,7 +67,7 @@ public final class SWTUtil { } }); } - + private SWTUtil() { // Not for instantiation } diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/util/Strings.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/util/Strings.java index c3e90855d7..a583c403f9 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/util/Strings.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/internal/ui/refactoring/util/Strings.java @@ -16,7 +16,7 @@ package org.eclipse.ltk.internal.ui.refactoring.util; /** * Utility class for string-related functions. - * + * * @since 3.0 */ public final class Strings { diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizard.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizard.java index b2f939a5a0..36ab4d00fc 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizard.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizard.java @@ -149,13 +149,13 @@ public abstract class RefactoringWizard extends Wizard { * Flag (value 128) indicating that a help control should be shown. * The flag is ignored if the flag {@link #WIZARD_BASED_USER_INTERFACE} * is specified (the '?' button is always shown there). - * + * * @see org.eclipse.jface.dialogs.TrayDialog#setHelpAvailable(boolean) - * + * * @since 3.6 */ public static final int SHOW_HELP_CONTROL= 1 << 7; - + private static final int LAST= 1 << 8; private final int fFlags; @@ -189,7 +189,7 @@ public abstract class RefactoringWizard extends Wizard { this(null, refactoring, flags); Assert.isNotNull(refactoring); } - + /** * Creates a new refactoring wizard for the given refactoring context. * @@ -204,7 +204,7 @@ public abstract class RefactoringWizard extends Wizard { this(refactoringContext, null, flags); Assert.isNotNull(refactoringContext); } - + private RefactoringWizard(RefactoringContext refactoringContext, Refactoring refactoring, int flags) { Assert.isTrue(flags < LAST); if ((flags & DIALOG_BASED_USER_INTERFACE) == 0) @@ -239,19 +239,19 @@ public abstract class RefactoringWizard extends Wizard { public final RefactoringContext getRefactoringContext() { return fRefactoringContext; } - + /** * Returns the refactoring wizard flags that have been set for this wizard. * Note that the set of valid flags may grow in the future. * * @return the wizard's flags - * + * * @since 3.6 */ public final int getWizardFlags(){ return fFlags; } - + /** * Sets the default page title to the given value. This value is used * as a page title for wizard pages which don't provide their own @@ -348,7 +348,7 @@ public abstract class RefactoringWizard extends Wizard { public final Change getChange() { return fChange; } - + /** * @param b {@inheritDoc} * @deprecated {@link #WIZARD_BASED_USER_INTERFACE} always shows a '?' button. @@ -480,9 +480,9 @@ public abstract class RefactoringWizard extends Wizard { * Sets the runnable context that will be used to computing refactoring conditions and change * while the refactoring dialog is not yet shown. The default is to use the active workbench * window. - * + * * @param context a runnable context, or <code>null</code> to re-set the default - * + * * @since 3.5 */ public void setInitialComputationContext(IRunnableContext context) { diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizardOpenOperation.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizardOpenOperation.java index 18830cc881..cd65fc147d 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizardOpenOperation.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/RefactoringWizardOpenOperation.java @@ -125,7 +125,7 @@ public class RefactoringWizardOpenOperation { public int run(final Shell parent, final String dialogTitle) throws InterruptedException { return run(parent, dialogTitle, null); } - + /** * Opens the refactoring dialog for the refactoring wizard passed to the constructor. * The method first checks the initial conditions of the refactoring. If the condition @@ -146,7 +146,7 @@ public class RefactoringWizardOpenOperation { * condition check (if any) * @param context the runnable context to use for conditions checking before the * refactoring wizard dialog is visible. If <code>null</code>, the workbench window's - * progress service is used. + * progress service is used. * * @return {@link #INITIAL_CONDITION_CHECKING_FAILED} if the initial condition checking * failed and no wizard dialog was presented. Otherwise either {@link IDialogConstants#OK_ID} @@ -155,7 +155,7 @@ public class RefactoringWizardOpenOperation { * * @throws InterruptedException if the initial condition checking got canceled by * the user. - * + * * @since 3.5 */ public int run(final Shell parent, final String dialogTitle, final IRunnableContext context) throws InterruptedException { diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/history/IRefactoringHistoryControl.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/history/IRefactoringHistoryControl.java index c7d1690b5b..b08c2cf964 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/history/IRefactoringHistoryControl.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/history/IRefactoringHistoryControl.java @@ -37,13 +37,13 @@ import org.eclipse.ltk.ui.refactoring.RefactoringUI; * <p> * Note: this interface is not intended to be implemented by clients. * </p> - * + * * @see RefactoringHistoryControlConfiguration * @see RefactoringHistoryContentProvider * @see RefactoringHistoryLabelProvider - * + * * @since 3.2 - * + * * @noimplement This interface is not intended to be implemented by clients. * @noextend This interface is not intended to be extended by clients. */ diff --git a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/history/RefactoringHistoryWizard.java b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/history/RefactoringHistoryWizard.java index 7a952dfcfe..890cf80c92 100644 --- a/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/history/RefactoringHistoryWizard.java +++ b/org.eclipse.ltk.ui.refactoring/src/org/eclipse/ltk/ui/refactoring/history/RefactoringHistoryWizard.java @@ -873,7 +873,7 @@ public class RefactoringHistoryWizard extends Wizard { } else { final Change change= createChange(refactoring, new SubProgressMonitor(monitor, 5, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)); getShell().getDisplay().syncExec(new Runnable() { - + @Override public final void run() { fPreviewPage.setChange(change); |
