Lines 21-26
Link Here
|
21 |
import org.eclipse.core.resources.IFile; |
21 |
import org.eclipse.core.resources.IFile; |
22 |
import org.eclipse.core.runtime.*; |
22 |
import org.eclipse.core.runtime.*; |
23 |
import org.eclipse.jdt.core.compiler.IScanner; |
23 |
import org.eclipse.jdt.core.compiler.IScanner; |
|
|
24 |
import org.eclipse.jdt.core.compiler.ITerminalSymbols; |
24 |
import org.eclipse.jdt.core.formatter.CodeFormatter; |
25 |
import org.eclipse.jdt.core.formatter.CodeFormatter; |
25 |
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
26 |
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; |
26 |
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; |
27 |
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; |
Lines 377-402
Link Here
|
377 |
* </pre> |
378 |
* </pre> |
378 |
* </code> |
379 |
* </code> |
379 |
* |
380 |
* |
380 |
* <p> |
381 |
* <p>By default the compliance used to create the scanner is the workspace's compliance when running inside the IDE |
381 |
* The returned scanner will tolerate unterminated line comments (missing line separator). It can be made stricter |
382 |
* or 1.4 if running from outside of a headless eclipse. |
382 |
* by using API with extra boolean parameter (<code>strictCommentMode</code>). |
383 |
* </p> |
383 |
* <p> |
384 |
* |
384 |
* @param tokenizeComments if set to <code>false</code>, comments will be silently consumed |
385 |
* @param tokenizeComments if set to <code>false</code>, comments will be silently consumed |
385 |
* @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed, |
386 |
* @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed, |
386 |
* @param assertMode if set to <code>false</code>, occurrences of 'assert' will be reported as identifiers |
387 |
* @param assertMode if set to <code>false</code>, occurrences of 'assert' will be reported as identifiers |
387 |
* (<code>ITerminalSymbols#TokenNameIdentifier</code>), whereas if set to <code>true</code>, it |
388 |
* ({@link ITerminalSymbols#TokenNameIdentifier}), whereas if set to <code>true</code>, it |
388 |
* would report assert keywords (<code>ITerminalSymbols#TokenNameassert</code>). Java 1.4 has introduced |
389 |
* would report assert keywords ({@link ITerminalSymbols#TokenNameassert}). Java 1.4 has introduced |
389 |
* a new 'assert' keyword. |
390 |
* a new 'assert' keyword. |
390 |
* @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line |
391 |
* @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line |
391 |
* separator ends. In case of multi-character line separators, the last character position is considered. These positions |
392 |
* separator ends. In case of multi-character line separators, the last character position is considered. These positions |
392 |
* can then be extracted using <code>IScanner#getLineEnds</code>. Only non-unicode escape sequences are |
393 |
* can then be extracted using {@link IScanner#getLineEnds()}. Only non-unicode escape sequences are |
393 |
* considered as valid line separators. |
394 |
* considered as valid line separators. |
394 |
* @return a scanner |
395 |
* @return a scanner |
395 |
* @see org.eclipse.jdt.core.compiler.IScanner |
396 |
* @see org.eclipse.jdt.core.compiler.IScanner |
|
|
397 |
* @see #createScanner(boolean, boolean, boolean, String, String) |
396 |
*/ |
398 |
*/ |
397 |
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean assertMode, boolean recordLineSeparator){ |
399 |
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean assertMode, boolean recordLineSeparator){ |
398 |
|
400 |
// use default workspace compliance |
399 |
PublicScanner scanner = new PublicScanner(tokenizeComments, tokenizeWhiteSpace, false/*nls*/, assertMode ? ClassFileConstants.JDK1_4 : ClassFileConstants.JDK1_3/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); |
401 |
long complianceLevelValue = CompilerOptions.versionToJdkLevel(JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); |
|
|
402 |
if (complianceLevelValue == 0) complianceLevelValue = ClassFileConstants.JDK1_4; // fault-tolerance |
403 |
PublicScanner scanner = |
404 |
new PublicScanner( |
405 |
tokenizeComments, |
406 |
tokenizeWhiteSpace, |
407 |
false/*nls*/, |
408 |
assertMode ? ClassFileConstants.JDK1_4 : ClassFileConstants.JDK1_3/*sourceLevel*/, |
409 |
complianceLevelValue, |
410 |
null/*taskTags*/, |
411 |
null/*taskPriorities*/, |
412 |
true/*taskCaseSensitive*/); |
400 |
scanner.recordLineSeparator = recordLineSeparator; |
413 |
scanner.recordLineSeparator = recordLineSeparator; |
401 |
return scanner; |
414 |
return scanner; |
402 |
} |
415 |
} |
Lines 418-446
Link Here
|
418 |
* </pre> |
431 |
* </pre> |
419 |
* </code> |
432 |
* </code> |
420 |
* |
433 |
* |
421 |
* <p> |
434 |
* <p>By default the compliance used to create the scanner is the workspace's compliance when running inside the IDE |
422 |
* The returned scanner will tolerate unterminated line comments (missing line separator). It can be made stricter |
435 |
* or 1.4 if running from outside of a headless eclipse. |
423 |
* by using API with extra boolean parameter (<code>strictCommentMode</code>). |
436 |
* </p> |
424 |
* <p> |
437 |
* |
425 |
* @param tokenizeComments if set to <code>false</code>, comments will be silently consumed |
438 |
* @param tokenizeComments if set to <code>false</code>, comments will be silently consumed |
426 |
* @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed, |
439 |
* @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed, |
427 |
* @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line |
440 |
* @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line |
428 |
* separator ends. In case of multi-character line separators, the last character position is considered. These positions |
441 |
* separator ends. In case of multi-character line separators, the last character position is considered. These positions |
429 |
* can then be extracted using <code>IScanner#getLineEnds</code>. Only non-unicode escape sequences are |
442 |
* can then be extracted using {@link IScanner#getLineEnds()}. Only non-unicode escape sequences are |
430 |
* considered as valid line separators. |
443 |
* considered as valid line separators. |
431 |
* @param sourceLevel if set to <code>"1.3"</code> or <code>null</code>, occurrences of 'assert' will be reported as identifiers |
444 |
* @param sourceLevel if set to <code>"1.3"</code> or <code>null</code>, occurrences of 'assert' will be reported as identifiers |
432 |
* (<code>ITerminalSymbols#TokenNameIdentifier</code>), whereas if set to <code>"1.4"</code>, it |
445 |
* ({@link ITerminalSymbols#TokenNameIdentifier}), whereas if set to <code>"1.4"</code>, it |
433 |
* would report assert keywords (<code>ITerminalSymbols#TokenNameassert</code>). Java 1.4 has introduced |
446 |
* would report assert keywords ({@link ITerminalSymbols#TokenNameassert}). Java 1.4 has introduced |
434 |
* a new 'assert' keyword. |
447 |
* a new 'assert' keyword. |
435 |
* @return a scanner |
448 |
* @return a scanner |
436 |
* @see org.eclipse.jdt.core.compiler.IScanner |
449 |
* @see org.eclipse.jdt.core.compiler.IScanner |
437 |
* @since 3.0 |
450 |
* @see #createScanner(boolean, boolean, boolean, String, String) |
|
|
451 |
* @since 3.0 |
438 |
*/ |
452 |
*/ |
439 |
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel) { |
453 |
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel) { |
440 |
PublicScanner scanner = null; |
454 |
// use default workspace compliance |
441 |
long level = CompilerOptions.versionToJdkLevel(sourceLevel); |
455 |
long complianceLevelValue = CompilerOptions.versionToJdkLevel(JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); |
442 |
if (level == 0) level = ClassFileConstants.JDK1_3; // fault-tolerance |
456 |
if (complianceLevelValue == 0) complianceLevelValue = ClassFileConstants.JDK1_4; // fault-tolerance |
443 |
scanner = new PublicScanner(tokenizeComments, tokenizeWhiteSpace, false/*nls*/,level /*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); |
457 |
long sourceLevelValue = CompilerOptions.versionToJdkLevel(sourceLevel); |
|
|
458 |
if (sourceLevelValue == 0) sourceLevelValue = ClassFileConstants.JDK1_3; // fault-tolerance |
459 |
PublicScanner scanner = |
460 |
new PublicScanner( |
461 |
tokenizeComments, |
462 |
tokenizeWhiteSpace, |
463 |
false/*nls*/, |
464 |
sourceLevelValue /*sourceLevel*/, |
465 |
complianceLevelValue, |
466 |
null/*taskTags*/, |
467 |
null/*taskPriorities*/, |
468 |
true/*taskCaseSensitive*/); |
444 |
scanner.recordLineSeparator = recordLineSeparator; |
469 |
scanner.recordLineSeparator = recordLineSeparator; |
445 |
return scanner; |
470 |
return scanner; |
446 |
} |
471 |
} |
Lines 462-494
Link Here
|
462 |
* </pre> |
487 |
* </pre> |
463 |
* </code> |
488 |
* </code> |
464 |
* |
489 |
* |
465 |
* <p> |
|
|
466 |
* The returned scanner will tolerate unterminated line comments (missing line separator). It can be made stricter |
467 |
* by using API with extra boolean parameter (<code>strictCommentMode</code>). |
468 |
* <p> |
469 |
* @param tokenizeComments if set to <code>false</code>, comments will be silently consumed |
490 |
* @param tokenizeComments if set to <code>false</code>, comments will be silently consumed |
470 |
* @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed, |
491 |
* @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed, |
471 |
* @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line |
492 |
* @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line |
472 |
* separator ends. In case of multi-character line separators, the last character position is considered. These positions |
493 |
* separator ends. In case of multi-character line separators, the last character position is considered. These positions |
473 |
* can then be extracted using <code>IScanner#getLineEnds</code>. Only non-unicode escape sequences are |
494 |
* can then be extracted using {@link IScanner#getLineEnds()}. Only non-unicode escape sequences are |
474 |
* considered as valid line separators. |
495 |
* considered as valid line separators. |
475 |
* @param sourceLevel if set to <code>"1.3"</code> or <code>null</code>, occurrences of 'assert' will be reported as identifiers |
496 |
* @param sourceLevel if set to <code>"1.3"</code> or <code>null</code>, occurrences of 'assert' will be reported as identifiers |
476 |
* (<code>ITerminalSymbols#TokenNameIdentifier</code>), whereas if set to <code>"1.4"</code>, it |
497 |
* ({@link ITerminalSymbols#TokenNameIdentifier}), whereas if set to <code>"1.4"</code>, it |
477 |
* would report assert keywords (<code>ITerminalSymbols#TokenNameassert</code>). Java 1.4 has introduced |
498 |
* would report assert keywords ({@link ITerminalSymbols#TokenNameassert}). Java 1.4 has introduced |
478 |
* a new 'assert' keyword. |
499 |
* a new 'assert' keyword. |
479 |
* @param complianceLevel This is used to support the Unicode 4.0 character sets. if set to 1.5 or above, |
500 |
* @param complianceLevel This is used to support the Unicode 4.0 character sets. if set to 1.5 or above, |
480 |
* the Unicode 4.0 is supporte, otherwise Unicode 3.0 is supported. |
501 |
* the Unicode 4.0 is supporte, otherwise Unicode 3.0 is supported. |
481 |
* @return a scanner |
502 |
* @return a scanner |
482 |
* @see org.eclipse.jdt.core.compiler.IScanner |
503 |
* @see org.eclipse.jdt.core.compiler.IScanner |
483 |
* |
504 |
* |
484 |
* @since 3.1 |
505 |
* @since 3.1 |
485 |
*/ |
506 |
*/ |
486 |
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel, String complianceLevel) { |
507 |
public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel, String complianceLevel) { |
487 |
PublicScanner scanner = null; |
508 |
PublicScanner scanner = null; |
488 |
long sourceLevelValue = CompilerOptions.versionToJdkLevel(sourceLevel); |
509 |
long sourceLevelValue = CompilerOptions.versionToJdkLevel(sourceLevel); |
489 |
if (sourceLevelValue == 0) sourceLevelValue = ClassFileConstants.JDK1_3; // fault-tolerance |
510 |
if (sourceLevelValue == 0) sourceLevelValue = ClassFileConstants.JDK1_3; // fault-tolerance |
490 |
long complianceLevelValue = CompilerOptions.versionToJdkLevel(complianceLevel); |
511 |
long complianceLevelValue = CompilerOptions.versionToJdkLevel(complianceLevel); |
491 |
if (complianceLevelValue == 0) complianceLevelValue = ClassFileConstants.JDK1_3; // fault-tolerance |
512 |
if (complianceLevelValue == 0) complianceLevelValue = ClassFileConstants.JDK1_4; // fault-tolerance |
492 |
scanner = new PublicScanner(tokenizeComments, tokenizeWhiteSpace, false/*nls*/,sourceLevelValue /*sourceLevel*/, complianceLevelValue, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); |
513 |
scanner = new PublicScanner(tokenizeComments, tokenizeWhiteSpace, false/*nls*/,sourceLevelValue /*sourceLevel*/, complianceLevelValue, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); |
493 |
scanner.recordLineSeparator = recordLineSeparator; |
514 |
scanner.recordLineSeparator = recordLineSeparator; |
494 |
return scanner; |
515 |
return scanner; |