3.x RC1 compatibility
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParserSuperclass.java
index ed690b0..88b2e8a 100644 (file)
@@ -3,7 +3,9 @@ package test;
 import java.text.MessageFormat;
 import java.util.Hashtable;
 
+import net.sourceforge.phpdt.core.IJavaModelMarker;
 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
+import net.sourceforge.phpdt.internal.core.builder.PHPBuilder;
 import net.sourceforge.phpdt.internal.ui.util.StringUtil;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
@@ -26,6 +28,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,7 +42,7 @@ public abstract class PHPParserSuperclass {
     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
     final String filename = file.getLocation().toString();
 
-    final String[] arguments = { filename };
+    final String[] arguments = {filename};
     final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
     final String command = form.format(arguments);
 
@@ -58,7 +62,8 @@ public abstract class PHPParserSuperclass {
    */
   protected static void createMarkers(final String output, final IFile file) throws CoreException {
     // delete all markers
-    file.deleteMarkers(IMarker.PROBLEM, false, 0);
+//    file.deleteMarkers(IMarker.PROBLEM, false, 0);
+               PHPBuilder.removeProblemsAndTasksFor(file);
 
     int indx = 0;
     int brIndx;
@@ -112,7 +117,8 @@ public abstract class PHPParserSuperclass {
         else
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
         MarkerUtilities.setLineNumber(attributes, lineNumber);
-        MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
+//        MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
+                               MarkerUtilities.createMarker(file, attributes, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
       }
     }
   }
@@ -149,32 +155,33 @@ public abstract class PHPParserSuperclass {
    * @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)
-    throws CoreException {
+      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();
       MarkerUtilities.setMessage(attributes, message);
       switch (errorLevel) {
-        case ERROR :
+        case ERROR:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
           break;
-        case WARNING :
+        case WARNING:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
           break;
-        case INFO :
+        case INFO:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
           break;
-        case TASK :
+        case TASK:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK));
           break;
       }
       MarkerUtilities.setCharStart(attributes, charStart);
       MarkerUtilities.setCharEnd(attributes, charEnd);
-      MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
+//      MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
+                       MarkerUtilities.createMarker(file, attributes, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
     }
   }
 
@@ -187,25 +194,31 @@ public abstract class PHPParserSuperclass {
    *        {@link PHPParserSuperclass#INFO},{@link PHPParserSuperclass#WARNING})
    * @throws CoreException an exception throwed by the MarkerUtilities
    */
-  public static void setMarker(final IFile file, final String message, final int line, final int errorLevel, final String location)
-    throws CoreException {
+  public static void setMarker(final IFile file,
+                               final String message,
+                               final int line,
+                               final int errorLevel,
+                               final String location)
+      throws CoreException {
     if (file != null) {
-      String markerKind = IMarker.PROBLEM;
+//      String markerKind = IMarker.PROBLEM;
+                       String markerKind = IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER;
       final Hashtable attributes = new Hashtable();
       MarkerUtilities.setMessage(attributes, message);
       switch (errorLevel) {
-        case ERROR :
+        case ERROR:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
           break;
-        case WARNING :
+        case WARNING:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
           break;
-        case INFO :
+        case INFO:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
           break;
-        case TASK :
+        case TASK:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
-          markerKind = IMarker.TASK;
+//          markerKind = IMarker.TASK;
+          markerKind = IJavaModelMarker.TASK_MARKER;
           break;
       }
       attributes.put(IMarker.LOCATION, location);
@@ -216,6 +229,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
@@ -225,35 +258,35 @@ public abstract class PHPParserSuperclass {
    * @param location the location of the error
    * @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,
-    final String location)
-    throws CoreException {
+  public static void setMarker(final IFile file,
+                               final String message,
+                               final int charStart,
+                               final int charEnd,
+                               final int errorLevel,
+                               final String location)
+      throws CoreException {
     if (file != null) {
       final Hashtable attributes = new Hashtable();
       MarkerUtilities.setMessage(attributes, message);
       switch (errorLevel) {
-        case ERROR :
+        case ERROR:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
           break;
-        case WARNING :
+        case WARNING:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
           break;
-        case INFO :
+        case INFO:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
           break;
-        case TASK :
+        case TASK:
           attributes.put(IMarker.SEVERITY, new Integer(IMarker.TASK));
           break;
       }
       attributes.put(IMarker.LOCATION, location);
       MarkerUtilities.setCharStart(attributes, charStart);
       MarkerUtilities.setCharEnd(attributes, charEnd);
-      MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
+//      MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
+                       MarkerUtilities.createMarker(file, attributes, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
     }
   }
 }