A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse.tests / src / net / sourceforge / phpdt / core / tests / util / AbstractCompilerTest.java
index c334f5f..19da326 100644 (file)
@@ -34,35 +34,35 @@ import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblem;
 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory;
 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
 
-//import net.sourceforge.phpdt.core.tests.junit.extension.TestCase;
-//import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
+// import net.sourceforge.phpdt.core.tests.junit.extension.TestCase;
+// import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
 
 public class AbstractCompilerTest extends TestCase {
 
        private static int possibleComplianceLevels = -1;
 
        protected String complianceLevel;
-       public void checkParsePHP(
-               char[] source,
-               String expectedSyntaxErrorDiagnosis) {
-//             String testName) {
 
-               UnitParser parser =
-                       new UnitParser(
-                               new ProblemReporter(
-                                       DefaultErrorHandlingPolicies.proceedWithAllProblems(),
-                                       new CompilerOptions(getCompilerOptions()),
-                                       new DefaultProblemFactory(Locale.getDefault())));
+       public void checkParsePHP(char[] source, String expectedSyntaxErrorDiagnosis) {
+               // String testName) {
+
+               UnitParser parser = new UnitParser(new ProblemReporter(
+                               DefaultErrorHandlingPolicies.proceedWithAllProblems(),
+                               new CompilerOptions(getCompilerOptions()),
+                               new DefaultProblemFactory(Locale.getDefault())));
 
                ICompilationUnit sourceUnit = new CompilationUnit(source, "", null);
-               CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
+               CompilationResult compilationResult = new CompilationResult(sourceUnit,
+                               0, 0, 0);
 
-               CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, true);
-//             if (computedUnit.types != null) {
-//                     for (int i = computedUnit.types.size(); --i >= 0;){
-//                             ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser, computedUnit);
-//                     }
-//             }
+               CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit,
+                               compilationResult, true);
+               // if (computedUnit.types != null) {
+               // for (int i = computedUnit.types.size(); --i >= 0;){
+               // ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser,
+               // computedUnit);
+               // }
+               // }
 
                StringBuffer buffer = new StringBuffer(100);
                if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
@@ -75,10 +75,16 @@ public class AbstractCompilerTest extends TestCase {
                                        if (problemCount == 0)
                                                buffer.append("----------\n");
                                        problemCount++;
-                                       buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING"));
-                                       buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\'));
+                                       buffer
+                                                       .append(problemCount
+                                                                       + (problems[i].isError() ? ". ERROR"
+                                                                                       : ". WARNING"));
+                                       buffer.append(" in "
+                                                       + new String(problems[i].getOriginatingFileName())
+                                                                       .replace('/', '\\'));
                                        try {
-                                               buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource));
+                                               buffer.append(((DefaultProblem) problems[i])
+                                                               .errorReportSource(unitSource));
                                                buffer.append("\n");
                                                buffer.append(problems[i].getMessage());
                                                buffer.append("\n");
@@ -92,35 +98,35 @@ public class AbstractCompilerTest extends TestCase {
                        }
                }
                String computedSyntaxErrorDiagnosis = buffer.toString();
-               if(!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
-                       System.out.println(Util.displayString(computedSyntaxErrorDiagnosis));
+               if (!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
+                       System.out
+                                       .println(Util.displayString(computedSyntaxErrorDiagnosis));
                }
-               assertEquals(
-                       "Invalid syntax error diagnosis",
-                       expectedSyntaxErrorDiagnosis,
-                       computedSyntaxErrorDiagnosis);
+               assertEquals("Invalid syntax error diagnosis",
+                               expectedSyntaxErrorDiagnosis, computedSyntaxErrorDiagnosis);
        }
-       public void checkParseHTML(
-               char[] source,
-               String expectedSyntaxErrorDiagnosis) {
-//             String testName) {
 
-               UnitParser parser =
-                       new UnitParser(
-                               new ProblemReporter(
-                                       DefaultErrorHandlingPolicies.proceedWithAllProblems(),
-                                       new CompilerOptions(getCompilerOptions()),
-                                       new DefaultProblemFactory(Locale.getDefault())));
+       public void checkParseHTML(char[] source,
+                       String expectedSyntaxErrorDiagnosis) {
+               // String testName) {
+
+               UnitParser parser = new UnitParser(new ProblemReporter(
+                               DefaultErrorHandlingPolicies.proceedWithAllProblems(),
+                               new CompilerOptions(getCompilerOptions()),
+                               new DefaultProblemFactory(Locale.getDefault())));
 
                ICompilationUnit sourceUnit = new CompilationUnit(source, "", null);
-               CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
+               CompilationResult compilationResult = new CompilationResult(sourceUnit,
+                               0, 0, 0);
 
-               CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, false);
-//             if (computedUnit.types != null) {
-//                     for (int i = computedUnit.types.size(); --i >= 0;){
-//                             ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser, computedUnit);
-//                     }
-//             }
+               CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit,
+                               compilationResult, false);
+               // if (computedUnit.types != null) {
+               // for (int i = computedUnit.types.size(); --i >= 0;){
+               // ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser,
+               // computedUnit);
+               // }
+               // }
 
                StringBuffer buffer = new StringBuffer(100);
                if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
@@ -133,10 +139,16 @@ public class AbstractCompilerTest extends TestCase {
                                        if (problemCount == 0)
                                                buffer.append("----------\n");
                                        problemCount++;
-                                       buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING"));
-                                       buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\'));
+                                       buffer
+                                                       .append(problemCount
+                                                                       + (problems[i].isError() ? ". ERROR"
+                                                                                       : ". WARNING"));
+                                       buffer.append(" in "
+                                                       + new String(problems[i].getOriginatingFileName())
+                                                                       .replace('/', '\\'));
                                        try {
-                                               buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource));
+                                               buffer.append(((DefaultProblem) problems[i])
+                                                               .errorReportSource(unitSource));
                                                buffer.append("\n");
                                                buffer.append(problems[i].getMessage());
                                                buffer.append("\n");
@@ -150,61 +162,65 @@ public class AbstractCompilerTest extends TestCase {
                        }
                }
                String computedSyntaxErrorDiagnosis = buffer.toString();
-               if(!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
-                       System.out.println(Util.displayString(computedSyntaxErrorDiagnosis));
+               if (!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
+                       System.out
+                                       .println(Util.displayString(computedSyntaxErrorDiagnosis));
                }
-               assertEquals(
-                       "Invalid syntax error diagnosis",
-                       expectedSyntaxErrorDiagnosis,
-                       computedSyntaxErrorDiagnosis);
+               assertEquals("Invalid syntax error diagnosis",
+                               expectedSyntaxErrorDiagnosis, computedSyntaxErrorDiagnosis);
        }
+
        /*
         * Returns the possible compliance levels this VM instance can run.
         */
-//     public static int getPossibleComplianceLevels() {
-//             if (possibleComplianceLevels == -1) {
-//                     String compliance = System.getProperty("compliance");
-//                     if (compliance != null) {
-//                             if (COMPLIANCE_1_3.equals(compliance)) {
-//                                     possibleComplianceLevels = F_1_3;
-//                             } else if (COMPLIANCE_1_4.equals(compliance)) {
-//                                     possibleComplianceLevels = F_1_4;
-//                             } else if (COMPLIANCE_1_5.equals(compliance)) {
-//                                     possibleComplianceLevels = F_1_5;
-//                             } else {
-//                                     System.out.println("Invalid compliance specified (" + compliance + ")");
-//                                     System.out.println("Use one of " + COMPLIANCE_1_3 + ", " + COMPLIANCE_1_4 + ", " + COMPLIANCE_1_5);
-//                                     System.out.println("Defaulting to all possible compliances");
-//                             }
-//                     }
-//                     if (possibleComplianceLevels == -1) {
-//                             possibleComplianceLevels = F_1_3;
-//                             String specVersion = System.getProperty("java.specification.version");
-//                             boolean canRun1_4 = !"1.0".equals(specVersion) && !"1.1".equals(specVersion) && !"1.2".equals(specVersion) && !"1.3".equals(specVersion);
-//                             if (canRun1_4) {
-//                                     possibleComplianceLevels |= F_1_4;
-//                             }
-//                             boolean canRun1_5 = canRun1_4 && !"1.4".equals(specVersion);
-//                             if (canRun1_5) {
-//                                     possibleComplianceLevels |= F_1_5;
-//                             }
-//                     }
-//             }
-//             return possibleComplianceLevels;
-//     }
-
+       // public static int getPossibleComplianceLevels() {
+       // if (possibleComplianceLevels == -1) {
+       // String compliance = System.getProperty("compliance");
+       // if (compliance != null) {
+       // if (COMPLIANCE_1_3.equals(compliance)) {
+       // possibleComplianceLevels = F_1_3;
+       // } else if (COMPLIANCE_1_4.equals(compliance)) {
+       // possibleComplianceLevels = F_1_4;
+       // } else if (COMPLIANCE_1_5.equals(compliance)) {
+       // possibleComplianceLevels = F_1_5;
+       // } else {
+       // System.out.println("Invalid compliance specified (" + compliance + ")");
+       // System.out.println("Use one of " + COMPLIANCE_1_3 + ", " + COMPLIANCE_1_4
+       // + ", " + COMPLIANCE_1_5);
+       // System.out.println("Defaulting to all possible compliances");
+       // }
+       // }
+       // if (possibleComplianceLevels == -1) {
+       // possibleComplianceLevels = F_1_3;
+       // String specVersion = System.getProperty("java.specification.version");
+       // boolean canRun1_4 = !"1.0".equals(specVersion) &&
+       // !"1.1".equals(specVersion) && !"1.2".equals(specVersion) &&
+       // !"1.3".equals(specVersion);
+       // if (canRun1_4) {
+       // possibleComplianceLevels |= F_1_4;
+       // }
+       // boolean canRun1_5 = canRun1_4 && !"1.4".equals(specVersion);
+       // if (canRun1_5) {
+       // possibleComplianceLevels |= F_1_5;
+       // }
+       // }
+       // }
+       // return possibleComplianceLevels;
+       // }
        /*
-        * Returns a test suite including the tests defined by the given classes for the given complianceLevel
-        * (see AbstractCompilerTest for valid values) and using the given setup class (CompilerTestSetup or a subclass)
+        * Returns a test suite including the tests defined by the given classes for
+        * the given complianceLevel (see AbstractCompilerTest for valid values) and
+        * using the given setup class (CompilerTestSetup or a subclass)
         */
-       public static Test suiteForComplianceLevel(String complianceLevel, Class setupClass, ArrayList testClasses) {
+       public static Test suiteForComplianceLevel(String complianceLevel,
+                       Class setupClass, ArrayList testClasses) {
                TestSuite suite;
                if (testClasses.size() == 1) {
-                       suite = new TestSuite((Class)testClasses.get(0), complianceLevel);
+                       suite = new TestSuite((Class) testClasses.get(0), complianceLevel);
                } else {
                        suite = new TestSuite(complianceLevel);
                        for (int i = 0, length = testClasses.size(); i < length; i++) {
-                               Class testClass = (Class)testClasses.get(i);
+                               Class testClass = (Class) testClasses.get(i);
                                TestSuite innerSuite = new TestSuite(testClass);
                                suite.addTest(innerSuite);
                        }
@@ -212,8 +228,10 @@ public class AbstractCompilerTest extends TestCase {
 
                // call the setup constructor with the suite and compliance level
                try {
-                       Constructor constructor = setupClass.getConstructor(new Class[]{Test.class, String.class});
-                       Test setUp = (Test)constructor.newInstance(new Object[]{suite, complianceLevel});
+                       Constructor constructor = setupClass.getConstructor(new Class[] {
+                                       Test.class, String.class });
+                       Test setUp = (Test) constructor.newInstance(new Object[] { suite,
+                                       complianceLevel });
                        return setUp;
                } catch (IllegalAccessException e) {
                        e.printStackTrace();
@@ -235,12 +253,19 @@ public class AbstractCompilerTest extends TestCase {
        protected Map getCompilerOptions() {
                Map options = new CompilerOptions().getMap();
                // ignore warnings
-               options.put(CompilerOptions.OPTION_PHPVarDeprecatedWarning, CompilerOptions.IGNORE);
-               options.put(CompilerOptions.OPTION_PHPBadStyleKeywordWarning, CompilerOptions.IGNORE);
-               options.put(CompilerOptions.OPTION_PHPBadStyleUppercaseIdentifierWarning, CompilerOptions.IGNORE);
-               options.put(CompilerOptions.OPTION_PHPIncludeNotExistWarning, CompilerOptions.IGNORE);
-               options.put(CompilerOptions.OPTION_UninitializedLocalVariableWarning, CompilerOptions.IGNORE);
-               options.put(CompilerOptions.OPTION_CodeCannotBeReachedWarning, CompilerOptions.IGNORE);
+               options.put(CompilerOptions.OPTION_PHPVarDeprecatedWarning,
+                               CompilerOptions.IGNORE);
+               options.put(CompilerOptions.OPTION_PHPBadStyleKeywordWarning,
+                               CompilerOptions.IGNORE);
+               options.put(
+                               CompilerOptions.OPTION_PHPBadStyleUppercaseIdentifierWarning,
+                               CompilerOptions.IGNORE);
+               options.put(CompilerOptions.OPTION_PHPIncludeNotExistWarning,
+                               CompilerOptions.IGNORE);
+               options.put(CompilerOptions.OPTION_UninitializedLocalVariableWarning,
+                               CompilerOptions.IGNORE);
+               options.put(CompilerOptions.OPTION_CodeCannotBeReachedWarning,
+                               CompilerOptions.IGNORE);
                return options;
        }
 
@@ -251,11 +276,12 @@ public class AbstractCompilerTest extends TestCase {
                }
                return name;
        }
-       
+
        protected void checkPHP(String strEval) {
-               checkPHP(strEval,"");
+               checkPHP(strEval, "");
        }
-       protected void checkPHP(String strEval, String expectedSyntaxErrorDiagnosis ) {
+
+       protected void checkPHP(String strEval, String expectedSyntaxErrorDiagnosis) {
                if (Scanner.DEBUG) {
                        System.out.println("\n------------------------------------");
                        System.out.println(strEval);
@@ -264,12 +290,10 @@ public class AbstractCompilerTest extends TestCase {
        }
 
        protected void checkHTML(String strEval) {
-           if (Scanner.DEBUG) {
-             System.out.println("\n------------------------------------");
-             System.out.println(strEval);
-           }
-           checkParseHTML(
-               strEval.toCharArray(),
-                       "");
-         }
+               if (Scanner.DEBUG) {
+                       System.out.println("\n------------------------------------");
+                       System.out.println(strEval);
+               }
+               checkParseHTML(strEval.toCharArray(), "");
+       }
 }