### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.ui Index: ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java,v retrieving revision 1.123 diff -u -r1.123 PreferencesMessages.java --- ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java 17 Nov 2009 07:50:05 -0000 1.123 +++ ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java 13 Jan 2010 19:36:51 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -417,6 +417,7 @@ public static String ProblemSeveritiesConfigurationBlock_pb_annotation_super_interface_label; public static String ProblemSeveritiesConfigurationBlock_pb_type_parameter_hiding_label; public static String ProblemSeveritiesConfigurationBlock_pb_unused_label_label; + public static String ProblemSeveritiesConfigurationBlock_pb_unused_object_allocation_label; public static String JavadocProblemsPreferencePage_title; public static String JavadocProblemsConfigurationBlock_allStandardTags; public static String JavadocProblemsConfigurationBlock_public; Index: ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties,v retrieving revision 1.497 diff -u -r1.497 PreferencesMessages.properties --- ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties 7 Dec 2009 11:10:50 -0000 1.497 +++ ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties 13 Jan 2010 19:36:51 -0000 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2009 IBM Corporation and others. +# Copyright (c) 2000, 2010 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 @@ -453,6 +453,7 @@ ProblemSeveritiesConfigurationBlock_ignore_documented_unused_parameters=Ignore parameters documented with '@param' tag ProblemSeveritiesConfigurationBlock_pb_type_parameter_hiding_label=Type parameter hides another type: ProblemSeveritiesConfigurationBlock_pb_unused_label_label=Unused 'break' or 'continue' label: +ProblemSeveritiesConfigurationBlock_pb_unused_object_allocation_label=Unused object allocation: ProblemSeveritiesConfigurationBlock_unused_suppresswarnings_token=Unused '@SuppressWarnings' token: JavadocProblemsPreferencePage_title=Javadoc Comments Index: ui/org/eclipse/jdt/internal/ui/preferences/ProblemSeveritiesConfigurationBlock.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/ProblemSeveritiesConfigurationBlock.java,v retrieving revision 1.56 diff -u -r1.56 ProblemSeveritiesConfigurationBlock.java --- ui/org/eclipse/jdt/internal/ui/preferences/ProblemSeveritiesConfigurationBlock.java 23 Sep 2009 08:54:18 -0000 1.56 +++ ui/org/eclipse/jdt/internal/ui/preferences/ProblemSeveritiesConfigurationBlock.java 13 Jan 2010 19:36:51 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -108,6 +108,7 @@ private static final Key PREF_PB_MISSING_HASHCODE_METHOD= getJDTCoreKey(JavaCore.COMPILER_PB_MISSING_HASHCODE_METHOD); private static final Key PREF_PB_DEAD_CODE= getJDTCoreKey(JavaCore.COMPILER_PB_DEAD_CODE); + private static final Key PREF_PB_UNUSED_OBJECT_ALLOCATION= getJDTCoreKey(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION); // values @@ -157,7 +158,7 @@ PREF_15_PB_RAW_TYPE_REFERENCE, PREF_PB_FATAL_OPTIONAL_ERROR, PREF_PB_FORBIDDEN_REFERENCE, PREF_PB_DISCOURRAGED_REFERENCE, PREF_PB_SUPPRESS_WARNINGS, PREF_PB_UNHANDLED_WARNING_TOKEN, PREF_PB_COMPARING_IDENTICAL, PREF_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD, PREF_PB_MISSING_HASHCODE_METHOD, - PREF_PB_DEAD_CODE + PREF_PB_DEAD_CODE, PREF_PB_UNUSED_OBJECT_ALLOCATION }; } @@ -315,6 +316,9 @@ label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_dead_code; addComboBox(inner, label, PREF_PB_DEAD_CODE, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent); + label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_pb_unused_object_allocation_label; + addComboBox(inner, label, PREF_PB_UNUSED_OBJECT_ALLOCATION, errorWarningIgnore, errorWarningIgnoreLabels, defaultIndent); + // --- name_shadowing label= PreferencesMessages.ProblemSeveritiesConfigurationBlock_section_name_shadowing; Index: ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java,v retrieving revision 1.86 diff -u -r1.86 CorrectionMessages.java --- ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java 17 Nov 2009 07:38:23 -0000 1.86 +++ ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java 13 Jan 2010 19:36:51 -0000 @@ -337,7 +337,9 @@ public static String ReorgCorrectionsSubProcessor_project_seup_fix_description; public static String ReorgCorrectionsSubProcessor_project_seup_fix_info; public static String UnresolvedElementsSubProcessor_change_full_type_description; + public static String LocalCorrectionsSubProcessor_remove_allocated_description; public static String LocalCorrectionsSubProcessor_remove_redundant_superinterface; + public static String LocalCorrectionsSubProcessor_return_allocated_description; public static String LocalCorrectionsSubProcessor_qualify_left_hand_side_description; public static String LocalCorrectionsSubProcessor_LocalCorrectionsSubProcessor_qualify_right_hand_side_description; public static String UnresolvedElementsSubProcessor_UnresolvedElementsSubProcessor_changetoattribute_description; @@ -350,6 +352,7 @@ public static String LocalCorrectionsSubProcessor_insert_break_statement; public static String LocalCorrectionsSubProcessor_insert_fall_through; public static String LocalCorrectionsSubProcessor_override_hashCode_description; + public static String LocalCorrectionsSubProcessor_throw_allocated_description; public static String SuppressWarningsSubProcessor_fix_suppress_token_label; public static String SuppressWarningsSubProcessor_remove_annotation_label; } Index: ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties,v retrieving revision 1.262 diff -u -r1.262 CorrectionMessages.properties --- ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties 17 Nov 2009 07:38:23 -0000 1.262 +++ ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties 13 Jan 2010 19:36:51 -0000 @@ -87,6 +87,7 @@ LocalCorrectionsSubProcessor_generate_hashCode_equals_description=Generate hashCode() and equals()... LocalCorrectionsSubProcessor_uninitializedvariable_description=Initialize variable LocalCorrectionsSubProcessor_removesemicolon_description=Remove semicolon +LocalCorrectionsSubProcessor_remove_allocated_description=Remove LocalCorrectionsSubProcessor_remove_redundant_superinterface=Remove super interface LocalCorrectionsSubProcessor_renaming_duplicate_method=Rename method ''{0}'' LocalCorrectionsSubProcessor_removeunreachablecode_description=Remove @@ -106,6 +107,8 @@ LocalCorrectionsSubProcessor_setparenteses_instanceof_description=Put 'instanceof' in parentheses LocalCorrectionsSubProcessor_qualify_left_hand_side_description=Qualify left hand side LocalCorrectionsSubProcessor_replacefieldaccesswithmethod_description=Replace with ''{0}'' +LocalCorrectionsSubProcessor_return_allocated_description=Return the allocated object +LocalCorrectionsSubProcessor_throw_allocated_description=Throw the allocated object TypeMismatchSubProcessor_addcast_description=Add cast to ''{0}'' TypeMismatchSubProcessor_changecast_description=Change cast to ''{0}'' TypeMismatchSubProcessor_changereturntype_description=Change method return type to ''{0}'' Index: ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java,v retrieving revision 1.220 diff -u -r1.220 LocalCorrectionsSubProcessor.java --- ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java 19 Feb 2009 14:53:11 -0000 1.220 +++ ui/org/eclipse/jdt/internal/ui/text/correction/LocalCorrectionsSubProcessor.java 13 Jan 2010 19:36:51 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -75,12 +75,14 @@ import org.eclipse.jdt.core.dom.Name; import org.eclipse.jdt.core.dom.ParenthesizedExpression; import org.eclipse.jdt.core.dom.PrefixExpression; +import org.eclipse.jdt.core.dom.ReturnStatement; 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.StructuralPropertyDescriptor; import org.eclipse.jdt.core.dom.SwitchCase; import org.eclipse.jdt.core.dom.SwitchStatement; +import org.eclipse.jdt.core.dom.ThrowStatement; import org.eclipse.jdt.core.dom.TryStatement; import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeDeclaration; @@ -111,6 +113,7 @@ import org.eclipse.jdt.internal.corext.refactoring.surround.ExceptionAnalyzer; import org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoring; import org.eclipse.jdt.internal.corext.refactoring.util.NoCommentSourceRangeComputer; +import org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer; import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.internal.corext.util.Messages; @@ -992,6 +995,67 @@ proposals.add(proposal); } + public static void getUnusedObjectAllocationProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) { + CompilationUnit root= context.getASTRoot(); + AST ast= root.getAST(); + ASTNode selectedNode= problem.getCoveringNode(root); + if (selectedNode == null) { + return; + } + + ASTNode parent= selectedNode.getParent(); + + if (parent instanceof ExpressionStatement) { + ExpressionStatement expressionStatement= (ExpressionStatement) parent; + Expression expr= expressionStatement.getExpression(); + ITypeBinding exprType= expr.resolveTypeBinding(); + + if (exprType != null && Bindings.isSuperType(ast.resolveWellKnownType("java.lang.Throwable"), exprType)) { //$NON-NLS-1$ + ASTRewrite rewrite= ASTRewrite.create(ast); + TightSourceRangeComputer sourceRangeComputer= new TightSourceRangeComputer(); + rewrite.setTargetSourceRangeComputer(sourceRangeComputer); + + ThrowStatement throwStatement= ast.newThrowStatement(); + throwStatement.setExpression((Expression) rewrite.createMoveTarget(expr)); + sourceRangeComputer.addTightSourceNode(expressionStatement); + rewrite.replace(expressionStatement, throwStatement, null); + + String label= CorrectionMessages.LocalCorrectionsSubProcessor_throw_allocated_description; + Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); + ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 8, image); + proposals.add(proposal); + } + + MethodDeclaration method= ASTResolving.findParentMethodDeclaration(selectedNode); + if (method != null) { + ASTRewrite rewrite= ASTRewrite.create(ast); + TightSourceRangeComputer sourceRangeComputer= new TightSourceRangeComputer(); + rewrite.setTargetSourceRangeComputer(sourceRangeComputer); + + ReturnStatement returnStatement= ast.newReturnStatement(); + returnStatement.setExpression((Expression) rewrite.createMoveTarget(expr)); + sourceRangeComputer.addTightSourceNode(expressionStatement); + rewrite.replace(expressionStatement, returnStatement, null); + + String label= CorrectionMessages.LocalCorrectionsSubProcessor_return_allocated_description; + Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); + ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 7, image); + proposals.add(proposal); + } + + { + ASTRewrite rewrite= ASTRewrite.create(ast); + rewrite.remove(parent, null); + + String label= CorrectionMessages.LocalCorrectionsSubProcessor_remove_allocated_description; + Image image= JavaPlugin.getDefault().getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE); + ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 2, image); + proposals.add(proposal); + } + + } + } + public static void getAssignmentHasNoEffectProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) { CompilationUnit root= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(root); Index: ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java,v retrieving revision 1.105 diff -u -r1.105 QuickFixProcessor.java --- ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java 24 Sep 2009 14:39:30 -0000 1.105 +++ ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java 13 Jan 2010 19:36:51 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -211,6 +211,7 @@ case IProblem.IncompatibleTypesInForeach: case IProblem.MissingEnumConstantCase: case IProblem.MissingSynchronizedModifierInInheritedMethod: + case IProblem.UnusedObjectAllocation: return true; default: return SuppressWarningsSubProcessor.hasSuppressWarningsProposal(cu.getJavaProject(), problemId); @@ -597,6 +598,9 @@ case IProblem.MissingSynchronizedModifierInInheritedMethod: ModifierCorrectionSubProcessor.addSynchronizedMethodProposal(context, problem, proposals); break; + case IProblem.UnusedObjectAllocation: + LocalCorrectionsSubProcessor.getUnusedObjectAllocationProposals(context, problem, proposals); + break; default: } if (JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {