1 2 25 26 package org.aspectj.ajde.internal; 27 28 import java.io.*; 29 import org.aspectj.compiler.base.*; 30 import org.aspectj.compiler.base.ast.*; 31 import org.aspectj.asm.*; 32 import org.aspectj.ajde.*; 33 34 37 public class AjdeBuildErrorHandler extends org.aspectj.compiler.base.ErrorHandler { 38 39 protected AjdeCompiler compiler; 40 protected TaskListManager taskListManager; 41 protected int errors = 0; 42 protected int warnings = 0; 43 44 public void cleanupErrorWarningCounters() { 45 errors = 0; 46 warnings = 0; 47 } 48 49 public AjdeBuildErrorHandler(TaskListManager taskListManager) { 50 this.taskListManager = taskListManager; 51 } 52 53 public synchronized boolean showMessage(String message) { 54 return showMessage(null, message, false, false); 55 } 56 57 public synchronized boolean showMessage(ASTObject where, String message) { 58 return showMessage(where, message, false, false); 59 } 60 61 public synchronized boolean showMessage(File source, int line, int endLine, int column, String message, boolean isError) { 62 return addMessage(source, line, column, message, isError); 63 } 64 65 public synchronized boolean showMessage(ASTObject where, String message, boolean showAll, boolean isError) { 66 if (where == null) { 67 return showMessage(null, -1, -1, -1, message, isError); 68 } 69 if (where.getSourceFile() == null || where.getBeginLine() == -1) { 70 71 ASTObject newWhere = where.getSourceLocation().getSourceObject(); 72 if (newWhere != null) { 73 return showMessage(newWhere, message, showAll, isError); 74 } 75 } 76 return addMessage(where.getSourceFile(), where.getBeginLine(), 77 where.getBeginColumn(), message, isError); 78 } 79 80 public synchronized void showError(ASTObject where, String message) { 81 if (showMessage(where, message, false, true)) errors += 1; 82 } 83 84 public synchronized void showError(File source, int line, int column, String message) { 85 if (showMessage(source, line, -1, column, message, true)) errors += 1; 86 } 87 88 public synchronized void showWarning(ASTObject where, String message) { 89 if (errors > 0) return; 90 if (showMessage(where, message, false, false)) warnings += 1; 91 } 92 93 94 public synchronized void showWarning(ASTObject where, Message message) { 95 if (compiler.getOptions().Xlint) { 96 showWarning(where, message.getString()); 97 } 98 } 99 100 protected boolean addMessage( 101 File source, 102 int line, 103 int column, 104 String message, 105 boolean isError) { 106 if (taskListManager == null) return false; 107 StructureMessage.Kind kind; 108 if (isError) { 109 kind = StructureMessage.Kind.ERROR; 110 } else { 111 kind = StructureMessage.Kind.WARNING; 112 } 113 114 if (source != null) { 115 taskListManager.addSourcelineTask( 116 message, 117 new org.aspectj.asm.SourceLocation(source.getPath(), line, column), 118 kind); 119 StructureNode node = Ajde.getDefault().getStructureModelManager().getStructureModel().findNodeForSourceLine( 120 source.getPath(), 121 line 122 ); 123 124 if (node != null) node.setMessage(new StructureMessage(message, kind)); 125 } else { 126 taskListManager.addProjectTask(message, kind); 127 } 128 129 return true; 130 } 131 132 public synchronized boolean willExitWithErrors() { 133 return errors > 0; 134 } 135 136 public synchronized void exitOnErrors() { 137 if (errors > 0) { 138 showWarnings(); 139 throw new CompilerErrors(errors); 140 } 141 } 142 143 public int getErrorCount() { 144 return errors; 145 } 146 147 public int getWarningCount() { 148 return warnings; 149 } 150 151 public void setCompiler(AjdeCompiler compiler) { 152 this.compiler = compiler; 153 } 154 } 155 | Popular Tags |