use of org.checkerframework.dataflow.qual.SideEffectFree in project checker-framework by typetools.
the class RegexUtil method regexError.
/**
* Returns null if the argument is a syntactically valid regular expression with at least the
* given number of groups. Otherwise returns a string describing why the argument is not a regex.
*
* @param s string to check for being a regular expression
* @param groups number of groups expected
* @return null, or a string describing why the argument is not a regex
*/
// RegexUtil;
@SuppressWarnings({ "regex", "not.sef" })
@SideEffectFree
@Nullable
public static String regexError(String s, int groups) {
try {
Pattern p = Pattern.compile(s);
int actualGroups = getGroupCount(p);
if (actualGroups < groups) {
return regexErrorMessage(s, groups, actualGroups);
}
} catch (PatternSyntaxException e) {
return e.getMessage();
}
return null;
}
use of org.checkerframework.dataflow.qual.SideEffectFree in project checker-framework by typetools.
the class RegexUtil method asRegex.
/**
* Returns the argument as a {@code @Regex(groups) String} if it is a regex with at least the
* given number of groups, otherwise throws an error.
*
* <p>The purpose of this method is to suppress Regex Checker warnings. It should be very rarely
* needed.
*
* @param s string to check for being a regular expression
* @param groups number of groups expected
* @return its argument
* @throws Error if argument is not a regex
*/
// RegexUtil
@SuppressWarnings("regex")
@SideEffectFree
// RegexAnnotatedTypeFactory.
@Regex
public static String asRegex(String s, int groups) {
try {
Pattern p = Pattern.compile(s);
int actualGroups = getGroupCount(p);
if (actualGroups < groups) {
throw new Error(regexErrorMessage(s, groups, actualGroups));
}
return s;
} catch (PatternSyntaxException e) {
throw new Error(e);
}
}
use of org.checkerframework.dataflow.qual.SideEffectFree in project checker-framework by typetools.
the class RegexUtil method regexException.
/**
* Returns null if the argument is a syntactically valid regular expression with at least the
* given number of groups. Otherwise returns a PatternSyntaxException describing why the argument
* is not a regex.
*
* @param s string to check for being a regular expression
* @param groups number of groups expected
* @return null, or a PatternSyntaxException describing why the argument is not a regex
*/
// RegexUtil
@SuppressWarnings("regex")
@SideEffectFree
@Nullable
public static PatternSyntaxException regexException(String s, int groups) {
try {
Pattern p = Pattern.compile(s);
int actualGroups = getGroupCount(p);
if (actualGroups < groups) {
return new PatternSyntaxException(regexErrorMessage(s, groups, actualGroups), s, -1);
}
} catch (PatternSyntaxException pse) {
return pse;
}
return null;
}
use of org.checkerframework.dataflow.qual.SideEffectFree in project checker-framework by typetools.
the class AnnotationUtils method toStringSimple.
/**
* Returns a string representation of the annotation mirrors, using simple (not fully-qualified)
* names.
*
* @param annos annotations to format
* @return the string representation, using simple (not fully-qualified) names
*/
@SideEffectFree
public static String toStringSimple(Set<AnnotationMirror> annos) {
DefaultAnnotationFormatter defaultAnnotationFormatter = new DefaultAnnotationFormatter();
StringJoiner result = new StringJoiner(" ");
for (AnnotationMirror am : annos) {
result.add(defaultAnnotationFormatter.formatAnnotationMirror(am));
}
return result.toString();
}
use of org.checkerframework.dataflow.qual.SideEffectFree in project checker-framework by typetools.
the class DefaultAnnotationFormatter method formatAnnotationString.
/**
* Creates a String of each annotation in annos separated by a single space character and
* terminated by a space character, obeying the printInvisible parameter.
*
* @param annos a collection of annotations to print
* @param printInvisible whether or not to print "invisible" annotation mirrors
* @return the list of annotations converted to a String
*/
@Override
@SideEffectFree
public String formatAnnotationString(Collection<? extends AnnotationMirror> annos, boolean printInvisible) {
StringBuilder sb = new StringBuilder();
for (AnnotationMirror obj : annos) {
if (obj == null) {
throw new BugInCF("AnnotatedTypeMirror.formatAnnotationString: found null AnnotationMirror");
}
if (isInvisibleQualified(obj) && !printInvisible) {
continue;
}
formatAnnotationMirror(obj, sb);
sb.append(" ");
}
return sb.toString();
}
Aggregations