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

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


  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


  return null;
}

private static SearchPattern createTypePattern(String patternString, int limitTo, int matchRule, char indexSuffix) {

  Scanner scanner = new Scanner(false /*comment*/, true /*whitespace*/, false /*nls*/, ClassFileConstants.JDK1_3/*sourceLevel*/, null /*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
  scanner.setSource(patternString.toCharArray());
  String type = null;
  int token;
  try {
    token = scanner.getNextToken();
  } catch (InvalidInputException e) {
    return null;
  }
  int argCount = 0;
  while (token != TerminalTokens.TokenNameEOF) {
    if (argCount == 0) {
      switch (token) {
        case TerminalTokens.TokenNameWHITESPACE:
          break;
        case TerminalTokens.TokenNameLESS:
          argCount++;
          // $FALL-THROUGH$ - fall through default case to add token to type
        default: // all other tokens are considered identifiers (see bug 21763 Problem in Java search [search])
          if (type == null)
            type = scanner.getCurrentTokenString();
          else
            type += scanner.getCurrentTokenString();
      }
    } else {
      switch (token) {
        case TerminalTokens.TokenNameGREATER:
        case TerminalTokens.TokenNameRIGHT_SHIFT:
        case TerminalTokens.TokenNameUNSIGNED_RIGHT_SHIFT:
          argCount--;
          break;
        case TerminalTokens.TokenNameLESS:
          argCount++;
          break;
      }
      if (type == null) return null; // invalid syntax
      type += scanner.getCurrentTokenString();
    }
    try {
      token = scanner.getNextToken();
    } catch (InvalidInputException e) {
      return null;
    }
  }
  if (type == null) return null;
View Full Code Here

  ICompilationUnit compilationUnit = compilationResult.getCompilationUnit();
  if (compilationUnit == null) return start;
  char[] contents = compilationUnit.getContents();
  if (contents.length == 0) return start;
  if (this.positionScanner == null) {
    this.positionScanner = new Scanner(false, false, false, this.options.sourceLevel, this.options.complianceLevel, null, null, false);
    this.positionScanner.returnOnlyGreater = true;
  }
  this.positionScanner.setSource(contents);
  this.positionScanner.resetTo(start, contents.length);
  int end = start;
View Full Code Here

  ICompilationUnit compilationUnit = compilationResult.getCompilationUnit();
  if (compilationUnit == null) return sourceEnd;
  char[] contents = compilationUnit.getContents();
  if (contents.length == 0) return sourceEnd;
  if (this.positionScanner == null) {
    this.positionScanner = new Scanner(false, false, false, this.options.sourceLevel, this.options.complianceLevel, null, null, false);
  }
  this.positionScanner.setSource(contents);
  this.positionScanner.resetTo(sourceStart, sourceEnd);
  try {
    int token;
View Full Code Here

  ICompilationUnit compilationUnit = compilationResult.getCompilationUnit();
  if (compilationUnit == null) return sourceStart;
  char[] contents = compilationUnit.getContents();
  if (contents.length == 0) return sourceStart;
  if (this.positionScanner == null) {
    this.positionScanner = new Scanner(false, false, false, this.options.sourceLevel, this.options.complianceLevel, null, null, false);
  }
  this.positionScanner.setSource(contents);
  this.positionScanner.resetTo(sourceStart, sourceEnd);
  int count = 0;
  try {
View Full Code Here

    NoArgument,
    methodDecl.returnType.sourceStart,
    methodDecl.returnType.sourceEnd);
}
public void scannerError(Parser parser, String errorTokenName) {
  Scanner scanner = parser.scanner;

  int flag = IProblem.ParsingErrorNoSuggestion;
  int startPos = scanner.startPosition;
  int endPos = scanner.currentPosition - 1;
View Full Code Here

  return new AndPattern(leftPattern, rightPattern);
}

private static SearchPattern createFieldPattern(String patternString, int limitTo, int matchRule) {

  Scanner scanner = new Scanner(false /*comment*/, true /*whitespace*/, false /*nls*/, ClassFileConstants.JDK1_3/*sourceLevel*/, null /*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
  scanner.setSource(patternString.toCharArray());
  final int InsideDeclaringPart = 1;
  final int InsideType = 2;
  int lastToken = -1;

  String declaringType = null, fieldName = null;
  String type = null;
  int mode = InsideDeclaringPart;
  int token;
  try {
    token = scanner.getNextToken();
  } catch (InvalidInputException e) {
    return null;
  }
  while (token != TerminalTokens.TokenNameEOF) {
    switch(mode) {
      // read declaring type and fieldName
      case InsideDeclaringPart :
        switch (token) {
          case TerminalTokens.TokenNameDOT:
            if (declaringType == null) {
              if (fieldName == null) return null;
              declaringType = fieldName;
            } else {
              String tokenSource = scanner.getCurrentTokenString();
              declaringType += tokenSource + fieldName;
            }
            fieldName = null;
            break;
          case TerminalTokens.TokenNameWHITESPACE:
            if (!(TerminalTokens.TokenNameWHITESPACE == lastToken || TerminalTokens.TokenNameDOT == lastToken))
              mode = InsideType;
            break;
          default: // all other tokens are considered identifiers (see bug 21763 Problem in Java search [search])
            if (fieldName == null)
              fieldName = scanner.getCurrentTokenString();
            else
              fieldName += scanner.getCurrentTokenString();
        }
        break;
      // read type
      case InsideType:
        switch (token) {
          case TerminalTokens.TokenNameWHITESPACE:
            break;
          default: // all other tokens are considered identifiers (see bug 21763 Problem in Java search [search])
            if (type == null)
              type = scanner.getCurrentTokenString();
            else
              type += scanner.getCurrentTokenString();
        }
        break;
    }
    lastToken = token;
    try {
      token = scanner.getNextToken();
    } catch (InvalidInputException e) {
      return null;
    }
  }
  if (fieldName == null) return null;
View Full Code Here

      matchRule);
}

private static SearchPattern createMethodOrConstructorPattern(String patternString, int limitTo, int matchRule, boolean isConstructor) {

  Scanner scanner = new Scanner(false /*comment*/, true /*whitespace*/, false /*nls*/, ClassFileConstants.JDK1_3/*sourceLevel*/, null /*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
  scanner.setSource(patternString.toCharArray());
  final int InsideSelector = 1;
  final int InsideTypeArguments = 2;
  final int InsideParameter = 3;
  final int InsideReturnType = 4;
  int lastToken = -1;

  String declaringType = null, selector = null, parameterType = null;
  String[] parameterTypes = null;
  char[][] typeArguments = null;
  String typeArgumentsString = null;
  int parameterCount = -1;
  String returnType = null;
  boolean foundClosingParenthesis = false;
  int mode = InsideSelector;
  int token, argCount = 0;
  try {
    token = scanner.getNextToken();
  } catch (InvalidInputException e) {
    return null;
  }
  while (token != TerminalTokens.TokenNameEOF) {
    switch(mode) {
      // read declaring type and selector
      case InsideSelector :
        if (argCount == 0) {
          switch (token) {
            case TerminalTokens.TokenNameLESS:
              argCount++;
              if (selector == null || lastToken == TerminalTokens.TokenNameDOT) {
                typeArgumentsString = scanner.getCurrentTokenString();
                mode = InsideTypeArguments;
                break;
              }
              if (declaringType == null) {
                declaringType = selector;
              } else {
                declaringType += '.' + selector;
              }
              declaringType += scanner.getCurrentTokenString();
              selector = null;
              break;
            case TerminalTokens.TokenNameDOT:
              if (!isConstructor && typeArgumentsString != null) return null; // invalid syntax
              if (declaringType == null) {
                if (selector == null) return null; // invalid syntax
                declaringType = selector;
              } else if (selector != null) {
                declaringType += scanner.getCurrentTokenString() + selector;
              }
              selector = null;
              break;
            case TerminalTokens.TokenNameLPAREN:
              parameterTypes = new String[5];
              parameterCount = 0;
              mode = InsideParameter;
              break;
            case TerminalTokens.TokenNameWHITESPACE:
              switch (lastToken) {
                case TerminalTokens.TokenNameWHITESPACE:
                case TerminalTokens.TokenNameDOT:
                case TerminalTokens.TokenNameGREATER:
                case TerminalTokens.TokenNameRIGHT_SHIFT:
                case TerminalTokens.TokenNameUNSIGNED_RIGHT_SHIFT:
                  break;
                default:
                  mode = InsideReturnType;
                  break;
              }
              break;
            default: // all other tokens are considered identifiers (see bug 21763 Problem in Java search [search])
              if (selector == null)
                selector = scanner.getCurrentTokenString();
              else
                selector += scanner.getCurrentTokenString();
              break;
          }
        } else {
          if (declaringType == null) return null; // invalid syntax
          switch (token) {
            case TerminalTokens.TokenNameGREATER:
            case TerminalTokens.TokenNameRIGHT_SHIFT:
            case TerminalTokens.TokenNameUNSIGNED_RIGHT_SHIFT:
              argCount--;
              break;
            case TerminalTokens.TokenNameLESS:
              argCount++;
              break;
          }
          declaringType += scanner.getCurrentTokenString();
        }
        break;
      // read type arguments
      case InsideTypeArguments:
        if (typeArgumentsString == null) return null; // invalid syntax
        typeArgumentsString += scanner.getCurrentTokenString();
        switch (token) {
          case TerminalTokens.TokenNameGREATER:
          case TerminalTokens.TokenNameRIGHT_SHIFT:
          case TerminalTokens.TokenNameUNSIGNED_RIGHT_SHIFT:
            argCount--;
            if (argCount == 0) {
              String pseudoType = "Type"+typeArgumentsString; //$NON-NLS-1$
              typeArguments = Signature.getTypeArguments(Signature.createTypeSignature(pseudoType, false).toCharArray());
              mode = InsideSelector;
            }
            break;
          case TerminalTokens.TokenNameLESS:
            argCount++;
            break;
        }
        break;
      // read parameter types
      case InsideParameter :
        if (argCount == 0) {
          switch (token) {
            case TerminalTokens.TokenNameWHITESPACE:
              break;
            case TerminalTokens.TokenNameCOMMA:
              if (parameterType == null) return null;
              if (parameterTypes != null) {
                if (parameterTypes.length == parameterCount)
                  System.arraycopy(parameterTypes, 0, parameterTypes = new String[parameterCount*2], 0, parameterCount);
                parameterTypes[parameterCount++] = parameterType;
              }
              parameterType = null;
              break;
            case TerminalTokens.TokenNameRPAREN:
              foundClosingParenthesis = true;
              if (parameterType != null && parameterTypes != null) {
                if (parameterTypes.length == parameterCount)
                  System.arraycopy(parameterTypes, 0, parameterTypes = new String[parameterCount*2], 0, parameterCount);
                parameterTypes[parameterCount++] = parameterType;
              }
              mode = isConstructor ? InsideTypeArguments : InsideReturnType;
              break;
            case TerminalTokens.TokenNameLESS:
              argCount++;
              if (parameterType == null) return null; // invalid syntax
              // $FALL-THROUGH$ - fall through next case to add token
            default: // all other tokens are considered identifiers (see bug 21763 Problem in Java search [search])
              if (parameterType == null)
                parameterType = scanner.getCurrentTokenString();
              else
                parameterType += scanner.getCurrentTokenString();
          }
        } else {
          if (parameterType == null) return null; // invalid syntax
          switch (token) {
            case TerminalTokens.TokenNameGREATER:
            case TerminalTokens.TokenNameRIGHT_SHIFT:
            case TerminalTokens.TokenNameUNSIGNED_RIGHT_SHIFT:
              argCount--;
              break;
            case TerminalTokens.TokenNameLESS:
              argCount++;
              break;
          }
          parameterType += scanner.getCurrentTokenString();
        }
        break;
      // read return type
      case InsideReturnType:
        if (argCount == 0) {
          switch (token) {
            case TerminalTokens.TokenNameWHITESPACE:
              break;
            case TerminalTokens.TokenNameLPAREN:
              parameterTypes = new String[5];
              parameterCount = 0;
              mode = InsideParameter;
              break;
            case TerminalTokens.TokenNameLESS:
              argCount++;
              if (returnType == null) return null; // invalid syntax
              // $FALL-THROUGH$ - fall through next case to add token
            default: // all other tokens are considered identifiers (see bug 21763 Problem in Java search [search])
              if (returnType == null)
                returnType = scanner.getCurrentTokenString();
              else
                returnType += scanner.getCurrentTokenString();
          }
        } else {
          if (returnType == null) return null; // invalid syntax
          switch (token) {
            case TerminalTokens.TokenNameGREATER:
            case TerminalTokens.TokenNameRIGHT_SHIFT:
            case TerminalTokens.TokenNameUNSIGNED_RIGHT_SHIFT:
              argCount--;
              break;
            case TerminalTokens.TokenNameLESS:
              argCount++;
              break;
          }
          returnType += scanner.getCurrentTokenString();
        }
        break;
    }
    lastToken = token;
    try {
      token = scanner.getNextToken();
    } catch (InvalidInputException e) {
      return null;
    }
  }
  // parenthesis mismatch
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

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.