KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > console > JavacPatternMatcher


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.ui.console;
12
13 import org.eclipse.ant.internal.ui.AntUIPlugin;
14 import org.eclipse.ui.console.PatternMatchEvent;
15
16 public class JavacPatternMatcher extends AbstractJavacPatternMatcher {
17
18     /*
19      * [javac] /Users/kevinbarnes/Eclipse/runtime-workspace/Foo/src/CarriageReturn.java:4: ';' expected
20      */

21     public void matchFound(PatternMatchEvent event) {
22         String JavaDoc matchedText= getMatchedText(event);
23         if (matchedText == null) {
24             return;
25         }
26
27         int numEnd= matchedText.lastIndexOf(':');
28         while (numEnd > 1 && !Character.isDigit(matchedText.charAt(numEnd - 1))) {
29             numEnd= matchedText.lastIndexOf(':', numEnd - 1);
30         }
31         int numStart= matchedText.lastIndexOf(':', numEnd - 1);
32         
33         int index = matchedText.indexOf("]"); //$NON-NLS-1$
34

35         String JavaDoc filePath;
36         if (numStart == -1) {
37             //file path from listfiles
38
filePath= matchedText.substring(index + 1);
39             filePath = filePath.trim();
40             int fileStart = matchedText.indexOf(filePath);
41             int eventOffset= event.getOffset() + fileStart;
42             int eventLength = filePath.length();
43             addLink(filePath, -1, eventOffset, eventLength, null);
44         } else {
45             filePath= matchedText.substring(index + 1, numStart);
46             filePath = filePath.trim();
47
48             int fileStart = matchedText.indexOf(filePath);
49             int eventOffset= event.getOffset() + fileStart;
50             int eventLength = filePath.length();
51
52             String JavaDoc lineNumberString = matchedText.substring(numStart + 1, numEnd);
53             int lineNumber= -1;
54             try {
55                 lineNumber= Integer.parseInt(lineNumberString);
56             } catch (NumberFormatException JavaDoc e) {
57                 AntUIPlugin.log(e);
58             }
59
60             Integer JavaDoc type= fgErrorType;
61             if (-1 != matchedText.indexOf("warning", numEnd)) { //$NON-NLS-1$
62
type= fgWarningType;
63             }
64             addLink(filePath, lineNumber, eventOffset, eventLength, type);
65         }
66     }
67 }
Popular Tags