1 11 package org.eclipse.jdt.internal.ui.fix; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.CoreException; 18 19 import org.eclipse.jdt.core.ICompilationUnit; 20 import org.eclipse.jdt.core.dom.CompilationUnit; 21 22 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; 23 import org.eclipse.jdt.internal.corext.fix.ConvertLoopFix; 24 import org.eclipse.jdt.internal.corext.fix.IFix; 25 26 import org.eclipse.jdt.ui.text.java.IProblemLocation; 27 28 public class ConvertLoopCleanUp extends AbstractCleanUp { 29 30 public ConvertLoopCleanUp(Map options) { 31 super(options); 32 } 33 34 public ConvertLoopCleanUp() { 35 super(); 36 } 37 38 41 public boolean requireAST(ICompilationUnit unit) throws CoreException { 42 return isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED); 43 } 44 45 48 public IFix createFix(CompilationUnit compilationUnit) throws CoreException { 49 if (compilationUnit == null) 50 return null; 51 52 boolean convertForLoops= isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED); 53 54 return ConvertLoopFix.createCleanUp(compilationUnit, 55 convertForLoops, convertForLoops, 56 isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL) && isEnabled(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES)); 57 } 58 59 62 public IFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException { 63 return null; 65 } 66 67 70 public Map getRequiredOptions() { 71 return null; 72 } 73 74 77 public String [] getDescriptions() { 78 List result= new ArrayList (); 79 80 if (isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED)) 81 result.add(MultiFixMessages.Java50CleanUp_ConvertToEnhancedForLoop_description); 82 83 return (String [])result.toArray(new String [result.size()]); 84 } 85 86 public String getPreview() { 87 StringBuffer buf= new StringBuffer (); 88 89 if (isEnabled(CleanUpConstants.CONTROL_STATMENTS_CONVERT_FOR_LOOP_TO_ENHANCED)) { 90 buf.append("for (int element : ids) {\n"); buf.append(" double value= element / 2; \n"); buf.append(" System.out.println(value);\n"); buf.append("}\n"); } else { 95 buf.append("for (int i = 0; i < ids.length; i++) {\n"); buf.append(" double value= ids[i] / 2; \n"); buf.append(" System.out.println(value);\n"); buf.append("}\n"); } 100 101 return buf.toString(); 102 } 103 104 107 public boolean canFix(CompilationUnit compilationUnit, IProblemLocation problem) throws CoreException { 108 return false; 109 } 110 111 114 public int maximalNumberOfFixes(CompilationUnit compilationUnit) { 115 return -1; 116 } 117 } 118 | Popular Tags |