/**
   * This function gets the activation token from the document given the current cursor position.
   *
   * @param document this is the document we want info on
   * @param offset this is the cursor position
   * @param getFullQualifier if true we get the full qualifier (even if it passes the current cursor
   *     location)
   * @return a tuple with the activation token and the cursor offset (may change if we need to get
   *     the full qualifier, otherwise, it is the same offset passed as a parameter).
   */
  public static Tuple<String, Integer> extractActivationToken(
      IDocument document, int offset, boolean getFullQualifier) {
    try {
      if (getFullQualifier) {
        // if we have to get the full qualifier, we'll have to walk the offset (cursor) forward
        while (offset < document.getLength()) {
          char ch = document.getChar(offset);
          if (Character.isJavaIdentifierPart(ch)) {
            offset++;
          } else {
            break;
          }
        }
      }
      int i = offset;

      if (i > document.getLength()) {
        return new Tuple<String, Integer>("", document.getLength()); // $NON-NLS-1$
      }

      while (i > 0) {
        char ch = document.getChar(i - 1);
        if (!Character.isJavaIdentifierPart(ch)) {
          break;
        }
        i--;
      }

      return new Tuple<String, Integer>(document.get(i, offset - i), offset);
    } catch (BadLocationException e) {
      return new Tuple<String, Integer>("", offset); // $NON-NLS-1$
    }
  }
示例#2
0
  CharSequence findVar() {
    int start = current;
    char c = peek();

    if (c == '{') {
      next();
      int end = find('}', '{');
      return text.subSequence(start, end);
    }
    if (c == '(') {
      next();
      int end = find(')', '(');
      return text.subSequence(start, end);
    }

    if (Character.isJavaIdentifierPart(c)) {
      while (c == '$') {
        c = next();
      }
      while (!eof() && (Character.isJavaIdentifierPart(c) || c == '.') && c != '$') {
        next();
        c = peek();
      }
      return text.subSequence(start, current);
    }
    throw new IllegalArgumentException(
        "Reference to variable does not match syntax of a variable: " + context(start));
  }
  /**
   * Checks whether the content of <code>document</code> in the range (<code>offset</code>, <code>
   * length</code>) contains the <code>new</code> keyword.
   *
   * @param document the document being modified
   * @param offset the first character position in <code>document</code> to be considered
   * @param length the length of the character range to be considered
   * @param partitioning the document partitioning
   * @return <code>true</code> if the specified character range contains a <code>new</code> keyword,
   *     <code>false</code> otherwise.
   */
  private static boolean isNewMatch(
      IDocument document, int offset, int length, String partitioning) {
    Assert.isTrue(length >= 0);
    Assert.isTrue(offset >= 0);
    Assert.isTrue(offset + length < document.getLength() + 1);

    try {
      String text = document.get(offset, length);
      int pos = text.indexOf("new"); // $NON-NLS-1$

      while (pos != -1 && !isDefaultPartition(document, pos + offset, partitioning))
        pos = text.indexOf("new", pos + 2); // $NON-NLS-1$

      if (pos < 0) return false;

      if (pos != 0 && Character.isJavaIdentifierPart(text.charAt(pos - 1))) return false;

      if (pos + 3 < length && Character.isJavaIdentifierPart(text.charAt(pos + 3))) return false;

      return true;

    } catch (BadLocationException e) {
    }
    return false;
  }
  /** Select the word at the current selection. Return true if successful, false otherwise. */
  protected boolean matchWord() {

    IDocument doc = fText.getDocument();

    try {

      int pos = fPos;
      char c;

      while (pos >= 0) {
        c = doc.getChar(pos);
        if (!Character.isJavaIdentifierPart(c)) break;
        --pos;
      }

      fStartPos = pos;

      pos = fPos;
      int length = doc.getLength();

      while (pos < length) {
        c = doc.getChar(pos);
        if (!Character.isJavaIdentifierPart(c)) break;
        ++pos;
      }

      fEndPos = pos;

      return true;

    } catch (BadLocationException x) {
    }

    return false;
  }
示例#5
0
  private static String getIdentifier(StyledDocument doc, JEditorPane ep, int offset) {
    String t = null;
    if ((ep.getSelectionStart() <= offset) && (offset <= ep.getSelectionEnd()))
      t = ep.getSelectedText();
    if (t != null) return t;

    int line = NbDocument.findLineNumber(doc, offset);
    int col = NbDocument.findLineColumn(doc, offset);
    try {
      Element lineElem = NbDocument.findLineRootElement(doc).getElement(line);

      if (lineElem == null) return null;
      int lineStartOffset = lineElem.getStartOffset();
      int lineLen = lineElem.getEndOffset() - lineStartOffset;
      t = doc.getText(lineStartOffset, lineLen);
      int identStart = col;
      while (identStart > 0
          && (Character.isJavaIdentifierPart(t.charAt(identStart - 1))
              || (t.charAt(identStart - 1) == '.'))) {
        identStart--;
      }
      int identEnd = col;
      while (identEnd < lineLen && Character.isJavaIdentifierPart(t.charAt(identEnd))) {
        identEnd++;
      }

      if (identStart == identEnd) return null;
      return t.substring(identStart, identEnd);
    } catch (BadLocationException e) {
      return null;
    }
  }
示例#6
0
 @Override
 public void checkConfiguration(Issues issues) {
   super.checkConfiguration(issues);
   if (isCheckFileExtension()) {
     for (String extension : fileExtensions) {
       char[] charArray = extension.toCharArray();
       if (!Character.isJavaIdentifierPart(charArray[0])) {
         issues.addError(
             "file extension '"
                 + extension
                 + "' starts with a non identifier letter : '"
                 + charArray[0]
                 + "'",
             this);
       }
       for (int i = 1; i < charArray.length; i++) {
         char c = charArray[i];
         if (!Character.isJavaIdentifierPart(c)) {
           issues.addError(
               "file extension '" + extension + "' contains non identifier letter : '" + c + "'",
               this);
         }
       }
     }
   }
   if (getGrammar() == null) {
     issues.addError("property 'uri' is mandatory for element 'language'.", this);
   }
 }
  private static boolean processTextIn(
      PsiElement scope,
      String stringToSearch,
      final boolean ignoreReferences,
      PairProcessor<PsiElement, TextRange> processor) {
    String text = scope.getText();
    for (int offset = 0; offset < text.length(); offset++) {
      offset = text.indexOf(stringToSearch, offset);
      if (offset < 0) break;
      final PsiReference referenceAt = scope.findReferenceAt(offset);
      if (!ignoreReferences && referenceAt != null && referenceAt.resolve() != null) continue;

      if (offset > 0) {
        char c = text.charAt(offset - 1);
        if (Character.isJavaIdentifierPart(c) && c != '$') {
          if (offset < 2 || text.charAt(offset - 2) != '\\') continue; // escape sequence
        }
      }

      if (offset + stringToSearch.length() < text.length()) {
        char c = text.charAt(offset + stringToSearch.length());
        if (Character.isJavaIdentifierPart(c) && c != '$') {
          continue;
        }
      }

      TextRange textRange = new TextRange(offset, offset + stringToSearch.length());
      if (!processor.process(scope, textRange)) {
        return false;
      }

      offset += stringToSearch.length();
    }
    return true;
  }
示例#8
0
  /**
   * Indicates if the tag matches at the given index.
   *
   * @param buffer is the buffer
   * @param tag is the tag to match
   * @param pos is the index
   * @return true if the tag matches at the given index
   */
  private boolean matches(StringBuffer buffer, String tag, int pos) {
    int len = tag.length();
    int currentPos = pos;
    int index = 0;
    while (--len >= 0) {
      if (buffer.charAt(currentPos++) != tag.charAt(index++)) {
        return false;
      }
    }
    boolean wholeWord = tag.length() > 0 && Character.isJavaIdentifierPart(tag.charAt(0));
    boolean result;
    if (wholeWord) {
      if ((pos == 0 || !Character.isJavaIdentifierPart(buffer.charAt(pos - 1)))
          && (currentPos >= buffer.length()
              || !Character.isJavaIdentifierPart(buffer.charAt(currentPos)))) {
        result = true;
      } else {
        result = false;
      }
    } else {
      result = true;
    }

    if (result
        && IAcceleoConstants.LITERAL_ESCAPE.equals(tag)
        && pos > 1
        && "\\".equals(buffer.substring(pos - 1, pos))) { // $NON-NLS-1$
      // We have found the string escape token but we have the escape token before.
      result = false;
    }

    return result;
  }
  /**
   * @param offset
   * @return
   */
  protected IRegion getRegion(IDocument document, int offset) {
    StructuredModelWrapper smw = new StructuredModelWrapper();
    try {
      smw.init(document);
      Document xmlDocument = smw.getDocument();
      if (xmlDocument == null) return null;

      Node n = Utils.findNodeForOffset(xmlDocument, offset);

      if (n == null || !(n instanceof Attr)) return null;
      int start = Utils.getValueStart(n);
      int end = Utils.getValueEnd(n);
      if (start > offset) return null;

      String attrText = document.get(start, end - start);

      StringBuffer sb = new StringBuffer(attrText);
      // find start of css class
      int bStart = offset - start;
      while (bStart >= 0) {
        if (!Character.isJavaIdentifierPart(sb.charAt(bStart))
            && sb.charAt(bStart) != '_'
            && sb.charAt(bStart) != '-'
            && sb.charAt(bStart) != '.') {
          bStart++;
          break;
        }

        if (bStart == 0) break;
        bStart--;
      }
      // find end of css class
      int bEnd = offset - start;
      while (bEnd < sb.length()) {
        if (!Character.isJavaIdentifierPart(sb.charAt(bEnd))
            && sb.charAt(bEnd) != '_'
            && sb.charAt(bEnd) != '-'
            && sb.charAt(bEnd) != '.') break;
        bEnd++;
      }

      final int propStart = bStart + start;
      final int propLength = bEnd - bStart;

      if (propStart > offset || propStart + propLength < offset) return null;
      return new Region(propStart, propLength);
    } catch (BadLocationException x) {
      // ignore
      return null;
    } finally {
      smw.dispose();
    }
  }
示例#10
0
  public IToken evaluate(ICharacterScanner charScanner) {

    RuleBasedScanner scanner = (RuleBasedScanner) charScanner;
    StringBuffer buff = new StringBuffer();
    boolean stopReading = false;
    int reads = 0;

    /*char c = (char) ICharacterScanner.EOF;

    do {
        c = (char) scanner.read();

        System.out.print(c);
    } while (c != (char) ICharacterScanner.EOF);

    scanner.unread();*/

    if (scanner.getColumn() > 0) {
      scanner.unread();

      char c = (char) scanner.read();

      if (Character.isJavaIdentifierPart(c)) return Token.UNDEFINED;
    }

    while (!stopReading) {

      reads++;

      char c = (char) scanner.read();

      String currentWord = buff.toString();

      if (buff.length() > 0 && !Character.isJavaIdentifierPart(c)) {
        if (isKeyword(currentWord.toLowerCase()) && !keywordExists(currentWord + c)) {
          scanner.unread();
          return keywordToken;
        }
      }

      buff.append(c);

      stopReading = !keywordExists(currentWord.toLowerCase());
    }

    for (int i = 0; i < reads; i++) {
      scanner.unread();
    }

    return Token.UNDEFINED;
  }
  public static IHyperlinkRegion getRegion(IDocument document, final int offset) {
    StructuredModelWrapper smw = new StructuredModelWrapper();
    try {
      smw.init(document);
      Document xmlDocument = smw.getDocument();
      if (xmlDocument == null) return null;

      Node n = Utils.findNodeForOffset(xmlDocument, offset);

      if (n == null || !(n instanceof Attr)) return null;

      int start = Utils.getValueStart(n);
      int end = Utils.getValueEnd(n);

      if (start < 0 || start > offset) return null;

      String attrText = document.get(start, end - start);
      StringBuffer sb = new StringBuffer(attrText);

      // find start of bean property
      int bStart = offset - start;
      while (bStart >= 0) {
        if (!Character.isJavaIdentifierPart(sb.charAt(bStart)) && sb.charAt(bStart) != '.') {
          bStart++;
          break;
        }

        if (bStart == 0) break;
        bStart--;
      }
      // find end of bean property
      int bEnd = offset - start;
      while (bEnd < sb.length()) {
        if (!Character.isJavaIdentifierPart(sb.charAt(bEnd)) && sb.charAt(bEnd) != '.') break;
        bEnd++;
      }

      int propStart = bStart + start;
      int propLength = bEnd - bStart;

      if (propStart > offset || propStart + propLength < offset) return null;

      IHyperlinkRegion region = new HyperlinkRegion(propStart, propLength, null, null, null);
      return region;
    } catch (BadLocationException x) {
      JSFExtensionsPlugin.log("", x); // $NON-NLS-1$
      return null;
    } finally {
      smw.dispose();
    }
  }
示例#12
0
 public IToken evaluate(ICharacterScanner scanner) {
   Arrays.fill(candidates, true);
   int candidateCount = todoTags.length;
   int count = 0;
   int c;
   while ((c = scanner.read()) != ICharacterScanner.EOF) {
     for (int i = 0; i < todoTags.length; i++) {
       if (candidates[i]) {
         final char[] tag = todoTags[i];
         if (count < tag.length) {
           final boolean eq =
               caseSensitive ? c == tag[count] : Character.toUpperCase((char) c) == tag[count];
           if (!eq) {
             candidates[i] = false;
             --candidateCount;
             if (candidateCount == 0) {
               unreadScanner(scanner, count + 1);
               return Token.UNDEFINED;
             }
           }
         } else if (count == tag.length) {
           if (!Character.isJavaIdentifierPart((char) c)) {
             scanner.unread();
             return getSuccessToken();
           }
         }
       }
     }
     ++count;
     if (count == maxLength) {
       c = scanner.read();
       if (c != ICharacterScanner.EOF && !Character.isJavaIdentifierPart((char) c)) {
         c = ICharacterScanner.EOF;
       }
       scanner.unread();
       break;
     }
   }
   if (c == ICharacterScanner.EOF) {
     for (int i = 0; i < todoTags.length; i++) {
       if (candidates[i] && count == todoTags[i].length) {
         return getSuccessToken();
       }
     }
   }
   unreadScanner(scanner, count);
   return Token.UNDEFINED;
 }
示例#13
0
  private IRegion findWord(IDocument document, int offset) {
    int start = -1;
    int end = -1;

    try {
      int pos = offset;
      char c;

      while (pos >= 0) {
        c = document.getChar(pos);
        if (!Character.isJavaIdentifierPart(c)
            && (c != '@')
            && (c != '<')
            && (c != '*')
            && (c != '?')
            && (c != '%')) break;
        --pos;
      }

      start = pos;

      pos = offset;
      int length = document.getLength();

      while (pos < length) {
        c = document.getChar(pos);
        if (!Character.isJavaIdentifierPart(c)
            && (c != '@')
            && (c != '<')
            && (c != '*')
            && (c != '?')
            && (c != '%')) break;
        ++pos;
      }

      end = pos;

    } catch (BadLocationException x) {
    }

    if (start > -1 && end > -1) {
      if (start == offset && end == offset) return new Region(offset, 0);
      else if (start == offset) return new Region(start, end - start);
      else return new Region(start + 1, end - start - 1);
    }

    return null;
  }
示例#14
0
  /**
   * Finds a word by specified offset and returns the region of word.
   *
   * @param source
   * @param offset
   * @return the region of found word
   */
  public static IRegion findWord(IDocument document, int offset) {

    int start = -2;
    int end = -1;

    try {
      int pos = offset;
      char c;

      while (pos > 0 && pos < document.getLength()) {
        c = document.getChar(pos);
        if (Character.isWhitespace(c) && !Character.isLetter(c)) break;
        --pos;
      }
      start = pos;
      pos = offset;
      int length = document.getLength();

      while (pos < length - 1) {
        c = document.getChar(pos);
        if (!Character.isJavaIdentifierPart(c)) break;
        ++pos;
      }
      end = pos;

    } catch (BadLocationException x) {
    }

    if (start >= -1 && end > -1) {
      return new Region(start, end - start);
    }

    return null;
  }
  private static void autoImport(final PsiFile file, int offset, final Editor editor) {
    final CharSequence text = editor.getDocument().getCharsSequence();
    while (offset > 0 && Character.isJavaIdentifierPart(text.charAt(offset))) offset--;
    if (offset <= 0) return;

    while (offset > 0 && Character.isWhitespace(text.charAt(offset))) offset--;
    if (offset <= 0 || text.charAt(offset) != '.') return;

    offset--;

    while (offset > 0 && Character.isWhitespace(text.charAt(offset))) offset--;
    if (offset <= 0) return;

    PsiJavaCodeReferenceElement element =
        extractReference(
            PsiTreeUtil.findElementOfClassAtOffset(file, offset, PsiExpression.class, false));
    if (element == null) return;

    while (true) {
      final PsiJavaCodeReferenceElement qualifier = extractReference(element.getQualifier());
      if (qualifier == null) break;

      element = qualifier;
    }
    if (!(element.getParent() instanceof PsiMethodCallExpression)
        && element.multiResolve(true).length == 0) {
      new ImportClassFix(element).doFix(editor, false, false);
    }
  }
示例#16
0
 /** A unique id for the api, required. */
 public void setId(String id) throws ConfigException {
   for (int i = 0; i < id.length(); i++) {
     if (!Character.isJavaIdentifierPart(id.charAt(i)))
       throw new ConfigException(L.l("illegal character in `{0}': {1}", "id", id.charAt(i)));
   }
   _id = id;
 }
 /**
  * Determines the kind of a character.
  *
  * @param ch the character to test
  */
 private int getKind(char ch) {
   if (Character.isUpperCase(ch)) return K_UPPER;
   if (Character.isLowerCase(ch)) return K_LOWER;
   if (Character.isJavaIdentifierPart(ch)) // _, digits...
   return K_OTHER;
   return K_INVALID;
 }
示例#18
0
  private static String parse(String query, Map<String, List<Integer>> paramMap) {

    int length = query.length();
    StringBuilder parsedQuery = new StringBuilder(length);
    boolean inSingleQuote = false;
    boolean inDoubleQuote = false;
    int index = 1;

    for (int i = 0; i < length; i++) {

      char c = query.charAt(i);

      // String end
      if (inSingleQuote) {
        if (c == '\'') {
          inSingleQuote = false;
        }
      } else if (inDoubleQuote) {
        if (c == '"') {
          inDoubleQuote = false;
        }
      } else {

        // String begin
        if (c == '\'') {
          inSingleQuote = true;
        } else if (c == '"') {
          inDoubleQuote = true;
        } else if (c == ':'
            && i + 1 < length
            && Character.isJavaIdentifierStart(query.charAt(i + 1))) {

          // Identifier name
          int j = i + 2;
          while (j < length && Character.isJavaIdentifierPart(query.charAt(j))) {
            j++;
          }

          String name = query.substring(i + 1, j);
          c = '?';
          i += name.length();
          name = name.toLowerCase();

          // Add to list
          List<Integer> indexList = paramMap.get(name);
          if (indexList == null) {
            indexList = new LinkedList<>();
            paramMap.put(name, indexList);
          }
          indexList.add(index);

          index++;
        }
      }

      parsedQuery.append(c);
    }

    return parsedQuery.toString();
  }
示例#19
0
 /** Converts the specified string into a valid identifier. All illegal characters are escaped. */
 public String toIdentifier(String string) {
   StringBuilder result = new StringBuilder();
   int index = 0;
   char c = string.charAt(index);
   if (Character.isJavaIdentifierStart(c)) {
     result.append(c);
     index++;
   } else if (Character.isJavaIdentifierPart(c)) {
     result.append(ESCAPE_TOKEN);
   }
   while (index < string.length()) {
     c = string.charAt(index++);
     result.append(Character.isJavaIdentifierPart(c) ? c : ESCAPE_TOKEN);
   }
   return result.toString();
 }
示例#20
0
 /**
  * Checks that the given string is a valid Java identifier.
  * 
  * @param version
  *            the class version.
  * @param name
  *            the string to be checked.
  * @param msg
  *            a message to be used in case of error.
  */
 static void checkMethodIdentifier(int version, final String name,
         final String msg) {
     if (name == null || name.length() == 0) {
         throw new IllegalArgumentException("Invalid " + msg
                 + " (must not be null or empty)");
     }
     if ((version & 0xFFFF) >= Opcodes.V1_5) {
         for (int i = 0; i < name.length(); ++i) {
             if (".;[/<>".indexOf(name.charAt(i)) != -1) {
                 throw new IllegalArgumentException("Invalid " + msg
                         + " (must be a valid unqualified name): " + name);
             }
         }
         return;
     }
     if (!Character.isJavaIdentifierStart(name.charAt(0))) {
         throw new IllegalArgumentException(
                 "Invalid "
                         + msg
                         + " (must be a '<init>', '<clinit>' or a valid Java identifier): "
                         + name);
     }
     for (int i = 1; i < name.length(); ++i) {
         if (!Character.isJavaIdentifierPart(name.charAt(i))) {
             throw new IllegalArgumentException(
                     "Invalid "
                             + msg
                             + " (must be '<init>' or '<clinit>' or a valid Java identifier): "
                             + name);
         }
     }
 }
  /** Copies all data that it can read from the given reader to the given writer. */
  protected void copyData(Reader reader, Writer writer) throws IOException {
    StringBuffer word = new StringBuffer();

    while (true) {
      int i = reader.read();
      if (i < 0) {
        break;
      }

      // Is the character part of a word?
      char c = (char) i;
      if (Character.isJavaIdentifierPart(c) || c == '.' || c == '-') {
        // Collect the characters in this word.
        word.append(c);
      } else {
        // Write out the updated word, if any.
        writeUpdatedWord(writer, word.toString());
        word.setLength(0);

        // Write out the character that terminated it.
        writer.write(c);
      }
    }

    // Write out the final word.
    writeUpdatedWord(writer, word.toString());
  }
示例#22
0
 private static boolean isValidPackageName(String name) {
   if (name.length() == 0) {
     // Fast check of default pkg
     return true;
   }
   StringTokenizer tk = new StringTokenizer(name, ".", true); // NOI18N
   boolean delimExpected = false;
   while (tk.hasMoreTokens()) {
     String namePart = tk.nextToken();
     if (!delimExpected) {
       if (namePart.equals(".")) { // NOI18N
         return false;
       }
       for (int i = 0; i < namePart.length(); i++) {
         char c = namePart.charAt(i);
         if (i == 0) {
           if (!Character.isJavaIdentifierStart(c)) {
             return false;
           }
         } else {
           if (!Character.isJavaIdentifierPart(c)) {
             return false;
           }
         }
       }
     } else {
       if (!namePart.equals(".")) { // NOI18N
         return false;
       }
     }
     delimExpected = !delimExpected;
   }
   return delimExpected;
 }
示例#23
0
  /**
   * Validates that the name of a processor option conforms to the grammar defined by <code>
   * javax.annotation.processing.Processor.getSupportedOptions()</code>.
   *
   * @param optionName
   * @return <code>true</code> if the name conforms to the grammar, <code>false</code> if not.
   */
  public static boolean isValidOptionName(String optionName) {
    if (optionName == null) {
      return false;
    }

    boolean startExpected = true;
    int codePoint;

    for (int i = 0; i < optionName.length(); i += Character.charCount(codePoint)) {
      codePoint = optionName.codePointAt(i);

      if (startExpected) {
        if (!Character.isJavaIdentifierStart(codePoint)) {
          return false;
        }

        startExpected = false;

      } else {
        if (codePoint == '.') {
          startExpected = true;

        } else if (!Character.isJavaIdentifierPart(codePoint)) {
          return false;
        }
      }
    }

    return !startExpected;
  }
示例#24
0
 public static String replace(
     String beforePlaceholder,
     String afterPlaceholder,
     String placeholder,
     String replacement,
     boolean wholeWords,
     boolean encloseInParensIfNecessary) {
   final boolean actuallyReplace =
       !wholeWords
           || afterPlaceholder.length() == 0
           || !Character.isJavaIdentifierPart(afterPlaceholder.charAt(0));
   boolean encloseInParens =
       actuallyReplace
           && encloseInParensIfNecessary
           && !(getLastNonWhitespaceCharacter(beforePlaceholder) == '(')
           && !(getFirstNonWhitespaceCharacter(afterPlaceholder) == ')');
   StringBuilder buf = new StringBuilder(beforePlaceholder);
   if (encloseInParens) {
     buf.append('(');
   }
   buf.append(actuallyReplace ? replacement : placeholder);
   if (encloseInParens) {
     buf.append(')');
   }
   buf.append(
       replace(
           afterPlaceholder, placeholder, replacement, wholeWords, encloseInParensIfNecessary));
   return buf.toString();
 }
示例#25
0
    public static void main(String[] args)
    {
        char a[] = { 'a', '5', '?', 'A', ' ', '$', 'жа' };
        for (int i = 0; i < a.length; i++) {
            if (Character.isDigit(a[i]))
                System.out.println(a[i] + " is a digit.");
            if (Character.isLetter(a[i]))
                System.out.println(a[i] + " is a letter.");
            if (Character.isWhitespace(a[i]))
                System.out.println(a[i] + " is whitespace.");
            if (Character.isUpperCase(a[i]))
                System.out.println(a[i] + " is uppercase.");
            if (Character.isLowerCase(a[i]))
                System.out.println(a[i] + " is lowercase.");
            if (Character.isJavaIdentifierPart(a[i]))
                System.out.println(a[i]
                        + " may be part of java Identifier part.");
            if (Character.isJavaIdentifierStart(a[i]))
                System.out.println(a[i]
                        + " may be part of java Identifier Start.");
            if (Character.isUnicodeIdentifierPart(a[i]))
                System.out.println(a[i]
                        + " may be part of a Unicode identifier .");
            if (Character.isUnicodeIdentifierStart(a[i]))
                System.out
                        .println(a[i]
                                + " may be the first character in a Unicode identifier.");

        }
    }
示例#26
0
    /**
     * Parses a type name token T (which can be potentially of the form Tr&ly;T1,T2,...>, or "?
     * extends/super T".)
     *
     * @return the index of the character next to T.
     */
    JClass parseTypeName() throws ClassNotFoundException {
      int start = idx;

      if (s.charAt(idx) == '?') {
        // wildcard
        idx++;
        ws();
        String head = s.substring(idx);
        if (head.startsWith("extends")) {
          idx += 7;
          ws();
          return parseTypeName().wildcard();
        } else if (head.startsWith("super")) {
          throw new UnsupportedOperationException("? super T not implemented");
        } else {
          // not supported
          throw new IllegalArgumentException(
              "only extends/super can follow ?, but found " + s.substring(idx));
        }
      }

      while (idx < s.length()) {
        char ch = s.charAt(idx);
        if (Character.isJavaIdentifierStart(ch) || Character.isJavaIdentifierPart(ch) || ch == '.')
          idx++;
        else break;
      }

      JClass clazz = ref(s.substring(start, idx));

      return parseSuffix(clazz);
    }
  @Override
  public boolean consume(CodeReader code, Lexer lexer) {
    if (!Character.isJavaIdentifierStart(code.peek())) {
      return false;
    }

    int line = code.getCursor().getLine();
    int column = code.getCursor().getColumn();
    while (Character.isJavaIdentifierPart(code.peek())) {
      tmpBuilder.append((char) code.pop());
    }

    String word = tmpBuilder.toString();

    TokenType keywordType = keywordsMap.get(word);
    Token token =
        tokenBuilder
            .setType(keywordType == null ? GenericTokenType.IDENTIFIER : keywordType)
            .setValueAndOriginalValue(word, word)
            .setURI(lexer.getURI())
            .setLine(line)
            .setColumn(column)
            .build();

    lexer.addToken(token);

    tmpBuilder.delete(0, tmpBuilder.length());

    return true;
  }
示例#28
0
 public static void main(String args[]) {
   char c = 'è';
   if (Character.isJavaIdentifierStart(c)) System.out.println("char\'" + c + "\'is right");
   else System.out.println("char\'" + c + "\'isn\'t right");
   if (Character.isJavaIdentifierPart(c)) System.out.println("char\'" + c + "\'is right chu shou");
   else System.out.println("char\'" + c + "\'isn\'t right shou");
 }
示例#29
0
  private static String[] getSuggestionsByValue(final String stringValue) {
    List<String> result = new ArrayList<String>();
    StringBuffer currentWord = new StringBuffer();

    boolean prevIsUpperCase = false;

    for (int i = 0; i < stringValue.length(); i++) {
      final char c = stringValue.charAt(i);
      if (Character.isUpperCase(c)) {
        if (currentWord.length() > 0 && !prevIsUpperCase) {
          result.add(currentWord.toString());
          currentWord = new StringBuffer();
        }
        currentWord.append(c);
      } else if (Character.isLowerCase(c)) {
        currentWord.append(Character.toUpperCase(c));
      } else if (Character.isJavaIdentifierPart(c) && c != '_') {
        if (Character.isJavaIdentifierStart(c) || currentWord.length() > 0 || !result.isEmpty()) {
          currentWord.append(c);
        }
      } else {
        if (currentWord.length() > 0) {
          result.add(currentWord.toString());
          currentWord = new StringBuffer();
        }
      }

      prevIsUpperCase = Character.isUpperCase(c);
    }

    if (currentWord.length() > 0) {
      result.add(currentWord.toString());
    }
    return ArrayUtil.toStringArray(result);
  }
示例#30
0
 private boolean isIdentifier(String content, char c) {
   if (content == null || content.length() == 0) {
     return !Character.isJavaIdentifierPart(c);
   } else {
     return content.charAt(0) == c;
   }
 }