Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 237707 Details for
Bug 394724
[inline] Inline local variable does not add throws clause in the resulting method in anonymous class
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix and Test
Bug 394724.patch (text/plain), 7.22 KB, created by
Samrat Dhillon
on 2013-11-25 20:51:11 EST
(
hide
)
Description:
Fix and Test
Filename:
MIME Type:
Creator:
Samrat Dhillon
Created:
2013-11-25 20:51:11 EST
Size:
7.22 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test49_in.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test49_in.java >new file mode 100644 >index 0000000..f8ecc4b >--- /dev/null >+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test49_in.java >@@ -0,0 +1,15 @@ >+package p; >+class A { >+ void f() throws Exception { >+ final int m = g(); >+ >+ new Object() { >+ void f() { >+ int n = m; >+ } >+ }; >+ } >+ int g() throws Exception { >+ return 0; >+ } >+} >\ No newline at end of file >diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test49_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test49_out.java >new file mode 100644 >index 0000000..1d77379 >--- /dev/null >+++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test49_out.java >@@ -0,0 +1,13 @@ >+package p; >+class A { >+ void f() throws Exception { >+ new Object() { >+ void f() throws Exception { >+ int n = g(); >+ } >+ }; >+ } >+ int g() throws Exception { >+ return 0; >+ } >+} >\ No newline at end of file >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 706167e..5e595b9 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, 2012 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 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 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Samrat Dhillon <samrat.dhillon@gmail.com> - [inline] Inline local variable does not add throws clause in the resulting method in anonymous class - https://bugs.eclipse.org/394724 > *******************************************************************************/ > package org.eclipse.jdt.ui.tests.refactoring; > >@@ -339,6 +340,11 @@ > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=388078 > helper1(6, 16, 6, 18); > } >+ >+ public void test49() throws Exception { >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=394724 >+ helper1(4, 9, 4, 27); >+ } > > //------ > >diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java >index 4778202..cc5921b 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/InlineTempRefactoring.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2012 IBM Corporation and others. >+ * Copyright (c) 2000, 2013 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 >@@ -7,10 +7,12 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Samrat Dhillon <samrat.dhillon@gmail.com> - [inline] Inline local variable does not add throws clause in the resulting method in anonymous class - https://bugs.eclipse.org/394724 > *******************************************************************************/ > package org.eclipse.jdt.internal.corext.refactoring.code; > > import java.util.HashMap; >+import java.util.Iterator; > import java.util.Map; > import java.util.StringTokenizer; > >@@ -61,6 +63,7 @@ > import org.eclipse.jdt.core.dom.MethodDeclaration; > 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.ParenthesizedExpression; > import org.eclipse.jdt.core.dom.SimpleName; > import org.eclipse.jdt.core.dom.SingleVariableDeclaration; >@@ -79,6 +82,7 @@ > import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory; > 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.NecessaryParenthesesChecker; > import org.eclipse.jdt.internal.corext.refactoring.Checks; > import org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment; >@@ -354,12 +358,41 @@ > } > return copy; > } >+ >+ private void addExceptionToNodeList(String fullyQualified, ListRewrite exceptionListRewrite, CompilationUnitRewrite rewrite) { >+ for (Iterator<? extends ASTNode> iter= exceptionListRewrite.getOriginalList().iterator(); iter.hasNext(); ) { >+ Name exName= (Name) iter.next(); >+ ITypeBinding typeBinding= exName.resolveTypeBinding(); >+ if (typeBinding == null) >+ continue; // newly added or unresolvable type >+ if (typeBinding.getQualifiedName().equals(fullyQualified)) >+ return; // don't add it again >+ } >+ String importedType= rewrite.getImportRewrite().addImport(fullyQualified); >+ rewrite.getImportRemover().registerAddedImport(importedType); >+ ASTNode exNode= rewrite.getASTRewrite().createStringPlaceholder(importedType, ASTNode.SIMPLE_NAME); >+ exceptionListRewrite.insertLast(exNode, rewrite.createGroupDescription(RefactoringCoreMessages.InlineTempRefactoring_inline_edit_name)); >+ } >+ > > private Expression getModifiedInitializerSource(CompilationUnitRewrite rewrite, SimpleName reference) throws JavaModelException { > VariableDeclaration varDecl= getVariableDeclaration(); > Expression initializer= varDecl.getInitializer(); > > ASTNode referenceContext= reference.getParent(); >+ >+ if(initializer instanceof MethodInvocation){ >+ MethodInvocation mi= (MethodInvocation) initializer; >+ ITypeBinding[] exceptionTypes= mi.resolveMethodBinding().getExceptionTypes(); >+ MethodDeclaration methodDeclaration= (MethodDeclaration) ASTNodes.getParent(reference, ASTNode.METHOD_DECLARATION); >+ for(ITypeBinding binding: exceptionTypes){ >+ if(!Bindings.isRuntimeException(binding)){ >+ addExceptionToNodeList(binding.getQualifiedName(), rewrite.getASTRewrite().getListRewrite(methodDeclaration, MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY), rewrite); >+ } >+ >+ } >+ } >+ > if (Invocations.isResolvedTypeInferredFromExpectedType(initializer)) { > if (! (referenceContext instanceof VariableDeclarationFragment > || referenceContext instanceof SingleVariableDeclaration
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 394724
: 237707