Cleaned up the unit tests.
authoraxelcl <axelcl>
Fri, 19 Aug 2005 19:23:27 +0000 (19:23 +0000)
committeraxelcl <axelcl>
Fri, 19 Aug 2005 19:23:27 +0000 (19:23 +0000)
Disabled all warnings for unit tests

net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/Util.java
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPFormatterTest.java
net.sourceforge.phpeclipse.tests/src/test/HelloWorld.java [deleted file]

index a85fa4d..b563138 100644 (file)
@@ -260,19 +260,13 @@ public class AbstractCompilerTest extends TestCase {
 
        protected Map getCompilerOptions() {
                Map options = new CompilerOptions().getMap();
-//             if (COMPLIANCE_1_3.equals(this.complianceLevel)) {
-//                     options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3);
-//                     options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
-//                     options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
-//             } else if (COMPLIANCE_1_4.equals(this.complianceLevel)) {
-//                     options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
-//                     options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
-//                     options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
-//             } else if (COMPLIANCE_1_5.equals(this.complianceLevel)) {
-//                     options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
-//                     options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
-//                     options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
-//             }
+               // 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);
+                   
                return options;
        }
 
index d7fb981..5c91332 100644 (file)
@@ -17,509 +17,481 @@ import java.util.Map;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
-//import net.sourceforge.phpdt.core.tests.compiler.regression.Requestor;
+// import net.sourceforge.phpdt.core.tests.compiler.regression.Requestor;
 import net.sourceforge.phpdt.internal.compiler.Compiler;
 import net.sourceforge.phpdt.internal.compiler.IErrorHandlingPolicy;
 import net.sourceforge.phpdt.internal.compiler.IProblemFactory;
 import net.sourceforge.phpdt.internal.compiler.batch.CompilationUnit;
-//import net.sourceforge.phpdt.internal.compiler.batch.FileSystem;
+// import net.sourceforge.phpdt.internal.compiler.batch.FileSystem;
 import net.sourceforge.phpdt.internal.compiler.env.INameEnvironment;
 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory;
+
 public class Util {
        public static String OUTPUT_DIRECTORY = "comptest";
 
-public static CompilationUnit[] compilationUnits(String[] testFiles) {
-       int length = testFiles.length / 2;
-       CompilationUnit[] result = new CompilationUnit[length];
-       int index = 0;
-       for (int i = 0; i < length; i++) {
-               result[i] = new CompilationUnit(testFiles[index + 1].toCharArray(), testFiles[index], null);
-               index += 2;
+       public static CompilationUnit[] compilationUnits(String[] testFiles) {
+               int length = testFiles.length / 2;
+               CompilationUnit[] result = new CompilationUnit[length];
+               int index = 0;
+               for (int i = 0; i < length; i++) {
+                       result[i] = new CompilationUnit(testFiles[index + 1].toCharArray(), testFiles[index], null);
+                       index += 2;
+               }
+               return result;
        }
-       return result;
-}
-//public static void compile(String[] pathsAndContents, Map options, String outputPath) {
-//             IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
-//             Requestor requestor = 
-//                     new Requestor(
-//                             problemFactory, 
-//                             outputPath.endsWith(File.separator) ? outputPath : outputPath + File.separator, 
-//                             false);
-//             INameEnvironment nameEnvironment = new FileSystem(getJavaClassLibs(), new String[] {}, null);
-//             IErrorHandlingPolicy errorHandlingPolicy = 
-//                     new IErrorHandlingPolicy() {
-//                             public boolean stopOnFirstError() {
-//                                     return false;
-//                             }
-//                             public boolean proceedOnErrors() {
-//                                     return true;
-//                             }
-//                     };
-//             Compiler batchCompiler = 
-//                     new Compiler(
-//                             nameEnvironment, 
-//                             errorHandlingPolicy, 
-//                             options,
-//                             requestor, 
-//                             problemFactory);
-//             batchCompiler.compile(compilationUnits(pathsAndContents)); // compile all files together
-//             System.err.print(requestor.problemLog); // problem log empty if no problems
-//}
-public static String[] concatWithClassLibs(String classpath, boolean inFront) {
-       String[] classLibs = getJavaClassLibs();
-       final int length = classLibs.length;
-       String[] defaultClassPaths = new String[length + 1];
-       if (inFront) {
-               System.arraycopy(classLibs, 0, defaultClassPaths, 1, length);
-               defaultClassPaths[0] = classpath;
-       } else {
-               System.arraycopy(classLibs, 0, defaultClassPaths, 0, length);
-               defaultClassPaths[length] = classpath;
-       } 
-       return defaultClassPaths;
-}
-public static String convertToIndependantLineDelimiter(String source) {
-       StringBuffer buffer = new StringBuffer();
-       for (int i = 0, length = source.length(); i < length; i++) {
-               char car = source.charAt(i);
-               if (car == '\r') {
-                       buffer.append('\n');
-                       if (i < length-1 && source.charAt(i+1) == '\n') {
-                               i++; // skip \n after \r
-                       }
+
+       public static String[] concatWithClassLibs(String classpath, boolean inFront) {
+               String[] classLibs = getJavaClassLibs();
+               final int length = classLibs.length;
+               String[] defaultClassPaths = new String[length + 1];
+               if (inFront) {
+                       System.arraycopy(classLibs, 0, defaultClassPaths, 1, length);
+                       defaultClassPaths[0] = classpath;
                } else {
-                       buffer.append(car);
+                       System.arraycopy(classLibs, 0, defaultClassPaths, 0, length);
+                       defaultClassPaths[length] = classpath;
                }
+               return defaultClassPaths;
        }
-       return buffer.toString();
-}
-/**
- * Copy the given source (a file or a directory that must exists) to the given destination (a directory that must exists).
- */
-public static void copy(String sourcePath, String destPath) {
-       sourcePath = toNativePath(sourcePath);
-       destPath = toNativePath(destPath);
-       File source = new File(sourcePath);
-       if (!source.exists()) return;
-       File dest = new File(destPath);
-       if (!dest.exists()) return;
-       if (source.isDirectory()) {
-               String[] files = source.list();
-               if (files != null) {
-                       for (int i = 0; i < files.length; i++) {
-                               String file = files[i];
-                               File sourceFile = new File(source, file);
-                               if (sourceFile.isDirectory()) {
-                                       File destSubDir = new File(dest, file);
-                                       destSubDir.mkdir();
-                                       copy(sourceFile.getPath(), destSubDir.getPath());
-                               } else {
-                                       copy(sourceFile.getPath(), dest.getPath());
+
+       public static String convertToIndependantLineDelimiter(String source) {
+               StringBuffer buffer = new StringBuffer();
+               for (int i = 0, length = source.length(); i < length; i++) {
+                       char car = source.charAt(i);
+                       if (car == '\r') {
+                               buffer.append('\n');
+                               if (i < length - 1 && source.charAt(i + 1) == '\n') {
+                                       i++; // skip \n after \r
                                }
+                       } else {
+                               buffer.append(car);
                        }
                }
-       } else {
-               FileInputStream in = null;
-               FileOutputStream out = null;
-               try {
-                       in = new FileInputStream(source);
-                       File destFile = new File(dest, source.getName());
-                       if (destFile.exists() && !destFile.delete()) {
-                               throw new IOException(destFile + " is in use");
-                       }
-                       out = new FileOutputStream(destFile);
-                       int bufferLength = 1024;
-                       byte[] buffer = new byte[bufferLength];
-                       int read = 0;
-                       while (read != -1) {
-                               read = in.read(buffer, 0, bufferLength);
-                               if (read != -1) {
-                                       out.write(buffer, 0, read);
+               return buffer.toString();
+       }
+
+       /**
+        * Copy the given source (a file or a directory that must exists) to the given
+        * destination (a directory that must exists).
+        */
+       public static void copy(String sourcePath, String destPath) {
+               sourcePath = toNativePath(sourcePath);
+               destPath = toNativePath(destPath);
+               File source = new File(sourcePath);
+               if (!source.exists())
+                       return;
+               File dest = new File(destPath);
+               if (!dest.exists())
+                       return;
+               if (source.isDirectory()) {
+                       String[] files = source.list();
+                       if (files != null) {
+                               for (int i = 0; i < files.length; i++) {
+                                       String file = files[i];
+                                       File sourceFile = new File(source, file);
+                                       if (sourceFile.isDirectory()) {
+                                               File destSubDir = new File(dest, file);
+                                               destSubDir.mkdir();
+                                               copy(sourceFile.getPath(), destSubDir.getPath());
+                                       } else {
+                                               copy(sourceFile.getPath(), dest.getPath());
+                                       }
                                }
                        }
-               } catch (IOException e) {
-                       throw new Error(e.toString());
-               } finally {
-                       if (in != null) {
-                               try {
-                                       in.close();
-                               } catch (IOException e) {
+               } else {
+                       FileInputStream in = null;
+                       FileOutputStream out = null;
+                       try {
+                               in = new FileInputStream(source);
+                               File destFile = new File(dest, source.getName());
+                               if (destFile.exists() && !destFile.delete()) {
+                                       throw new IOException(destFile + " is in use");
                                }
-                       }
-                       if (out != null) {
-                               try {
-                                       out.close();
-                               } catch (IOException e) {
+                               out = new FileOutputStream(destFile);
+                               int bufferLength = 1024;
+                               byte[] buffer = new byte[bufferLength];
+                               int read = 0;
+                               while (read != -1) {
+                                       read = in.read(buffer, 0, bufferLength);
+                                       if (read != -1) {
+                                               out.write(buffer, 0, read);
+                                       }
+                               }
+                       } catch (IOException e) {
+                               throw new Error(e.toString());
+                       } finally {
+                               if (in != null) {
+                                       try {
+                                               in.close();
+                                       } catch (IOException e) {
+                                       }
+                               }
+                               if (out != null) {
+                                       try {
+                                               out.close();
+                                       } catch (IOException e) {
+                                       }
                                }
                        }
                }
        }
-}
-//public static void createJar(String[] pathsAndContents, Map options, String jarPath) throws IOException {
-//     String classesPath = getOutputDirectory() + File.separator + "classes";
-//     File classesDir = new File(classesPath);
-//     flushDirectoryContent(classesDir);
-//     compile(pathsAndContents, options, classesPath);
-//     zip(classesDir, jarPath);
-//}
-/**
- * Generate a display string from the given String.
- * @param indent number of tabs are added at the begining of each line.
- *
- * Example of use: [org.eclipse.jdt.core.tests.util.Util.displayString("abc\ndef\tghi")]
-*/
-public static String displayString(String inputString){
-       return displayString(inputString, 0);
-}
-/**
- * Generate a display string from the given String.
- * It converts:
- * <ul>
- * <li>\t to \t</li>
- * <li>\r to \\r</li>
- * <li>\n to \n</li>
- * <li>\b to \\b</li>
- * <li>\f to \\f</li>
- * <li>\" to \\\"</li>
- * <li>\' to \\'</li>
- * <li>\\ to \\\\</li>
- * <li>All other characters are unchanged.</li>
- * </ul>
- * This method doesn't convert \r\n to \n. 
- * <p>
- * Example of use:
- * <o>
- * <li>
- * <pre>
- * input string = "abc\ndef\tghi",
- * indent = 3
- * result = "\"\t\t\tabc\\n" +
- *                     "\t\t\tdef\tghi\""
- * </pre>
- * </li>
- * <li>
- * <pre>
- * input string = "abc\ndef\tghi\n",
- * indent = 3
- * result = "\"\t\t\tabc\\n" +
- *                     "\t\t\tdef\tghi\\n\""
- * </pre>
- * </li>
- * <li>
- * <pre>
- * input string = "abc\r\ndef\tghi\r\n",
- * indent = 3
- * result = "\"\t\t\tabc\\r\\n" +
- *                     "\t\t\tdef\tghi\\r\\n\""
- * </pre>
- * </li>
- * </ol>
- * </p>
- * 
- * @param inputString the given input string
- * @param indent number of tabs are added at the begining of each line.
- *
- * @return the displayed string
-*/
-public static String displayString(String inputString, int indent) {
-       int length = inputString.length();
-       StringBuffer buffer = new StringBuffer(length);
-       java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(inputString, "\n\r", true);
-       for (int i = 0; i < indent; i++) buffer.append("\t");
-       buffer.append("\"");
-       while (tokenizer.hasMoreTokens()){
 
-               String token = tokenizer.nextToken();
-               if (token.equals("\r")) {
-                       buffer.append("\\r");
-                       if (tokenizer.hasMoreTokens()) {
-                               token = tokenizer.nextToken();
-                               if (token.equals("\n")) {
-                                       buffer.append("\\n");
-                                       if (tokenizer.hasMoreTokens()) {
+       // public static void createJar(String[] pathsAndContents, Map options, String
+       // jarPath) throws IOException {
+       // String classesPath = getOutputDirectory() + File.separator + "classes";
+       // File classesDir = new File(classesPath);
+       // flushDirectoryContent(classesDir);
+       // compile(pathsAndContents, options, classesPath);
+       // zip(classesDir, jarPath);
+       // }
+       /**
+        * Generate a display string from the given String.
+        * 
+        * @param indent
+        *          number of tabs are added at the begining of each line.
+        * 
+        * Example of use:
+        * [org.eclipse.jdt.core.tests.util.Util.displayString("abc\ndef\tghi")]
+        */
+       public static String displayString(String inputString) {
+               return displayString(inputString, 0);
+       }
+
+       /**
+        * Generate a display string from the given String. It converts:
+        * <ul>
+        * <li>\t to \t</li>
+        * <li>\r to \\r</li>
+        * <li>\n to \n</li>
+        * <li>\b to \\b</li>
+        * <li>\f to \\f</li>
+        * <li>\" to \\\"</li>
+        * <li>\' to \\'</li>
+        * <li>\\ to \\\\</li>
+        * <li>All other characters are unchanged.</li>
+        * </ul>
+        * This method doesn't convert \r\n to \n.
+        * <p>
+        * Example of use: <o>
+        * <li>
+        * 
+        * <pre>
+        *  input string = &quot;abc\ndef\tghi&quot;,
+        *  indent = 3
+        *  result = &quot;\&quot;\t\t\tabc\\n&quot; +
+        *                      &quot;\t\t\tdef\tghi\&quot;&quot;
+        * </pre>
+        * 
+        * </li>
+        * <li>
+        * 
+        * <pre>
+        *  input string = &quot;abc\ndef\tghi\n&quot;,
+        *  indent = 3
+        *  result = &quot;\&quot;\t\t\tabc\\n&quot; +
+        *                      &quot;\t\t\tdef\tghi\\n\&quot;&quot;
+        * </pre>
+        * 
+        * </li>
+        * <li>
+        * 
+        * <pre>
+        *  input string = &quot;abc\r\ndef\tghi\r\n&quot;,
+        *  indent = 3
+        *  result = &quot;\&quot;\t\t\tabc\\r\\n&quot; +
+        *                      &quot;\t\t\tdef\tghi\\r\\n\&quot;&quot;
+        * </pre>
+        * 
+        * </li>
+        * </ol>
+        * </p>
+        * 
+        * @param inputString
+        *          the given input string
+        * @param indent
+        *          number of tabs are added at the begining of each line.
+        * 
+        * @return the displayed string
+        */
+       public static String displayString(String inputString, int indent) {
+               int length = inputString.length();
+               StringBuffer buffer = new StringBuffer(length);
+               java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(inputString, "\n\r", true);
+               for (int i = 0; i < indent; i++)
+                       buffer.append("\t");
+               buffer.append("\"");
+               while (tokenizer.hasMoreTokens()) {
+
+                       String token = tokenizer.nextToken();
+                       if (token.equals("\r")) {
+                               buffer.append("\\r");
+                               if (tokenizer.hasMoreTokens()) {
+                                       token = tokenizer.nextToken();
+                                       if (token.equals("\n")) {
+                                               buffer.append("\\n");
+                                               if (tokenizer.hasMoreTokens()) {
+                                                       buffer.append("\" + \n");
+                                                       for (int i = 0; i < indent; i++)
+                                                               buffer.append("\t");
+                                                       buffer.append("\"");
+                                               }
+                                               continue;
+                                       } else {
                                                buffer.append("\" + \n");
-                                               for (int i = 0; i < indent; i++) buffer.append("\t");
+                                               for (int i = 0; i < indent; i++)
+                                                       buffer.append("\t");
                                                buffer.append("\"");
                                        }
-                                       continue;
                                } else {
+                                       continue;
+                               }
+                       } else if (token.equals("\n")) {
+                               buffer.append("\\n");
+                               if (tokenizer.hasMoreTokens()) {
                                        buffer.append("\" + \n");
-                                       for (int i = 0; i < indent; i++) buffer.append("\t");
+                                       for (int i = 0; i < indent; i++)
+                                               buffer.append("\t");
                                        buffer.append("\"");
                                }
-                       } else {
                                continue;
                        }
-               } else if (token.equals("\n")) {
-                       buffer.append("\\n");
-                       if (tokenizer.hasMoreTokens()) {
-                               buffer.append("\" + \n");
-                               for (int i = 0; i < indent; i++) buffer.append("\t");
-                               buffer.append("\"");
-                       }
-                       continue;
-               }       
 
-               StringBuffer tokenBuffer = new StringBuffer();
-               for (int i = 0; i < token.length(); i++){ 
-                       char c = token.charAt(i);
-                       switch (c) {
-                               case '\r' :
+                       StringBuffer tokenBuffer = new StringBuffer();
+                       for (int i = 0; i < token.length(); i++) {
+                               char c = token.charAt(i);
+                               switch (c) {
+                               case '\r':
                                        tokenBuffer.append("\\r");
                                        break;
-                               case '\n' :
+                               case '\n':
                                        tokenBuffer.append("\\n");
                                        break;
-                               case '\b' :
+                               case '\b':
                                        tokenBuffer.append("\\b");
                                        break;
-                               case '\t' :
+                               case '\t':
                                        tokenBuffer.append("\t");
                                        break;
-                               case '\f' :
+                               case '\f':
                                        tokenBuffer.append("\\f");
                                        break;
-                               case '\"' :
+                               case '\"':
                                        tokenBuffer.append("\\\"");
                                        break;
-                               case '\'' :
+                               case '\'':
                                        tokenBuffer.append("\\'");
                                        break;
-                               case '\\' :
+                               case '\\':
                                        tokenBuffer.append("\\\\");
                                        break;
-                               default :
+                               default:
                                        tokenBuffer.append(c);
+                               }
                        }
+                       buffer.append(tokenBuffer.toString());
                }
-               buffer.append(tokenBuffer.toString());
-       }
-       buffer.append("\"");
-       return buffer.toString();
-}
-/**
- * Reads the content of the given source file and converts it to a display string.
- *
- * Example of use: [org.eclipse.jdt.core.tests.util.Util.fileContentToDisplayString("c:/temp/X.java", 0)]
-*/
-public static String fileContentToDisplayString(String sourceFilePath, int indent, boolean independantLineDelimiter) {
-       File sourceFile = new File(sourceFilePath);
-       if (!sourceFile.exists()) {
-               System.out.println("File " + sourceFilePath + " does not exists.");
-               return null;
+               buffer.append("\"");
+               return buffer.toString();
        }
-       if (!sourceFile.isFile()) {
-               System.out.println(sourceFilePath + " is not a file.");
-               return null;
-       }
-       StringBuffer sourceContentBuffer = new StringBuffer();
-       FileInputStream input = null;
-       try {
-               input = new FileInputStream(sourceFile);
-       } catch (FileNotFoundException e) {
-               return null;
-       }
-       try { 
-               int read;
-               do {
-                       read = input.read();
-                       if (read != -1) {
-                               sourceContentBuffer.append((char)read);
-                       }
-               } while (read != -1);
-               input.close();
-       } catch (IOException e) {
-               e.printStackTrace();
-               return null;
-       } finally {
+
+       /**
+        * Reads the content of the given source file and converts it to a display
+        * string.
+        * 
+        * Example of use:
+        * [org.eclipse.jdt.core.tests.util.Util.fileContentToDisplayString("c:/temp/X.java",
+        * 0)]
+        */
+       public static String fileContentToDisplayString(String sourceFilePath, int indent, boolean independantLineDelimiter) {
+               File sourceFile = new File(sourceFilePath);
+               if (!sourceFile.exists()) {
+                       System.out.println("File " + sourceFilePath + " does not exists.");
+                       return null;
+               }
+               if (!sourceFile.isFile()) {
+                       System.out.println(sourceFilePath + " is not a file.");
+                       return null;
+               }
+               StringBuffer sourceContentBuffer = new StringBuffer();
+               FileInputStream input = null;
                try {
+                       input = new FileInputStream(sourceFile);
+               } catch (FileNotFoundException e) {
+                       return null;
+               }
+               try {
+                       int read;
+                       do {
+                               read = input.read();
+                               if (read != -1) {
+                                       sourceContentBuffer.append((char) read);
+                               }
+                       } while (read != -1);
                        input.close();
-               } catch (IOException e2) {
+               } catch (IOException e) {
+                       e.printStackTrace();
+                       return null;
+               } finally {
+                       try {
+                               input.close();
+                       } catch (IOException e2) {
+                       }
                }
+               String sourceString = sourceContentBuffer.toString();
+               if (independantLineDelimiter) {
+                       sourceString = convertToIndependantLineDelimiter(sourceString);
+               }
+               return displayString(sourceString, indent);
        }
-       String sourceString = sourceContentBuffer.toString();
-       if (independantLineDelimiter) {
-               sourceString = convertToIndependantLineDelimiter(sourceString);
-       }
-       return displayString(sourceString, indent);
-}
-/**
- * Reads the content of the given source file, converts it to a display string.
- * If the destination file path is not null, writes the result to this file.
- * Otherwise writes it to the console.
- *
- * Example of use: [org.eclipse.jdt.core.tests.util.Util.fileContentToDisplayString("c:/temp/X.java", 0, null)]
-*/
-public static void fileContentToDisplayString(String sourceFilePath, int indent, String destinationFilePath, boolean independantLineDelimiter) {
-       String displayString = fileContentToDisplayString(sourceFilePath, indent, independantLineDelimiter);
-       if (destinationFilePath == null) {
-               System.out.println(displayString);
-               return;
+
+       /**
+        * Reads the content of the given source file, converts it to a display
+        * string. If the destination file path is not null, writes the result to this
+        * file. Otherwise writes it to the console.
+        * 
+        * Example of use:
+        * [org.eclipse.jdt.core.tests.util.Util.fileContentToDisplayString("c:/temp/X.java",
+        * 0, null)]
+        */
+       public static void fileContentToDisplayString(String sourceFilePath, int indent, String destinationFilePath,
+                       boolean independantLineDelimiter) {
+               String displayString = fileContentToDisplayString(sourceFilePath, indent, independantLineDelimiter);
+               if (destinationFilePath == null) {
+                       System.out.println(displayString);
+                       return;
+               }
+               writeToFile(displayString, destinationFilePath);
        }
-       writeToFile(displayString, destinationFilePath);
-}
-/**
- * Flush content of a given directory (leaving it empty),
- * no-op if not a directory.
- */
-public static void flushDirectoryContent(File dir) {
-       if (dir.isDirectory()) {
-               String[] files = dir.list();
-               if (files == null) return;
-               for (int i = 0, max = files.length; i < max; i++) {
-                       File current = new File(dir, files[i]);
-                       if (current.isDirectory()) {
-                               flushDirectoryContent(current);
+
+       /**
+        * Flush content of a given directory (leaving it empty), no-op if not a
+        * directory.
+        */
+       public static void flushDirectoryContent(File dir) {
+               if (dir.isDirectory()) {
+                       String[] files = dir.list();
+                       if (files == null)
+                               return;
+                       for (int i = 0, max = files.length; i < max; i++) {
+                               File current = new File(dir, files[i]);
+                               if (current.isDirectory()) {
+                                       flushDirectoryContent(current);
+                               }
+                               current.delete();
                        }
-                       current.delete();
                }
        }
-}
-/**
- * Search the user hard-drive for a Java class library.
- * Returns null if none could be found.
- *
- * Example of use: [org.eclipse.jdt.core.tests.util.Util.getJavaClassLib()]
-*/
-public static String[] getJavaClassLibs() {
-       String jreDir = getJREDirectory();
-       if (jreDir == null)  {
-               return new String[] {};
-       } else {
-               final String vmName = System.getProperty("java.vm.name");
-               if ("J9".equals(vmName)) {
-                       return new String[] { toNativePath(jreDir + "/lib/jclMax/classes.zip")};
+
+       /**
+        * Search the user hard-drive for a Java class library. Returns null if none
+        * could be found.
+        * 
+        * Example of use: [org.eclipse.jdt.core.tests.util.Util.getJavaClassLib()]
+        */
+       public static String[] getJavaClassLibs() {
+               String jreDir = getJREDirectory();
+               if (jreDir == null) {
+                       return new String[] {};
                } else {
-                       File file = new File(jreDir + "/lib/rt.jar");
-                       if (file.exists()) {
-                               return new String[] {
-                                       toNativePath(jreDir + "/lib/rt.jar")
-                               };                              
-                       } else {                                
-                               return new String[] { 
-                                       toNativePath(jreDir + "/lib/core.jar"),
-                                       toNativePath(jreDir + "/lib/security.jar"),
-                                       toNativePath(jreDir + "/lib/graphics.jar")
-                               };
+                       final String vmName = System.getProperty("java.vm.name");
+                       if ("J9".equals(vmName)) {
+                               return new String[] { toNativePath(jreDir + "/lib/jclMax/classes.zip") };
+                       } else {
+                               File file = new File(jreDir + "/lib/rt.jar");
+                               if (file.exists()) {
+                                       return new String[] { toNativePath(jreDir + "/lib/rt.jar") };
+                               } else {
+                                       return new String[] { toNativePath(jreDir + "/lib/core.jar"), toNativePath(jreDir + "/lib/security.jar"),
+                                                       toNativePath(jreDir + "/lib/graphics.jar") };
+                               }
                        }
                }
        }
-}
-public static String getJavaClassLibsAsString() {
-       String[] classLibs = getJavaClassLibs();
-       StringBuffer buffer = new StringBuffer();
-       for (int i = 0, max = classLibs.length; i < max; i++) {
-               buffer
-                       .append(classLibs[i])
-                       .append(File.pathSeparatorChar);
-               
+
+       public static String getJavaClassLibsAsString() {
+               String[] classLibs = getJavaClassLibs();
+               StringBuffer buffer = new StringBuffer();
+               for (int i = 0, max = classLibs.length; i < max; i++) {
+                       buffer.append(classLibs[i]).append(File.pathSeparatorChar);
+
+               }
+               return buffer.toString();
        }
-       return buffer.toString();
-}
-/**
- * Returns the JRE directory this tests are running on.
- * Returns null if none could be found.
- *
- * Example of use: [org.eclipse.jdt.core.tests.util.Util.getJREDirectory()]
-*/
-public static String getJREDirectory() {
-       return System.getProperty("java.home");
-}
-/**
- * Search the user hard-drive for a possible output directory.
- * Returns null if none could be found.
- *
- * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()]
-*/
-public static String getOutputDirectory() {
-       String container = System.getProperty("user.home");
-       if (container == null){
-               return null;
-       } else {
-               return toNativePath(container) + File.separator + OUTPUT_DIRECTORY;
+
+       /**
+        * Returns the JRE directory this tests are running on. Returns null if none
+        * could be found.
+        * 
+        * Example of use: [org.eclipse.jdt.core.tests.util.Util.getJREDirectory()]
+        */
+       public static String getJREDirectory() {
+               return System.getProperty("java.home");
        }
-}
-/**
- * Returns the next available port number on the local host.
- */
-public static int getFreePort() {
-       ServerSocket socket = null;
-       try {
-               socket = new ServerSocket(0);
-               return socket.getLocalPort();
-       } catch (IOException e) {
-               // ignore
-       } finally {
-               if (socket != null) {
-                       try {
-                               socket.close();
-                       } catch (IOException e) {
-                               // ignore
+
+       /**
+        * Search the user hard-drive for a possible output directory. Returns null if
+        * none could be found.
+        * 
+        * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()]
+        */
+       public static String getOutputDirectory() {
+               String container = System.getProperty("user.home");
+               if (container == null) {
+                       return null;
+               } else {
+                       return toNativePath(container) + File.separator + OUTPUT_DIRECTORY;
+               }
+       }
+
+       /**
+        * Returns the next available port number on the local host.
+        */
+       public static int getFreePort() {
+               ServerSocket socket = null;
+               try {
+                       socket = new ServerSocket(0);
+                       return socket.getLocalPort();
+               } catch (IOException e) {
+                       // ignore
+               } finally {
+                       if (socket != null) {
+                               try {
+                                       socket.close();
+                               } catch (IOException e) {
+                                       // ignore
+                               }
                        }
                }
+               return -1;
        }
-       return -1;
-}
-/**
- * Makes the given path a path using native path separators as returned by File.getPath()
- * and trimming any extra slash.
- */
-public static String toNativePath(String path) {
-       String nativePath = path.replace('\\', File.separatorChar).replace('/', File.separatorChar);
-       return
-               nativePath.endsWith("/") || nativePath.endsWith("\\") ?
-                       nativePath.substring(0, nativePath.length() - 1) :
-                       nativePath;
-}
-public static void writeToFile(String contents, String destinationFilePath) {
-       File destFile = new File(destinationFilePath);
-       FileOutputStream output = null;
-       try {
-               output = new FileOutputStream(destFile);
-               PrintWriter writer = new PrintWriter(output);
-               writer.print(contents);
-               writer.flush();
-       } catch (IOException e) {
-               e.printStackTrace();
-               return;
-       } finally {
-               if (output != null) {
-                       try {
-                               output.close();
-                       } catch (IOException e2) {
+
+       /**
+        * Makes the given path a path using native path separators as returned by
+        * File.getPath() and trimming any extra slash.
+        */
+       public static String toNativePath(String path) {
+               String nativePath = path.replace('\\', File.separatorChar).replace('/', File.separatorChar);
+               return nativePath.endsWith("/") || nativePath.endsWith("\\") ? nativePath.substring(0, nativePath.length() - 1) : nativePath;
+       }
+
+       public static void writeToFile(String contents, String destinationFilePath) {
+               File destFile = new File(destinationFilePath);
+               FileOutputStream output = null;
+               try {
+                       output = new FileOutputStream(destFile);
+                       PrintWriter writer = new PrintWriter(output);
+                       writer.print(contents);
+                       writer.flush();
+               } catch (IOException e) {
+                       e.printStackTrace();
+                       return;
+               } finally {
+                       if (output != null) {
+                               try {
+                                       output.close();
+                               } catch (IOException e2) {
+                               }
                        }
                }
        }
 }
-//public static void zip(File rootDir, String zipPath) throws IOException {
-//     ZipOutputStream zip = null;
-//     try {
-//             zip  = new ZipOutputStream(new FileOutputStream(zipPath));
-//             zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash
-//     } finally {
-//             if (zip != null) {
-//                     zip.close();
-//             }
-//     }
-//}
-//private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException {
-//     String[] list = dir.list();
-//     if (list != null) {
-//             for (int i = 0, length = list.length; i < length; i++) {
-//                     String name = list[i];
-//                     File file = new File(dir, name);
-//                     if (file.isDirectory()) {
-//                             zip(file, zip, rootPathLength);
-//                     } else {
-//                             String path = file.getPath();
-//                             path = path.substring(rootPathLength);
-//                             ZipEntry entry = new ZipEntry(path.replace('\\', '/'));
-//                             zip.putNextEntry(entry);
-//                             zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file));
-//                             zip.closeEntry();
-//                     }
-//             }
-//     }
-//}
-}
-
index 8acbb51..d8b9d32 100644 (file)
@@ -19,7 +19,7 @@ import org.eclipse.jface.text.IDocument;
  * Testcase for the PHP CodeFormatter
  * 
  * @author Stefan Langer
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
  */
 public class PHPFormatterTest extends TestCase {
   private CodeFormatter fFormatter;
@@ -49,7 +49,7 @@ public class PHPFormatterTest extends TestCase {
       indent = Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
     }
     String formatedString = fFormatter.format(text, indent, null, lineDelimiter);
-    String testResult = "<?php " + lineDelimiter
+    String testResult = "<?php" + lineDelimiter
         + "header(\"Location: http://www.phpeclipse.de/eclipse/space/eclipse/faq/longlinetester\");" + lineDelimiter + "exit;"
         + lineDelimiter + "?>";
     junit.framework.Assert.assertEquals(formatedString, testResult);
@@ -65,7 +65,7 @@ public class PHPFormatterTest extends TestCase {
       indent = Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
     }
     String formatedString = fFormatter.format(text, indent, null, lineDelimiter);
-    String testResult = "<?php " + lineDelimiter + "function test() {" + lineDelimiter + "\techo 'Test!';" + lineDelimiter + "}"
+    String testResult = "<?php" + lineDelimiter + "function test() {" + lineDelimiter + "\techo 'Test!';" + lineDelimiter + "}"
         + lineDelimiter + "?>";
     junit.framework.Assert.assertEquals(formatedString, testResult);
   }
@@ -81,7 +81,7 @@ public class PHPFormatterTest extends TestCase {
       indent = Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
     }
     String formatedString = fFormatter.format(text, indent, null, lineDelimiter);
-    String testResult = "<?php " + lineDelimiter + "if (${ $feldname } == $modellvar)" + lineDelimiter + "\t$i = 0;"
+    String testResult = "<?php" + lineDelimiter + "if (${ $feldname } == $modellvar)" + lineDelimiter + "\t$i = 0;"
         + lineDelimiter + "?>";
     junit.framework.Assert.assertEquals(formatedString, testResult);
   }
@@ -96,7 +96,7 @@ public class PHPFormatterTest extends TestCase {
       indent = Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
     }
     String formatedString = fFormatter.format(text, indent, null, lineDelimiter);
-    String testResult = "<?php " + lineDelimiter + " " + lineDelimiter + " " + lineDelimiter + "function test() {" + lineDelimiter
+    String testResult = "<?php" + lineDelimiter + "function test() {" + lineDelimiter
         + "\techo 'Test!';" + lineDelimiter + "}" + lineDelimiter + "?>";
     junit.framework.Assert.assertEquals(formatedString, testResult);
   }
diff --git a/net.sourceforge.phpeclipse.tests/src/test/HelloWorld.java b/net.sourceforge.phpeclipse.tests/src/test/HelloWorld.java
deleted file mode 100644 (file)
index 2f8b47e..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package test;
-
-class HelloWorld
-{ 
-        public static void main(String args[])
-        {
-           System.out.println("Hello World!");
-        }
-}