Search in sources :

Example 6 with Edit

use of processing.mode.java.pdex.TextTransform.Edit in project processing by processing.

the class SourceUtils method fixFloatsRegex.

public static List<Edit> fixFloatsRegex(CharSequence source) {
    final List<Edit> edits = new ArrayList<>();
    Matcher matcher = NUMBER_LITERAL_REGEX.matcher(source);
    while (matcher.find()) {
        int offset = matcher.start();
        int end = matcher.end();
        String group = matcher.group().toLowerCase();
        boolean isFloatingPoint = group.contains(".") || group.contains("e");
        boolean hasSuffix = end < source.length() && Character.toLowerCase(source.charAt(end)) != 'f' && Character.toLowerCase(source.charAt(end)) != 'd';
        if (isFloatingPoint && !hasSuffix) {
            edits.add(Edit.insert(offset, "f"));
        }
    }
    return edits;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Edit(processing.mode.java.pdex.TextTransform.Edit)

Aggregations

ArrayList (java.util.ArrayList)6 Edit (processing.mode.java.pdex.TextTransform.Edit)6 Matcher (java.util.regex.Matcher)5 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)1 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)1 NumberLiteral (org.eclipse.jdt.core.dom.NumberLiteral)1 SimpleType (org.eclipse.jdt.core.dom.SimpleType)1