X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/ToolFactory.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/ToolFactory.java index ca6331d..34590c9 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/ToolFactory.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/ToolFactory.java @@ -13,15 +13,17 @@ package net.sourceforge.phpdt.core; import java.util.Map; -import net.sourceforge.phpeclipse.PHPCore; +import net.sourceforge.phpdt.internal.compiler.parser.Scanner; +import net.sourceforge.phpdt.internal.formatter.CodeFormatter; import org.eclipse.core.runtime.Plugin; -import net.sourceforge.phpdt.internal.formatter.CodeFormatter; /** - * Factory for creating various compiler tools, such as scanners, parsers and compilers. + * Factory for creating various compiler tools, such as scanners, parsers and + * compilers. *

- * This class provides static methods only; it is not intended to be instantiated or subclassed by clients. + * This class provides static methods only; it is not intended to be + * instantiated or subclassed by clients. *

* * @since 2.0 @@ -29,136 +31,185 @@ import net.sourceforge.phpdt.internal.formatter.CodeFormatter; public class ToolFactory { /** - * Create an instance of a code formatter. A code formatter implementation can be contributed via the - * extension point "org.phpeclipse.phpdt.core.codeFormatter". If unable to find a registered extension, the factory - * will default to using the default code formatter. + * Create an instance of a code formatter. A code formatter implementation + * can be contributed via the extension point + * "org.phpeclipse.phpdt.core.codeFormatter". If unable to find a registered + * extension, the factory will default to using the default code formatter. * * @return an instance of a code formatter * @see ICodeFormatter * @see ToolFactory#createDefaultCodeFormatter(Map) */ - public static ICodeFormatter createCodeFormatter(){ - - Plugin jdtCorePlugin = PHPCore.getPlugin(); - if (jdtCorePlugin == null) return null; - -// IExtensionPoint extension = jdtCorePlugin.getDescriptor().getExtensionPoint(JavaModelManager.FORMATTER_EXTPOINT_ID); -// if (extension != null) { -// IExtension[] extensions = extension.getExtensions(); -// for(int i = 0; i < extensions.length; i++){ -// IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); -// for(int j = 0; j < configElements.length; j++){ -// try { -// Object execExt = configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ -// if (execExt instanceof ICodeFormatter){ -// // use first contribution found -// return (ICodeFormatter)execExt; -// } -// } catch(CoreException e){ -// } -// } -// } -// } - // no proper contribution found, use default formatter + public static ICodeFormatter createCodeFormatter() { + + Plugin jdtCorePlugin = JavaCore.getPlugin(); + if (jdtCorePlugin == null) + return null; + + // IExtensionPoint extension = + // jdtCorePlugin.getDescriptor().getExtensionPoint(JavaModelManager.FORMATTER_EXTPOINT_ID); + // if (extension != null) { + // IExtension[] extensions = extension.getExtensions(); + // for(int i = 0; i < extensions.length; i++){ + // IConfigurationElement [] configElements = + // extensions[i].getConfigurationElements(); + // for(int j = 0; j < configElements.length; j++){ + // try { + // Object execExt = + // configElements[j].createExecutableExtension("class"); //$NON-NLS-1$ + // if (execExt instanceof ICodeFormatter){ + // // use first contribution found + // return (ICodeFormatter)execExt; + // } + // } catch(CoreException e){ + // } + // } + // } + // } + // no proper contribution found, use default formatter return createDefaultCodeFormatter(null); } /** - * Create an instance of the built-in code formatter. A code formatter implementation can be contributed via the - * extension point "org.phpeclipse.phpdt.core.codeFormatter". If unable to find a registered extension, the factory will - * default to using the default code formatter. + * Create an instance of the built-in code formatter. A code formatter + * implementation can be contributed via the extension point + * "org.phpeclipse.phpdt.core.codeFormatter". If unable to find a registered + * extension, the factory will default to using the default code formatter. * - * @param options - the options map to use for formatting with the default code formatter. Recognized options - * are documented on JavaCore#getDefaultOptions(). If set to null, then use - * the current settings from JavaCore#getOptions. + * @param options - + * the options map to use for formatting with the default code + * formatter. Recognized options are documented on + * JavaCore#getDefaultOptions(). If set to + * null, then use the current settings from + * JavaCore#getOptions. * @return an instance of the built-in code formatter * @see ICodeFormatter * @see ToolFactory#createCodeFormatter() * @see JavaCore#getOptions() */ - public static ICodeFormatter createDefaultCodeFormatter(Map options){ + public static ICodeFormatter createDefaultCodeFormatter(Map options) { - if (options == null) options = PHPCore.getOptions(); + if (options == null) + options = JavaCore.getOptions(); return new CodeFormatter(options); } - + /** - * Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be - * used to tokenize some source in a Java aware way. - * Here is a typical scanning loop: + * Create a scanner, indicating the level of detail requested for + * tokenizing. The scanner can then be used to tokenize some source in a + * Java aware way. Here is a typical scanning loop: * * *
-	 *   IScanner scanner = ToolFactory.createScanner(false, false, false, false);
-	 *   scanner.setSource("int i = 0;".toCharArray());
-	 *   while (true) {
-	 *     int token = scanner.getNextToken();
-	 *     if (token == ITerminalSymbols.TokenNameEOF) break;
-	 *     System.out.println(token + " : " + new String(scanner.getCurrentTokenSource()));
-	 *   }
+	 * IScanner scanner = ToolFactory.createScanner(false, false, false, false);
+	 * scanner.setSource("int i = 0;".toCharArray());
+	 * while (true) {
+	 * 	int token = scanner.getNextToken();
+	 * 	if (token == ITerminalSymbols.TokenNameEOF)
+	 * 		break;
+	 * 	System.out.println(token + " : "
+	 * 			+ new String(scanner.getCurrentTokenSource()));
+	 * }
 	 * 
*
* *

- * The returned scanner will tolerate unterminated line comments (missing line separator). It can be made stricter - * by using API with extra boolean parameter (strictCommentMode). + * The returned scanner will tolerate unterminated line comments (missing + * line separator). It can be made stricter by using API with extra boolean + * parameter (strictCommentMode). *

- * @param tokenizeComments if set to false, comments will be silently consumed - * @param tokenizeWhiteSpace if set to false, white spaces will be silently consumed, - * @param assertKeyword if set to false, occurrences of 'assert' will be reported as identifiers - * (ITerminalSymbols#TokenNameIdentifier), whereas if set to true, it - * would report assert keywords (ITerminalSymbols#TokenNameassert). Java 1.4 has introduced - * a new 'assert' keyword. - * @param recordLineSeparator if set to true, the scanner will record positions of encountered line - * separator ends. In case of multi-character line separators, the last character position is considered. These positions - * can then be extracted using IScanner#getLineEnds. Only non-unicode escape sequences are - * considered as valid line separators. - * @return a scanner + * + * @param tokenizeComments + * if set to false, comments will be silently + * consumed + * @param tokenizeWhiteSpace + * if set to false, white spaces will be silently + * consumed, + * @param assertKeyword + * if set to false, occurrences of 'assert' will + * be reported as identifiers (ITerminalSymbols#TokenNameIdentifier), + * whereas if set to true, it would report assert + * keywords (ITerminalSymbols#TokenNameassert). + * Java 1.4 has introduced a new 'assert' keyword. + * @param recordLineSeparator + * if set to true, the scanner will record + * positions of encountered line separator ends. In case of + * multi-character line separators, the last character position + * is considered. These positions can then be extracted using + * IScanner#getLineEnds. Only non-unicode escape + * sequences are considered as valid line separators. + * @return a scanner * @see ToolFactory#createScanner(boolean,boolean,boolean,boolean, boolean) * @see org.phpeclipse.phpdt.core.compiler.IScanner */ -// public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean assertMode, boolean recordLineSeparator){ -// return createScanner(tokenizeComments, tokenizeWhiteSpace, assertMode, recordLineSeparator, false); -// } - + // public static IScanner createScanner(boolean tokenizeComments, boolean + // tokenizeWhiteSpace, boolean recordLineSeparator){ + // return createScanner(tokenizeComments, tokenizeWhiteSpace, + // recordLineSeparator); + // } /** - * Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be - * used to tokenize some source in a Java aware way. - * Here is a typical scanning loop: + * Create a scanner, indicating the level of detail requested for + * tokenizing. The scanner can then be used to tokenize some source in a + * Java aware way. Here is a typical scanning loop: * * *

-	 *   IScanner scanner = ToolFactory.createScanner(false, false, false, false);
-	 *   scanner.setSource("int i = 0;".toCharArray());
-	 *   while (true) {
-	 *     int token = scanner.getNextToken();
-	 *     if (token == ITerminalSymbols.TokenNameEOF) break;
-	 *     System.out.println(token + " : " + new String(scanner.getCurrentTokenSource()));
-	 *   }
+	 * IScanner scanner = ToolFactory.createScanner(false, false, false, false);
+	 * scanner.setSource("int i = 0;".toCharArray());
+	 * while (true) {
+	 * 	int token = scanner.getNextToken();
+	 * 	if (token == ITerminalSymbols.TokenNameEOF)
+	 * 		break;
+	 * 	System.out.println(token + " : "
+	 * 			+ new String(scanner.getCurrentTokenSource()));
+	 * }
 	 * 
* * - * @param tokenizeComments if set to false, comments will be silently consumed - * @param tokenizeWhiteSpace if set to false, white spaces will be silently consumed, - * @param assertMode if set to false, occurrences of 'assert' will be reported as identifiers - * (ITerminalSymbols#TokenNameIdentifier), whereas if set to true, it - * would report assert keywords (ITerminalSymbols#TokenNameassert). Java 1.4 has introduced - * a new 'assert' keyword. - * @param recordLineSeparator if set to true, the scanner will record positions of encountered line - * separator ends. In case of multi-character line separators, the last character position is considered. These positions - * can then be extracted using IScanner#getLineEnds. Only non-unicode escape sequences are - * considered as valid line separators. - * @param strictCommentMode if set to true, line comments with no trailing line separator will be - * treated as invalid tokens. - * @return a scanner + * @param tokenizeComments + * if set to false, comments will be silently + * consumed + * @param tokenizeWhiteSpace + * if set to false, white spaces will be silently + * consumed, + * @param assertMode + * if set to false, occurrences of 'assert' will + * be reported as identifiers (ITerminalSymbols#TokenNameIdentifier), + * whereas if set to true, it would report assert + * keywords (ITerminalSymbols#TokenNameassert). + * Java 1.4 has introduced a new 'assert' keyword. + * @param recordLineSeparator + * if set to true, the scanner will record + * positions of encountered line separator ends. In case of + * multi-character line separators, the last character position + * is considered. These positions can then be extracted using + * IScanner#getLineEnds. Only non-unicode escape + * sequences are considered as valid line separators. + * @param strictCommentMode + * if set to true, line comments with no trailing + * line separator will be treated as invalid tokens. + * @return a scanner * * @see org.phpeclipse.phpdt.core.compiler.IScanner * @since 2.1 */ -// public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean assertMode, boolean recordLineSeparator, boolean strictCommentMode){ -// -// PublicScanner scanner = new PublicScanner(tokenizeComments, tokenizeWhiteSpace, false/*nls*/, assertMode, strictCommentMode /*strict comment*/, null/*taskTags*/, null/*taskPriorities*/); -// scanner.recordLineSeparator = recordLineSeparator; -// return scanner; -// } + public static Scanner createScanner(boolean tokenizeComments, + boolean tokenizeWhiteSpace, boolean recordLineSeparator) { + + Scanner scanner = new Scanner(tokenizeComments, tokenizeWhiteSpace, + false/* nls */); + scanner.recordLineSeparator = recordLineSeparator; + return scanner; + } + + public static Scanner createScanner(boolean tokenizeComments, + boolean tokenizeWhiteSpace, boolean recordLineSeparator, + boolean phpMode) { + + Scanner scanner = new Scanner(tokenizeComments, tokenizeWhiteSpace, + false/* nls */); + scanner.recordLineSeparator = recordLineSeparator; + scanner.setPHPMode(phpMode); + return scanner; + } }