1 11 package org.eclipse.jdt.internal.ui.fix; 12 13 import java.util.ArrayList ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.CoreException; 17 18 import org.eclipse.jdt.core.ICompilationUnit; 19 import org.eclipse.jdt.core.dom.CompilationUnit; 20 21 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; 22 import org.eclipse.jdt.internal.corext.fix.IFix; 23 24 import org.eclipse.jdt.ui.text.java.IProblemLocation; 25 26 public class CodeFormatCleanUp extends AbstractCleanUp { 27 28 public CodeFormatCleanUp() { 29 super(); 30 } 31 32 public CodeFormatCleanUp(Map options) { 33 super(options); 34 } 35 36 39 public boolean requireAST(ICompilationUnit unit) throws CoreException { 40 return false; 41 } 42 43 public IFix createFix(ICompilationUnit compilationUnit) throws CoreException { 44 if (compilationUnit == null) 45 return null; 46 47 boolean removeWhitespaces= isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES); 48 return CodeFormatFix.createCleanUp(compilationUnit, isEnabled(CleanUpConstants.FORMAT_SOURCE_CODE), removeWhitespaces && isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL), removeWhitespaces && isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_IGNORE_EMPTY)); 49 } 50 51 54 public IFix createFix(CompilationUnit compilationUnit) throws CoreException { 55 return null; 56 } 57 58 61 public IFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException { 62 if (compilationUnit == null) 63 return null; 64 65 return null; 66 } 67 68 public Map getRequiredOptions() { 69 return null; 70 } 71 72 75 public String [] getDescriptions() { 76 ArrayList result= new ArrayList (); 77 if (isEnabled(CleanUpConstants.FORMAT_SOURCE_CODE)) 78 result.add(MultiFixMessages.CodeFormatCleanUp_description); 79 80 if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES)) { 81 if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL)) { 82 result.add(MultiFixMessages.CodeFormatCleanUp_RemoveTrailingAll_description); 83 } else if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_IGNORE_EMPTY)) { 84 result.add(MultiFixMessages.CodeFormatCleanUp_RemoveTrailingNoEmpty_description); 85 } 86 } 87 88 return (String [])result.toArray(new String [result.size()]); 89 } 90 91 public String getPreview() { 92 StringBuffer buf= new StringBuffer (); 93 buf.append("public class Engine {\n"); buf.append(" public void start() {}\n"); if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES) && isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES_ALL)) { 96 buf.append("\n"); } else { 98 buf.append(" \n"); } 100 if (isEnabled(CleanUpConstants.FORMAT_REMOVE_TRAILING_WHITESPACES)) { 101 buf.append(" public\n"); } else { 103 buf.append(" public \n"); } 105 buf.append(" void stop() {\n"); buf.append(" }\n"); buf.append("}\n"); 109 return buf.toString(); 110 } 111 112 115 public int maximalNumberOfFixes(CompilationUnit compilationUnit) { 116 return -1; 117 } 118 119 public boolean canFix(CompilationUnit compilationUnit, IProblemLocation problem) throws CoreException { 120 return false; 121 } 122 } 123 | Popular Tags |