Package org.eclipse.jdt.internal.compiler.parser

Examples of org.eclipse.jdt.internal.compiler.parser.Scanner$VanguardParser


  // perform final changes to the open and close body ranges
  int openBodyEnd, openBodyStart, closeBodyStart, closeBodyEnd;
  DOMNode first = (DOMNode) getFirstChild();
  DOMNode lastNode = null;
  // look for the open body
  Scanner scanner = new Scanner();
  scanner.setSource(this.fDocument);
  scanner.resetTo(this.fNameRange[1] + 1, this.fDocument.length);

  try {
    int currentToken = scanner.getNextToken();
    while(currentToken != TerminalTokens.TokenNameLBRACE &&
        currentToken != TerminalTokens.TokenNameEOF) {
      currentToken = scanner.getNextToken();
    }
    if(currentToken == TerminalTokens.TokenNameLBRACE) {
      openBodyEnd = scanner.currentPosition - 1;
      openBodyStart = scanner.startPosition;
    } else {
      openBodyEnd = this.fDocument.length;
      openBodyStart = this.fDocument.length;
    }
  } catch(InvalidInputException e) {
    openBodyEnd = this.fDocument.length;
    openBodyStart = this.fDocument.length;
  }
  if (first != null) {
    int lineStart = finder.getLineStart(first.getStartPosition());
    if (lineStart > openBodyEnd) {
      openBodyEnd = lineStart - 1;
    } else {
      openBodyEnd = first.getStartPosition() - 1;
    }
    lastNode = (DOMNode) first.getNextNode();
    if (lastNode == null) {
      lastNode = first;
    } else {
      while (lastNode.getNextNode() != null) {
        lastNode = (DOMNode) lastNode.getNextNode();
      }
    }
    scanner.setSource(this.fDocument);
    scanner.resetTo(lastNode.getEndPosition() + 1, this.fDocument.length);
    try {
      int currentToken = scanner.getNextToken();
      while(currentToken != TerminalTokens.TokenNameRBRACE &&
          currentToken != TerminalTokens.TokenNameEOF) {
        currentToken = scanner.getNextToken();
      }
      if(currentToken == TerminalTokens.TokenNameRBRACE) {
        closeBodyStart = scanner.startPosition;
        closeBodyEnd = scanner.currentPosition - 1;
      } else {
        closeBodyStart = this.fDocument.length;
        closeBodyEnd = this.fDocument.length;
      }
    } catch(InvalidInputException e) {
      closeBodyStart = this.fDocument.length;
      closeBodyEnd = this.fDocument.length;
    }
  } else {
    scanner.resetTo(openBodyEnd, this.fDocument.length);
    try {
      int currentToken = scanner.getNextToken();
      while(currentToken != TerminalTokens.TokenNameRBRACE &&
          currentToken != TerminalTokens.TokenNameEOF) {
        currentToken = scanner.getNextToken();
      }
      if(currentToken == TerminalTokens.TokenNameRBRACE) {
        closeBodyStart = scanner.startPosition;
        closeBodyEnd = scanner.currentPosition - 1;
      } else {
View Full Code Here


  /* (non-Javadoc)
   * Create and store a specific comment recorder scanner.
   * @see org.eclipse.jdt.internal.compiler.parser.Parser#initializeScanner()
   */
  public void initializeScanner() {
    this.scanner = new Scanner(
        false /*comment*/,
        false /*whitespace*/,
        this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/,
        this.options.sourceLevel /*sourceLevel*/,
        this.options.taskTags/*taskTags*/,
 
View Full Code Here

              break;
          }
        }
      }
    }
    this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, taskTags, null/*taskPriorities*/, true/*taskCaseSensitive*/);
    this.editsEnabled = true;
  }
View Full Code Here

  public void setEscapedValue(String token) {
    // update internalSetEscapedValue(String) if this is changed
    if (token == null) {
      throw new IllegalArgumentException("Token cannot be null"); //$NON-NLS-1$
    }
    Scanner scanner = this.ast.scanner;
    char[] source = token.toCharArray();
    scanner.setSource(source);
    scanner.resetTo(0, source.length);
    try {
      int tokenType = scanner.getNextToken();
      switch(tokenType) {
        case TerminalTokens.TokenNameStringLiteral:
          break;
        default:
          throw new IllegalArgumentException("Invalid string literal : >" + token + "<"); //$NON-NLS-1$//$NON-NLS-2$
View Full Code Here

    int len = s.length();
    if (len < 2 || s.charAt(0) != '\"' || s.charAt(len-1) != '\"' ) {
      throw new IllegalArgumentException();
    }

    Scanner scanner = this.ast.scanner;
    char[] source = s.toCharArray();
    scanner.setSource(source);
    scanner.resetTo(0, source.length);
    try {
      int tokenType = scanner.getNextToken();
      switch(tokenType) {
        case TerminalTokens.TokenNameStringLiteral:
          return scanner.getCurrentStringLiteral();
        default:
          throw new IllegalArgumentException();
      }
    } catch(InvalidInputException e) {
      throw new IllegalArgumentException();
View Full Code Here

   * comments with statements.
   */
  public void setLeadingComment(String comment) {
    if (comment != null) {
      char[] source = comment.toCharArray();
      Scanner scanner = this.ast.scanner;
      scanner.resetTo(0, source.length);
      scanner.setSource(source);
      try {
        int token;
        boolean onlyOneComment = false;
        while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
          switch(token) {
            case TerminalTokens.TokenNameCOMMENT_BLOCK :
            case TerminalTokens.TokenNameCOMMENT_JAVADOC :
            case TerminalTokens.TokenNameCOMMENT_LINE :
              if (onlyOneComment) {
View Full Code Here

    long sourceLevel = CompilerOptions.versionToJdkLevel(sourceModeSetting);
    if (sourceLevel == 0) {
      // unknown sourceModeSetting
      sourceLevel = ClassFileConstants.JDK1_3;
    }
    this.scanner = new Scanner(
      true /*comment*/,
      false /*whitespace*/,
      false /*nls*/,
      sourceLevel /*sourceLevel*/,
      null /*taskTags*/,
 
View Full Code Here

    int end = expression.sourceEnd;
    int token;
    int trimLeftPosition = expression.sourceStart;
    int trimRightPosition = expression.sourceEnd;
    boolean first = true;
    Scanner removeBlankScanner = this.ast.scanner;
    try {
      removeBlankScanner.setSource(this.compilationUnitSource);
      removeBlankScanner.resetTo(start, end);
      while (true) {
        token = removeBlankScanner.getNextToken();
        switch (token) {
          case TerminalTokens.TokenNameCOMMENT_JAVADOC :
          case TerminalTokens.TokenNameCOMMENT_LINE :
          case TerminalTokens.TokenNameCOMMENT_BLOCK :
            if (first) {
View Full Code Here

  private  boolean isValidPackageNameForClass(String className) {
    char[] classNameArray = className.toCharArray();
    // use 1.7 as the source level as there are more valid identifiers in 1.7 mode
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=376673
    if (this.scanner == null)
      this.scanner = new Scanner(false /* comment */, true /* whitespace */, false /* nls */,
          ClassFileConstants.JDK1_7/* sourceLevel */, null/* taskTag */, null/* taskPriorities */, true /* taskCaseSensitive */);
   
    this.scanner.setSource(classNameArray);
    this.scanner.eofPosition = classNameArray.length - SuffixConstants.SUFFIX_CLASS.length;
    try {
View Full Code Here

  private TextEdit probeFormatting(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
    if (PROBING_SCANNER == null) {
      // scanner use to check if the kind could be K_JAVA_DOC, K_MULTI_LINE_COMMENT or K_SINGLE_LINE_COMMENT
      // do not tokenize white spaces to get single comments even with spaces before...
      PROBING_SCANNER = new Scanner(true, false/*do not tokenize whitespaces*/, false/*nls*/, ClassFileConstants.JDK1_6, ClassFileConstants.JDK1_6, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
    }
    PROBING_SCANNER.setSource(source.toCharArray());

    IRegion coveredRegion = getCoveredRegion(regions);
    int offset = coveredRegion.getOffset();
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.parser.Scanner$VanguardParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.