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

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


  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

}

private static SearchPattern createFieldPattern(String patternString, int limitTo, int matchRule) {
  // use 1.7 as the source level as there are more valid tokens in 1.7 mode
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=376673
  Scanner scanner = new Scanner(false /*comment*/, true /*whitespace*/, false /*nls*/, ClassFileConstants.JDK1_7/*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

}

private static SearchPattern createMethodOrConstructorPattern(String patternString, int limitTo, int matchRule, boolean isConstructor) {
  // use 1.7 as the source level as there are more valid tokens in 1.7 mode
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=376673
  Scanner scanner = new Scanner(false /*comment*/, true /*whitespace*/, false /*nls*/, ClassFileConstants.JDK1_7/*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

}

private static SearchPattern createTypePattern(String patternString, int limitTo, int matchRule, char indexSuffix) {
  // use 1.7 as the source level as there are more valid tokens in 1.7 mode
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=376673
  Scanner scanner = new Scanner(false /*comment*/, true /*whitespace*/, false /*nls*/, ClassFileConstants.JDK1_7/*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

  public void setToken(String token) {
    // update internalSetToken(String) if this is changed
    if (token == null || token.length() == 0) {
      throw new IllegalArgumentException();
    }
    Scanner scanner = this.ast.scanner;
    char[] source = token.toCharArray();
    scanner.setSource(source);
    scanner.resetTo(0, source.length);
    scanner.tokenizeComments = false;
    scanner.tokenizeWhiteSpace = false;
    try {
      int tokenType = scanner.getNextToken();
      switch(tokenType) {
        case TerminalTokens.TokenNameDoubleLiteral:
        case TerminalTokens.TokenNameIntegerLiteral:
        case TerminalTokens.TokenNameFloatingPointLiteral:
        case TerminalTokens.TokenNameLongLiteral:
          break;
        case TerminalTokens.TokenNameMINUS :
          tokenType = scanner.getNextToken();
          switch(tokenType) {
            case TerminalTokens.TokenNameDoubleLiteral:
            case TerminalTokens.TokenNameIntegerLiteral:
            case TerminalTokens.TokenNameFloatingPointLiteral:
            case TerminalTokens.TokenNameLongLiteral:
View Full Code Here

  public void setIdentifier(String identifier) {
    // update internalSetIdentifier if this is changed
    if (identifier == null) {
      throw new IllegalArgumentException();
    }
    Scanner scanner = this.ast.scanner;
    long sourceLevel = scanner.sourceLevel;
    long complianceLevel = scanner.complianceLevel;

    try {
      scanner.sourceLevel = ClassFileConstants.JDK1_3;
      scanner.complianceLevel = ClassFileConstants.JDK1_5;
      char[] source = identifier.toCharArray();
      scanner.setSource(source);
      final int length = source.length;
      scanner.resetTo(0, length - 1);
      try {
        int tokenType = scanner.scanIdentifier();
        if (tokenType != TerminalTokens.TokenNameIdentifier) {
          throw new IllegalArgumentException();
        }
        if (scanner.currentPosition != length) {
          // this is the case when there is only one identifier see 87849
View Full Code Here

    switch(level) {
      case JLS2_INTERNAL :
      case JLS3_INTERNAL :
        this.apiLevel = level;
        // initialize a scanner
        this.scanner = new Scanner(
            true /*comment*/,
            true /*whitespace*/,
            false /*nls*/,
            ClassFileConstants.JDK1_3 /*sourceLevel*/,
            ClassFileConstants.JDK1_5 /*complianceLevel*/,
            null/*taskTag*/,
            null/*taskPriorities*/,
            true/*taskCaseSensitive*/);
        break;
      case JLS4 :
        this.apiLevel = level;
        // initialize a scanner
        this.scanner = new Scanner(
            true /*comment*/,
            true /*whitespace*/,
            false /*nls*/,
            ClassFileConstants.JDK1_7 /*sourceLevel*/,
            ClassFileConstants.JDK1_7 /*complianceLevel*/,
 
View Full Code Here

      complianceLevel = ClassFileConstants.JDK1_5;
    } else if (JavaCore.VERSION_1_7.equals(complianceLevelOption)) {
      complianceLevel = ClassFileConstants.JDK1_7;
    }
    // override scanner if 1.4 or 1.5 asked for
    this.scanner = new Scanner(
      true /*comment*/,
      true /*whitespace*/,
      false /*nls*/,
      sourceLevel /*sourceLevel*/,
      complianceLevel /*complianceLevel*/,
 
View Full Code Here

TOP

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

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.