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 221222 Details for
Bug 388724
[surround with try/catch][quick fix] Multi-Catch QuickFix creates compiler error
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]
patch for this bug
Bug 388724.patch (text/plain), 4.57 KB, created by
Samrat Dhillon
on 2012-09-18 18:49:18 EDT
(
hide
)
Description:
patch for this bug
Filename:
MIME Type:
Creator:
Samrat Dhillon
Created:
2012-09-18 18:49:18 EDT
Size:
4.57 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java >index 617690d..4809f10 100644 >--- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java >+++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/surround/SurroundWithTryCatchRefactoring.java >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Samrat Dhillon samrat.dhillon@gmail.com - Bug 388724 - [surround with try/catch][quick fix] Multi-Catch QuickFix creates compiler error > *******************************************************************************/ > package org.eclipse.jdt.internal.corext.refactoring.surround; > >@@ -235,7 +236,8 @@ > TryStatement tryStatement= getAST().newTryStatement(); > ITypeBinding[] exceptions= fAnalyzer.getExceptions(); > ImportRewriteContext context= new ContextSensitiveImportRewriteContext(fAnalyzer.getEnclosingBodyDeclaration(), fImportRewrite); >- >+ ITypeBinding[] superExceptions = getSuperExceptionSet(exceptions); >+ > if (!fIsMultiCatch) { > for (int i= 0; i < exceptions.length; i++) { > ITypeBinding exception= exceptions[i]; >@@ -265,11 +267,14 @@ > > UnionType unionType= getAST().newUnionType(); > List<Type> types= unionType.types(); >- for (int i= 0; i < exceptions.length; i++) { >- ITypeBinding exception= exceptions[i]; >- Type type= fImportRewrite.addImport(exception, getAST(), context); >- types.add(type); >- fLinkedProposalModel.getPositionGroup(GROUP_EXC_TYPE + i, true).addPosition(fRewriter.track(type), i == 0); >+ int i=0; >+ for (ITypeBinding exception:superExceptions) { >+ if(exception!=null){ >+ Type type= fImportRewrite.addImport(exception, getAST(), context); >+ types.add(type); >+ fLinkedProposalModel.getPositionGroup(GROUP_EXC_TYPE + i, true).addPosition(fRewriter.track(type), i == 0); >+ i++; >+ } > } > > decl.setType(unionType); >@@ -373,6 +378,57 @@ > statements.insertLast(toMove, null); > } > } >+ /* >+ * Get the subset of exceptions from a list, that are not subclass of any other other class in the same list >+ */ >+ private ITypeBinding[] getSuperExceptionSet(ITypeBinding[] exceptions) { >+ //initialize the array to size of given exception array. That is the maximum size possible. >+ ITypeBinding[] superExceptions = new ITypeBinding[exceptions.length]; >+ int currentIndex=0; >+ for(int i =0;i<exceptions.length;i++){ >+ currentIndex=addToSuperException(superExceptions, exceptions[i], currentIndex); >+ } >+ return superExceptions; >+ } >+ private int addToSuperException(ITypeBinding[] superExceptions,ITypeBinding exception, int currentIndex) { >+ boolean superTypeAlreadyPresent=false; >+ boolean addingSuperType=false; >+ for(int i=0;i<superExceptions.length;i++){ >+ //check if the super class of the exception that we want to add in the array, is already present. If super class is present dont add anything. >+ if(superExceptions[i]!=null && exception.isSubTypeCompatible(superExceptions[i])){ >+ superTypeAlreadyPresent=true; >+ break; >+ } >+ //if exception we are adding now is the super class of the exception already added, then replace the existing exception with super class >+ if(superExceptions[i]!=null && superExceptions[i].isSubTypeCompatible(exception)){ >+ addingSuperType=true; >+ superExceptions[i]=exception; >+ //normalize will remove duplicate if we added the same class twice >+ normalize(superExceptions,exception); >+ } >+ } >+ //if super class was not present or if we were not adding super type, then add the new exception >+ if(!superTypeAlreadyPresent && !addingSuperType){ >+ superExceptions[currentIndex] = exception; >+ currentIndex++; >+ } >+ return currentIndex; >+ } >+ //Remove duplicates from the list of exceptions >+ private void normalize(ITypeBinding[] superExceptions,ITypeBinding exception) { >+ boolean firstInstanceFound=false; >+ for(int i=0;i<superExceptions.length;i++){ >+ if(superExceptions[i]!=null){ >+ if(superExceptions[i].getQualifiedName().equals(exception.getQualifiedName())){ >+ if(!firstInstanceFound){ >+ firstInstanceFound=true; >+ }else{ >+ superExceptions[i]=null; >+ } >+ } >+ } >+ } >+ } > > private List<ASTNode> getSpecialVariableDeclarationStatements() { > List<ASTNode> result= new ArrayList<ASTNode>(3);
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 388724
: 221222 |
236463
|
256663