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

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


      internalPrefix = removePrefix(internalPrefix, prefixes);
    }

    char[][] tempNames = null;
   
    Scanner nameScanner = getNameScanner(compilerOptions);
    if (baseNameKind == BK_SIMPLE_TYPE_NAME) {
      boolean isBaseType = false;
     
      try{
        nameScanner.setSource(baseName);
        switch (nameScanner.getNextToken()) {
          case TerminalTokens.TokenNameint :
          case TerminalTokens.TokenNamebyte :
          case TerminalTokens.TokenNameshort :
          case TerminalTokens.TokenNamechar :
          case TerminalTokens.TokenNamelong :
          case TerminalTokens.TokenNamefloat :
          case TerminalTokens.TokenNamedouble :
          case TerminalTokens.TokenNameboolean :
            isBaseType = true;
            break;
        }
      } catch(InvalidInputException e){
        // ignore
      }
      if (isBaseType) {
        // compute variable name from base type
        if (internalPrefix.length > 0) return;
 
        tempNames = computeBaseTypeNames(baseName, isConstantField, excluded);
      } else {
        // compute variable name for non base type
        tempNames = computeNonBaseTypeNames(baseName, isConstantField, false);
      }
    } else {
      tempNames = computeNonBaseTypeNames(baseName, isConstantField, true);
    }

    boolean acceptDefaultName = true;
    SimpleSetOfCharArray foundNames = new SimpleSetOfCharArray();

    for (int i = 0; i < tempNames.length; i++) {
      char[] tempName = tempNames[i];
     
      // add English plural form is necessary
      if(dim > 0) {
        int length = tempName.length;
       
        if (isConstantField) {
          if (tempName[length-1] == 'S'){
            if(tempName.length > 1 && tempName[length-2] == 'S') {
              System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
              tempName[length] = 'E';
              tempName[length+1] = 'S';
            }
          } else if(tempName[length-1] == 'Y') {
            boolean precededByAVowel = false;
            if(tempName.length > 1) {
              switch (tempName[length-2]) {
                case 'A':
                case 'E':
                case 'I':
                case 'O':
                case 'U':
                  precededByAVowel = true;
                  break;
              }
            }
            if (precededByAVowel) {
              System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
              tempName[length] = 'S';
            } else {
              System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
              tempName[length-1] = 'I';
              tempName[length] = 'E';
              tempName[length+1] = 'S';
            }
          } else {
            System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
            tempName[length] = 'S';
          }
        } else {
          if (tempName[length-1] == 's'){
            if(tempName.length > 1 && tempName[length-2] == 's') {
              System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
              tempName[length] = 'e';
              tempName[length+1] = 's';
            }
          } else if(tempName[length-1] == 'y') {
            boolean precededByAVowel = false;
            if(tempName.length > 1) {
              switch (tempName[length-2]) {
                case 'a':
                case 'e':
                case 'i':
                case 'o':
                case 'u':
                  precededByAVowel = true;
                  break;
              }
            }
            if (precededByAVowel) {
              System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
              tempName[length] = 's';
            } else {
              System.arraycopy(tempName, 0, tempName = new char[length + 2], 0, length);
              tempName[length-1] = 'i';
              tempName[length] = 'e';
              tempName[length+1] = 's';
            }
          } else {
            System.arraycopy(tempName, 0, tempName = new char[length + 1], 0, length);
            tempName[length] = 's';
          }
        }
      }
     
      char[] unprefixedName = tempName;
     
      int matchingIndex = -1;
      if (!isConstantField) {
        unprefixedName[0] = ScannerHelper.toUpperCase(unprefixedName[0]);
       
        done : for (int j = 0; j <= internalPrefix.length; j++) {
          if(j == internalPrefix.length ||
              CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) {
            matchingIndex = j;
            break done;
          }
        }
      } else {
        done : for (int j = 0; j <= internalPrefix.length; j++) {
          if(j == internalPrefix.length) {
            matchingIndex = j;
            break done;
          } else if(CharOperation.prefixEquals(CharOperation.subarray(internalPrefix, j, -1), unprefixedName, j != 0 /*do not check case when there is no prefix*/)) {
            if (j == 0 || internalPrefix[j - 1] == '_') {
              matchingIndex = j;
              break done;
            }
           
          }
        }
      }

      if(matchingIndex > -1) {
        if (!isConstantField) {
          tempName = CharOperation.concat(CharOperation.subarray(internalPrefix, 0, matchingIndex), unprefixedName);
          if(matchingIndex == 0) tempName[0] = ScannerHelper.toLowerCase(tempName[0]);
        } else {
          if(matchingIndex != 0 && tempName[0] != '_' && internalPrefix[matchingIndex - 1] != '_') {
            tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName, '_');
          } else {
            tempName = CharOperation.concat(CharOperation.subarray(CharOperation.toUpperCase(internalPrefix), 0, matchingIndex), unprefixedName);
          }
        }
       
        for (int k = 0; k < prefixes.length; k++) {
          if (!isConstantField) {
            if(prefixes[k].length > 0
              && ScannerHelper.isLetterOrDigit(prefixes[k][prefixes[k].length - 1])) {
              tempName[0] = ScannerHelper.toUpperCase(tempName[0]);
            } else {
              tempName[0] = ScannerHelper.toLowerCase(tempName[0]);
            }
          }
          char[] prefixName = CharOperation.concat(prefixes[k], tempName);
          for (int l = 0; l < suffixes.length; l++) {
            char[] suffixName = CharOperation.concat(prefixName, suffixes[l]);
            suffixName =
              excludeNames(
                suffixName,
                prefixName,
                suffixes[l],
                excluded);
            try{
              nameScanner.setSource(suffixName);
              switch (nameScanner.getNextToken()) {
                case TerminalTokens.TokenNameIdentifier :
                  int token = nameScanner.getNextToken();
                  if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) {
                    if (!foundNames.includes(suffixName)) {
                      acceptName(suffixName, prefixes[k], suffixes[l],  k == 0, l == 0, internalPrefix.length - matchingIndex, requestor);
                      foundNames.add(suffixName);
                      acceptDefaultName = false;
                    }
                  }
                  break;
                default:
                  suffixName = CharOperation.concat(
                    prefixName,
                    String.valueOf(1).toCharArray(),
                    suffixes[l]
                  );
                  suffixName =
                    excludeNames(
                      suffixName,
                      prefixName,
                      suffixes[l],
                      excluded);
                  nameScanner.setSource(suffixName);
                  switch (nameScanner.getNextToken()) {
                    case TerminalTokens.TokenNameIdentifier :
                      token = nameScanner.getNextToken();
                      if (token == TerminalTokens.TokenNameEOF && nameScanner.startPosition == suffixName.length) {
                        if (!foundNames.includes(suffixName)) {
                          acceptName(suffixName, prefixes[k], suffixes[l], k == 0, l == 0, internalPrefix.length - matchingIndex, requestor);
                          foundNames.add(suffixName);
                          acceptDefaultName = false;
View Full Code Here


  }

  final TokenScanner getScanner() {
    if (this.tokenScanner == null) {
      CompilerOptions compilerOptions = new CompilerOptions(this.options);
      Scanner scanner;
      if (this.recoveryScannerData == null) {
        scanner =
          new Scanner(
              true,/*tokenizeComments*/
              false,/*tokenizeWhiteSpace*/
              false,/*checkNonExternalizedStringLiterals*/
              compilerOptions.sourceLevel,
              compilerOptions.complianceLevel,
              null/*taskTags*/,
              null/*taskPriorities*/,
              true/*taskCaseSensitive*/);
      } else {
        scanner =
          new RecoveryScanner(
              false,/*tokenizeWhiteSpace*/
              false,/*checkNonExternalizedStringLiterals*/
              compilerOptions.sourceLevel,
              compilerOptions.complianceLevel,
              null/*taskTags*/,
              null/*taskPriorities*/,
              true/*taskCaseSensitive*/,
              this.recoveryScannerData);
      }
      scanner.setSource(this.content);
      this.tokenScanner= new TokenScanner(scanner);
    }
    return this.tokenScanner;
  }
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

    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_INTERNAL :
        this.apiLevel = level;
        // initialize a scanner
        this.scanner = new Scanner(
            true /*comment*/,
            true /*whitespace*/,
            false /*nls*/,
            ClassFileConstants.JDK1_7 /*sourceLevel*/,
            ClassFileConstants.JDK1_7 /*complianceLevel*/,
            null/*taskTag*/,
            null/*taskPriorities*/,
            true/*taskCaseSensitive*/);
        break;
      case JLS8 :
        this.apiLevel = level;
        // initialize a scanner
        this.scanner = new Scanner(
            true /*comment*/,
            true /*whitespace*/,
            false /*nls*/,
            ClassFileConstants.JDK1_8 /*sourceLevel*/,
            ClassFileConstants.JDK1_8 /*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

  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

  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

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.