/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
package org.codehaus.groovy.parser.antlr4;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;

import static org.codehaus.groovy.parser.antlr4.GroovyParser.Identifier;

/**
 * Created by Daniel.Sun on 2016/8/20.
 */
public class GrammarPredicates {
    public static boolean isFollowedByJavaLetterInGString(CharStream cs) {
        int c1 = cs.LA(1);
        String str1 = String.valueOf((char) c1);

        if (str1.matches("[a-zA-Z_{]")) {
            return true;
        }

        if (str1.matches("[^\u0000-\u007F\uD800-\uDBFF]")
                && Character.isJavaIdentifierPart(c1)) {
            return true;
        }

        int c2 = cs.LA(2);
        String str2 = String.valueOf((char) c2);

        if (str1.matches("[\uD800-\uDBFF]")
                && str2.matches("[\uDC00-\uDFFF]")
                && Character.isJavaIdentifierPart(Character.toCodePoint((char) c1, (char) c2))) {

            return true;
        }

        return false;
    }

    public static boolean isUpperCase(Token x) {
        if (x == null || x.getType() != Identifier)
            return false;  // cannot happen?

        String xtext = x.getText();
        return (xtext.length() > 0 && Character.isUpperCase(xtext.charAt(0)));
    }
}

@@ -902,117 +902,8 @@
 eam;
-%0Aimport org.antlr.v4.runtime.Token;%0A%0Aimport static org.codehaus.groovy.parser.antlr4.GroovyParser.Identifier;
 %0A%0A/*
@@ -1701,274 +1701,6 @@
  %7D%0A%0A
-    public static boolean isUpperCase(Token x) %7B%0A        if (x == null %7C%7C x.getType() != Identifier)%0A            return false;  // cannot happen?%0A%0A        String xtext = x.getText();%0A        return (xtext.length() %3E 0 && Character.isUpperCase(xtext.charAt(0)));%0A    %7D%0A
 %7D%0A

Remove useless codes