1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 21:05:37 +02:00

Change implementation to save extension form the

CCorePlugin
This commit is contained in:
Alain Magloire 2003-08-31 23:54:38 +00:00
parent 9e854093ca
commit f1966eafe3

View file

@ -13,15 +13,9 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
import org.eclipse.cdt.core.resources.ACBuilder;
import org.eclipse.cdt.internal.errorparsers.GASErrorParser;
import org.eclipse.cdt.internal.errorparsers.GCCErrorParser;
import org.eclipse.cdt.internal.errorparsers.GLDErrorParser;
import org.eclipse.cdt.internal.errorparsers.MakeErrorParser;
import org.eclipse.cdt.internal.errorparsers.VCErrorParser;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@ -31,16 +25,15 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class ErrorParserManager extends OutputStream {
private int nOpens;
private static String PREF_ERROR_PARSER = "errorOutputParser";
private int nOpens;
private IProject fProject;
private IMarkerGenerator fMarkerGenerator;
private Map fFilesInProject;
private List fNameConflicts;
private ArrayList fErrorParsers;
private Map fErrorParsers;
private ArrayList fErrors;
private Vector fDirectoryStack;
@ -57,14 +50,26 @@ public class ErrorParserManager extends OutputStream {
}
public ErrorParserManager(IProject project, IMarkerGenerator markerGenerator) {
fProject = project;
fErrorParsers = new ArrayList();
fMarkerGenerator = markerGenerator;
readPreferences();
initParser();
this(project, markerGenerator, null);
}
private void initParser() {
public ErrorParserManager(IProject project, IMarkerGenerator markerGenerator, String[] parsersIDs) {
fProject = project;
if (parsersIDs == null) {
fErrorParsers = new HashMap();
readPreferences();
} else {
fErrorParsers = new HashMap(parsersIDs.length);
for (int i = 0; i < parsersIDs.length; i++) {
IErrorParser[] parsers = CCorePlugin.getDefault().getErrorParser(parsersIDs[i]);
fErrorParsers.put(parsersIDs[i], parsers);
}
}
fMarkerGenerator = markerGenerator;
initErrorParserManager();
}
private void initErrorParserManager() {
fFilesInProject = new HashMap();
fNameConflicts = new ArrayList();
fDirectoryStack = new Vector();
@ -123,57 +128,34 @@ public class ErrorParserManager extends OutputStream {
return fDirectoryStack.size();
}
protected void addParser(IErrorParser parser) {
fErrorParsers.add(parser);
}
private void readPreferences() {
fErrorParsers.clear();
String parserNames = CCorePlugin.getDefault().getPluginPreferences().getString(PREF_ERROR_PARSER);
if (parserNames != null && parserNames.length() > 0) {
StringTokenizer tok = new StringTokenizer(parserNames, ";");
while (tok.hasMoreElements()) {
String clName = tok.nextToken();
try {
IErrorParser parser = (IErrorParser) Class.forName(clName).newInstance();
fErrorParsers.add(parser);
}
catch (ClassNotFoundException e) {
// not found
CCorePlugin.log(e);
}
catch (InstantiationException e) {
CCorePlugin.log(e);
}
catch (IllegalAccessException e) {
CCorePlugin.log(e);
}
catch (ClassCastException e) {
CCorePlugin.log(e);
}
}
String[] parserIDs = CCorePlugin.getDefault().getPreferenceErrorParserIDs();
for (int i = 0; i < parserIDs.length; i++) {
IErrorParser[] parsers = CCorePlugin.getDefault().getErrorParser(parserIDs[i]);
fErrorParsers.put(parserIDs[i], parsers);
}
if (fErrorParsers.size() == 0) {
initErrorParsersArray(fErrorParsers);
}
initErrorParsersMap();
savePreferences();
}
}
private void initErrorParsersArray(List errorParsers) {
errorParsers.add(new VCErrorParser());
errorParsers.add(new GCCErrorParser());
errorParsers.add(new GLDErrorParser());
errorParsers.add(new GASErrorParser());
errorParsers.add(new MakeErrorParser());
private void initErrorParsersMap() {
String[] parserIDs = CCorePlugin.getDefault().getAllErrorParsersIDs();
for (int i = 0; i < parserIDs.length; i++) {
IErrorParser[] parsers = CCorePlugin.getDefault().getErrorParser(parserIDs[i]);
fErrorParsers.put(parserIDs[i], parsers);
}
}
private void savePreferences() {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < fErrorParsers.size(); i++) {
buf.append(fErrorParsers.get(i).getClass().getName());
buf.append(';');
String[] parserIDs = new String[fErrorParsers.size()];
Iterator items = fErrorParsers.keySet().iterator();
for (int i = 0; items.hasNext(); i++) {
parserIDs[i] = (String) items.next();
}
CCorePlugin.getDefault().getPluginPreferences().setValue(PREF_ERROR_PARSER, buf.toString());
CCorePlugin.getDefault().setPreferenceErrorParser(parserIDs);
}
protected void collectFiles(IContainer parent, List result) {
@ -183,13 +165,11 @@ public class ErrorParserManager extends OutputStream {
IResource resource = resources[i];
if (resource instanceof IFile) {
result.add(resource);
}
else if (resource instanceof IContainer) {
} else if (resource instanceof IContainer) {
collectFiles((IContainer) resource, result);
}
}
}
catch (CoreException e) {
} catch (CoreException e) {
CCorePlugin.log(e.getStatus());
}
}
@ -198,22 +178,30 @@ public class ErrorParserManager extends OutputStream {
* Parses the input and try to generate error or warning markers
*/
private void processLine(String line) {
int top = fErrorParsers.size() - 1;
String[] parserIDs = new String[fErrorParsers.size()];
Iterator items = fErrorParsers.keySet().iterator();
for (int i = 0; items.hasNext(); i++) {
parserIDs[i] = (String) items.next();
}
int top = parserIDs.length - 1;
int i = top;
do {
IErrorParser curr = (IErrorParser) fErrorParsers.get(i);
IErrorParser[] parsers = (IErrorParser[]) fErrorParsers.get(parserIDs[i]);
for (int j = 0; j < parsers.length; j++) {
IErrorParser curr = parsers[j];
if (curr.processLine(line, this)) {
if (i != top) {
// move to top
Object used = fErrorParsers.remove(i);
fErrorParsers.add(used);
savePreferences();
Object used = fErrorParsers.remove(parserIDs[i]);
fErrorParsers.put(parserIDs[i], used);
//savePreferences();
}
return;
}
i--;
}
while (i >= 0);
i--;
} while (i >= 0);
}
/**
@ -242,8 +230,7 @@ public class ErrorParserManager extends OutputStream {
if (fBaseDirectory.isPrefixOf(fp)) {
int segments = fBaseDirectory.matchingFirstSegments(fp);
path = fp.removeFirstSegments(segments);
}
else {
} else {
path = fp;
}
} else {
@ -357,11 +344,9 @@ public class ErrorParserManager extends OutputStream {
public synchronized void write(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
}
else if (off != 0 || (len < 0) || (len > b.length)) {
} else if (off != 0 || (len < 0) || (len > b.length)) {
throw new IndexOutOfBoundsException();
}
else if (len == 0) {
} else if (len == 0) {
return;
}
currentLine.append(new String(b, 0, len));