KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > internal > AjdeBuildErrorHandler


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

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 /**
35  * @author Mik Kersten
36  */

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 JavaDoc message) {
54         return showMessage(null, message, false, false);
55     }
56
57     public synchronized boolean showMessage(ASTObject where, String JavaDoc message) {
58         return showMessage(where, message, false, false);
59     }
60
61     public synchronized boolean showMessage(File source, int line, int endLine, int column, String JavaDoc message, boolean isError) {
62         return addMessage(source, line, column, message, isError);
63     }
64
65     public synchronized boolean showMessage(ASTObject where, String JavaDoc 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 JavaDoc message) {
81         if (showMessage(where, message, false, true)) errors += 1;
82     }
83
84     public synchronized void showError(File source, int line, int column, String JavaDoc message) {
85         if (showMessage(source, line, -1, column, message, true)) errors += 1;
86     }
87
88     public synchronized void showWarning(ASTObject where, String JavaDoc 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 JavaDoc 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