X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java b/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java index c1bf446..bdb5fdf 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java +++ b/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java @@ -1,17 +1,18 @@ package test; +import java.text.MessageFormat; +import java.util.Hashtable; + +import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; +import net.sourceforge.phpdt.internal.ui.util.StringUtil; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.texteditor.MarkerUtilities; -import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; -import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; -import net.sourceforge.phpdt.internal.compiler.parser.Parser; - -import java.text.MessageFormat; -import java.util.Hashtable; /** * The superclass for our PHP parsers. @@ -25,6 +26,8 @@ public abstract class PHPParserSuperclass { public static final int WARNING = 1; public static final int INFO = 0; public static final int TASK = 3; + // TODO design error? Analyze why fileToParse must be static ??? + protected static IFile fileToParse; /** * Call the php parse command ( php -l -f <filename> ) @@ -38,12 +41,10 @@ public abstract class PHPParserSuperclass { final String filename = file.getLocation().toString(); final String[] arguments = {filename}; - final MessageFormat form = - new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); + final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); final String command = form.format(arguments); - final String parserResult = - PHPStartApacheAction.getParserOutput(command, "External parser: "); + final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: "); try { // parse the buffer to find the errors and warnings @@ -57,8 +58,7 @@ public abstract class PHPParserSuperclass { * @param output the external parser output * @param file the file that was parsed. */ - protected static void createMarkers(final String output, final IFile file) - throws CoreException { + protected static void createMarkers(final String output, final IFile file) throws CoreException { // delete all markers file.deleteMarkers(IMarker.PROBLEM, false, 0); @@ -80,16 +80,14 @@ public abstract class PHPParserSuperclass { } } - private static void scanLine(final String output, final IFile file, final int indx, final int brIndx) - throws CoreException { + private static void scanLine(final String output, final IFile file, final int indx, final int brIndx) throws CoreException { String current; // String outLineNumberString; never used final StringBuffer lineNumberBuffer = new StringBuffer(10); char ch; current = output.substring(indx, brIndx); - if (current.indexOf(PARSE_WARNING_STRING) != -1 - || current.indexOf(PARSE_ERROR_STRING) != -1) { + if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) { final int onLine = current.indexOf("on line "); if (onLine != -1) { lineNumberBuffer.delete(0, lineNumberBuffer.length()); @@ -104,17 +102,15 @@ public abstract class PHPParserSuperclass { final Hashtable attributes = new Hashtable(); - current = current.replaceAll("\n", ""); - current = current.replaceAll("", ""); - current = current.replaceAll("", ""); + current = StringUtil.replaceAll(current, "\n", ""); + current = StringUtil.replaceAll(current, "", ""); + current = StringUtil.replaceAll(current, "", ""); MarkerUtilities.setMessage(attributes, current); if (current.indexOf(PARSE_ERROR_STRING) != -1) attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); else if (current.indexOf(PARSE_WARNING_STRING) != -1) - attributes.put( - IMarker.SEVERITY, - new Integer(IMarker.SEVERITY_WARNING)); + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); else attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); MarkerUtilities.setLineNumber(attributes, lineNumber); @@ -154,11 +150,12 @@ public abstract class PHPParserSuperclass { * {@link PHPParserSuperclass#INFO},{@link PHPParserSuperclass#WARNING}),{@link PHPParserSuperclass#TASK}) * @throws CoreException an exception throwed by the MarkerUtilities */ - public static void setMarker(final IFile file, - final String message, - final int charStart, - final int charEnd, - final int errorLevel) + public static void setMarker( + final IFile file, + final String message, + final int charStart, + final int charEnd, + final int errorLevel) throws CoreException { if (file != null) { final Hashtable attributes = new Hashtable(); @@ -225,6 +222,26 @@ public abstract class PHPParserSuperclass { /** * This will set a marker. + * @param message the message + * @param charStart the starting character + * @param charEnd the end character + * @param errorLevel the error level ({@link PHPParserSuperclass#ERROR}, + * {@link PHPParserSuperclass#INFO},{@link PHPParserSuperclass#WARNING}) + * @throws CoreException an exception throwed by the MarkerUtilities + */ + public static void setMarker(final String message, + final int charStart, + final int charEnd, + final int errorLevel, + final String location) + throws CoreException { + if (fileToParse != null) { + setMarker(fileToParse, message, charStart, charEnd, errorLevel, location); + } + } + + /** + * This will set a marker. * @param file the file that generated the marker * @param message the message * @param charStart the starting character