1 11 package org.eclipse.jdt.internal.ui.fix; 12 13 import java.util.ArrayList ; 14 import java.util.Hashtable ; 15 import java.util.List ; 16 import java.util.Map ; 17 18 import org.eclipse.core.runtime.CoreException; 19 20 import org.eclipse.jdt.core.ICompilationUnit; 21 import org.eclipse.jdt.core.JavaCore; 22 import org.eclipse.jdt.core.compiler.IProblem; 23 import org.eclipse.jdt.core.dom.CompilationUnit; 24 25 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; 26 import org.eclipse.jdt.internal.corext.fix.IFix; 27 import org.eclipse.jdt.internal.corext.fix.StringFix; 28 29 import org.eclipse.jdt.ui.text.java.IProblemLocation; 30 31 36 public class StringCleanUp extends AbstractCleanUp { 37 38 public StringCleanUp(Map options) { 39 super(options); 40 } 41 42 public StringCleanUp() { 43 super(); 44 } 45 46 49 public boolean requireAST(ICompilationUnit unit) throws CoreException { 50 return isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS) || 51 isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS); 52 } 53 54 public IFix createFix(CompilationUnit compilationUnit) throws CoreException { 55 if (compilationUnit == null) 56 return null; 57 58 return StringFix.createCleanUp(compilationUnit, 59 isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS), 60 isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)); 61 } 62 63 66 public IFix createFix(CompilationUnit compilationUnit, IProblemLocation[] problems) throws CoreException { 67 if (compilationUnit == null) 68 return null; 69 70 return StringFix.createCleanUp(compilationUnit, problems, 71 isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS), 72 isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)); 73 } 74 75 public Map getRequiredOptions() { 76 Map result= new Hashtable (); 77 78 if (isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS) || isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)) 79 result.put(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL, JavaCore.WARNING); 80 81 return result; 82 } 83 84 87 public String [] getDescriptions() { 88 List result= new ArrayList (); 89 if (isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS)) 90 result.add(MultiFixMessages.StringMultiFix_AddMissingNonNls_description); 91 if (isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)) 92 result.add(MultiFixMessages.StringMultiFix_RemoveUnnecessaryNonNls_description); 93 return (String [])result.toArray(new String [result.size()]); 94 } 95 96 99 public String getPreview() { 100 StringBuffer buf= new StringBuffer (); 101 102 if (isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)) { 103 buf.append("public String s;"); } else { 105 buf.append("public String s; //$NON-NLS-1$"); } 107 108 return buf.toString(); 109 } 110 111 115 public boolean canFix(CompilationUnit compilationUnit, IProblemLocation problem) throws CoreException { 116 return StringFix.createFix(compilationUnit, problem, isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS), isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS)) != null; 117 } 118 119 122 public int maximalNumberOfFixes(CompilationUnit compilationUnit) { 123 int result= 0; 124 IProblem[] problems= compilationUnit.getProblems(); 125 if (isEnabled(CleanUpConstants.ADD_MISSING_NLS_TAGS)) 126 result+= getNumberOfProblems(problems, IProblem.NonExternalizedStringLiteral); 127 128 if (isEnabled(CleanUpConstants.REMOVE_UNNECESSARY_NLS_TAGS)) 129 result+= getNumberOfProblems(problems, IProblem.UnnecessaryNLSTag); 130 131 return result; 132 } 133 } 134 | Popular Tags |