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 197682 Details for
Bug 347839
[1.7][quick assist]Quick assists for base conversion
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
v0.5
baseconversion.txt (text/plain), 6.78 KB, created by
Deepak Azad
on 2011-06-09 07:21:27 EDT
(
hide
)
Description:
v0.5
Filename:
MIME Type:
Creator:
Deepak Azad
Created:
2011-06-09 07:21:27 EDT
Size:
6.78 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.ui >Index: ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java,v >retrieving revision 1.80.2.3 >diff -u -r1.80.2.3 AdvancedQuickAssistProcessor.java >--- ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java 9 Jun 2011 08:34:16 -0000 1.80.2.3 >+++ ui/org/eclipse/jdt/internal/ui/text/correction/AdvancedQuickAssistProcessor.java 9 Jun 2011 11:12:05 -0000 >@@ -60,6 +60,7 @@ > import org.eclipse.jdt.core.dom.MethodDeclaration; > import org.eclipse.jdt.core.dom.MethodInvocation; > import org.eclipse.jdt.core.dom.Name; >+import org.eclipse.jdt.core.dom.NumberLiteral; > import org.eclipse.jdt.core.dom.ParenthesizedExpression; > import org.eclipse.jdt.core.dom.PrefixExpression; > import org.eclipse.jdt.core.dom.PrimitiveType; >@@ -147,6 +148,7 @@ > || getPullNegationUpProposals(context, coveredNodes, null) > || getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, null) > || getConvertSwitchToIfProposals(context, coveringNode, null) >+ || getConvertBaseProposals(context, coveringNode, null) > || GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, null, null); > } > return false; >@@ -185,6 +187,7 @@ > getPullNegationUpProposals(context, coveredNodes, resultingCollections); > getJoinIfListInIfElseIfProposals(context, coveringNode, coveredNodes, resultingCollections); > getConvertSwitchToIfProposals(context, coveringNode, resultingCollections); >+ getConvertBaseProposals(context, coveringNode, resultingCollections); > GetterSetterCorrectionSubProcessor.addGetterSetterProposal(context, coveringNode, locations, resultingCollections); > } > >@@ -2345,4 +2348,101 @@ > } > return (Statement) rewrite.createMoveTarget(source); > } >+ >+ private static boolean getConvertBaseProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) { >+ //TODO: 0xCAFEBABE - quick assist on this throws exceptions -- range problems I suppose >+ //TODO: does not work with literals having underscore, maybe have to try with newer JDK >+ >+ if (!(covering instanceof NumberLiteral)) >+ return false; >+ >+ NumberLiteral numberLiteral= (NumberLiteral) covering; >+ String token= numberLiteral.getToken(); >+ if (token.indexOf('.') != -1) >+ return false; >+ >+ if(resultingCollections==null) >+ return true; >+ >+ AST ast= covering.getAST(); >+ Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); >+ if (token.startsWith("0b")) { //$NON-NLS-1$ >+ //binary >+ String binaryString= token.substring(2); >+ int i= Integer.parseInt(binaryString, 2); >+ >+ convertToOctal(context, resultingCollections, numberLiteral, ast, image, i); >+ convertToHex(context, resultingCollections, numberLiteral, ast, image, i); >+ convertToDecimal(context, resultingCollections, numberLiteral, ast, image, i); >+ return true; >+ } else if (token.startsWith("0x")) { //$NON-NLS-1$ >+ //hex >+ String hexString= token.substring(2); >+ int i= Integer.parseInt(hexString, 16); >+ >+ convertToBinary(context, resultingCollections, numberLiteral, ast, image, i); >+ convertToOctal(context, resultingCollections, numberLiteral, ast, image, i); >+ convertToDecimal(context, resultingCollections, numberLiteral, ast, image, i); >+ return true; >+ } else if (token.startsWith("0")) { //$NON-NLS-1$ >+ //octal >+ String octalString= token.substring(1); >+ int i= Integer.parseInt(octalString, 8); >+ >+ convertToBinary(context, resultingCollections, numberLiteral, ast, image, i); >+ convertToHex(context, resultingCollections, numberLiteral, ast, image, i); >+ convertToDecimal(context, resultingCollections, numberLiteral, ast, image, i); >+ return true; >+ } else { >+ //decimal >+ int i= Integer.parseInt(token); >+ >+ convertToBinary(context, resultingCollections, numberLiteral, ast, image, i); >+ convertToOctal(context, resultingCollections, numberLiteral, ast, image, i); >+ convertToHex(context, resultingCollections, numberLiteral, ast, image, i); >+ return true; >+ } >+ } >+ >+ private static void convertToBinary(IInvocationContext context, Collection<ICommandAccess> resultingCollections, NumberLiteral numberLiteral, AST ast, Image image, int i) { >+ if(!JavaModelUtil.is70OrHigher(context.getCompilationUnit().getJavaProject())) >+ return; >+ ASTRewrite rewrite= ASTRewrite.create(ast); >+ NumberLiteral binary= ast.newNumberLiteral(); >+ binary.setToken("0b".concat(Integer.toBinaryString(i))); //$NON-NLS-1$ >+ rewrite.replace(numberLiteral, binary, null); >+ String label= "Convert to Binary"; >+ ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, -10, image); >+ resultingCollections.add(proposal); >+ } >+ >+ private static void convertToDecimal(IInvocationContext context, Collection<ICommandAccess> resultingCollections, NumberLiteral numberLiteral, AST ast, Image image, int i) { >+ ASTRewrite rewrite= ASTRewrite.create(ast); >+ NumberLiteral decimal= ast.newNumberLiteral(); >+ decimal.setToken(Integer.toString(i)); >+ rewrite.replace(numberLiteral, decimal, null); >+ String label= "Convert to Decimal"; >+ ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, -10, image); >+ resultingCollections.add(proposal); >+ } >+ >+ private static void convertToHex(IInvocationContext context, Collection<ICommandAccess> resultingCollections, NumberLiteral numberLiteral, AST ast, Image image, int i) { >+ ASTRewrite rewrite= ASTRewrite.create(ast); >+ NumberLiteral hex= ast.newNumberLiteral(); >+ hex.setToken("0x".concat(Integer.toHexString(i))); //$NON-NLS-1$ >+ rewrite.replace(numberLiteral, hex, null); >+ String label= "Convert to Hexadecimal"; >+ ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, -10, image); >+ resultingCollections.add(proposal); >+ } >+ >+ private static void convertToOctal(IInvocationContext context, Collection<ICommandAccess> resultingCollections, NumberLiteral numberLiteral, AST ast, Image image, int i) { >+ ASTRewrite rewrite= ASTRewrite.create(ast); >+ NumberLiteral octal= ast.newNumberLiteral(); >+ octal.setToken("0".concat(Integer.toOctalString(i))); //$NON-NLS-1$ >+ rewrite.replace(numberLiteral, octal, null); >+ String label= "Convert to Octal"; >+ ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, -10, image); >+ resultingCollections.add(proposal); >+ } > }
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 347839
: 197682