1 19 20 package org.netbeans.modules.tasklist.pmd; 21 22 import net.sourceforge.pmd.RuleViolation; 23 import pmd.*; 24 import javax.swing.text.*; 25 import javax.swing.event.*; 26 import java.awt.*; 27 import java.awt.event.*; 28 import javax.swing.*; 29 import org.openide.explorer.view.*; 30 import org.openide.nodes.*; 31 import org.openide.loaders.DataObject; 32 import org.openide.text.Line; 33 import org.openide.text.DataEditorSupport; 34 import org.openide.util.NbBundle; 35 36 import org.netbeans.modules.tasklist.core.TLUtils; 37 import org.netbeans.modules.tasklist.core.ConfPanel; 38 import org.netbeans.modules.tasklist.client.Suggestion; 39 import org.netbeans.modules.tasklist.client.SuggestionPerformer; 40 41 46 47 48 public class ImportPerformer implements SuggestionPerformer { 49 private Line line; 50 private RuleViolation violation; 51 private boolean comment; 52 53 ImportPerformer(Line line, RuleViolation violation, 54 boolean comment) { 55 this.line = line; 56 this.violation = violation; 57 } 58 59 public void perform(Suggestion s) { 60 if (comment) { 62 TLUtils.commentLine(line, "import "); } else { 64 TLUtils.deleteLine(line, "import "); } 66 } 67 public boolean hasConfirmation() { 68 return true; 69 } 70 public Object getConfirmation(Suggestion s) { 71 DataObject dao = DataEditorSupport.findDataObject(line); 72 int linenumber = line.getLineNumber(); 73 String filename = dao.getPrimaryFile().getNameExt(); 74 String ruleDesc = violation.getRule().getDescription(); 75 String ruleExample = violation.getRule().getExample(); 76 StringBuffer sb = new StringBuffer (200); 77 String beforeContents = null; 78 String afterContents = null; 79 String afterDesc = null; 80 String beforeDesc = null; 81 if (comment) { 82 beforeDesc = NbBundle.getMessage(ImportPerformer.class, 84 "ImportConfirmationBefore"); afterDesc = 86 NbBundle.getMessage(ImportPerformer.class, 87 "ImportConfirmationAfter"); 89 Line l = line; 90 sb.append("<html>"); TLUtils.appendSurroundingLine(sb, l, -1); 92 sb.append("<br><b>"); sb.append(line.getText()); 94 sb.append("</b><br>"); TLUtils.appendSurroundingLine(sb, l, +1); 96 sb.append("</html>"); beforeContents = sb.toString(); 98 99 sb.setLength(0); 100 sb.append("<html>"); TLUtils.appendSurroundingLine(sb, l, -1); 102 sb.append("<br><b><i>// "); sb.append(line.getText()); 104 sb.append("</i></b><br>"); TLUtils.appendSurroundingLine(sb, l, +1); 106 sb.append("</html>"); afterContents = sb.toString(); 108 } else { 109 String rulename = violation.getRule().getName(); 110 if (rulename.equals("UnusedImports")) { beforeDesc = NbBundle.getMessage(ImportPerformer.class, 112 "ImportConfirmationUnused"); } else if (rulename.equals("ImportFromSamePackage")) { beforeDesc = NbBundle.getMessage(ImportPerformer.class, 115 "ImportConfirmationSame"); } else if (rulename.equals("DontImportJavaLang")) { beforeDesc = NbBundle.getMessage(ImportPerformer.class, 118 "ImportConfirmationLang"); } else if (rulename.equals("DuplicateImports")) { beforeDesc = NbBundle.getMessage(ImportPerformer.class, 121 "ImportConfirmationDuplicate"); } else { 123 beforeDesc = NbBundle.getMessage(ImportPerformer.class, 124 "ImportConfirmationOther"); } 126 127 Line l = line; 128 sb.append("<html>"); TLUtils.appendSurroundingLine(sb, l, -1); 130 sb.append("<br>"); 131 sb.append("<b><strike>"); sb.append(line.getText()); 133 sb.append("</strike></b>"); sb.append("<br>"); TLUtils.appendSurroundingLine(sb, l, +1); 136 sb.append("</html>"); beforeContents = sb.toString(); 138 } 139 140 return new ConfPanel(beforeDesc, 141 beforeContents, afterDesc, 142 afterContents, 143 filename, linenumber, 144 ViolationProvider.getBottomPanel(ruleDesc, 145 ruleExample)); 146 147 } 148 } 149 | Popular Tags |