Skip to content

Commit

Permalink
squid:S2325 - "private" methods that don't access instance data shoul…
Browse files Browse the repository at this point in the history
…d be "static"
  • Loading branch information
Mohammed Ezzat committed Feb 20, 2016
1 parent 03a8a30 commit c6a64b3
Show file tree
Hide file tree
Showing 35 changed files with 42 additions and 42 deletions.
Expand Up @@ -59,7 +59,7 @@ public Boolean convert(String value, Class<? extends Boolean> type, ResourceBund
throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_boolean"), value));
}

private boolean matches(Set<String> words, String value) {
private static boolean matches(Set<String> words, String value) {
return words.contains(value);
}
}
Expand Up @@ -50,7 +50,7 @@ public Time convert(String value, Class<? extends Time> type,
}
}

private boolean isUncompleteTime(String value) {
private static boolean isUncompleteTime(String value) {
return Pattern.compile("[0-9]{2}\\:[0-9]{2}").matcher(value).find();
}
}
Expand Up @@ -80,7 +80,7 @@ public ExceptionRecorder<Result> findByException(Exception e) {
return hasExceptionCause(e) ? findByException((Exception) e.getCause()) : null;
}

private boolean hasExceptionCause(Exception e) {
private static boolean hasExceptionCause(Exception e) {
return e.getCause() != null && e.getCause() instanceof Exception;
}
}
Expand Up @@ -60,11 +60,11 @@ private String uriRelativeToContextRoot(HttpServletRequest request) {
return removeQueryStringAndJSessionId(uri);
}

private String removeQueryStringAndJSessionId(String uri) {
private static String removeQueryStringAndJSessionId(String uri) {
return uri.replaceAll("[\\?;].+", "");
}

private boolean isAFile(URL resourceUrl) {
private static boolean isAFile(URL resourceUrl) {
return !resourceUrl.toString().endsWith("/");
}

Expand Down
Expand Up @@ -70,7 +70,7 @@ private Deserializer subpathDeserializerForPlus(String contentType,
return null;
}

private String removeChar(String type, String by) {
private static String removeChar(String type, String by) {
return type.substring(type.lastIndexOf(by)+1);
}

Expand Down
Expand Up @@ -76,7 +76,7 @@ public XStream getConfiguredXStream(Method javaMethod, Class<?>[] types) {
return builder.configure(xStream);
}

private void chooseParam(Class<?>[] types, Object[] params, Object deserialized) {
private static void chooseParam(Class<?>[] types, Object[] params, Object deserialized) {
for (int i = 0; i < types.length; i++) {
if (types[i].isInstance(deserialized)) {
params[i] = deserialized;
Expand Down
Expand Up @@ -71,7 +71,7 @@ public XStream getConfiguredXStream(Method javaMethod, Class<?>[] types) {
return xStream;
}

private void chooseParam(Class<?>[] types, Object[] params, Object deserialized) {
private static void chooseParam(Class<?>[] types, Object[] params, Object deserialized) {
for (int i = 0; i < types.length; i++) {
if (types[i].isInstance(deserialized)) {
params[i] = deserialized;
Expand Down
Expand Up @@ -140,7 +140,7 @@ protected Class<?>[] getTypes(ResourceMethod method) {
return method.getMethod().getParameterTypes();
}

private Class<?>[] parseGenericParameters(Method method, Class<?> genericType) {
private static Class<?>[] parseGenericParameters(Method method, Class<?> genericType) {
Class<?>[] paramClasses = method.getParameterTypes();
Type[] paramTypes = method.getGenericParameterTypes();

Expand All @@ -159,7 +159,7 @@ private Class<?>[] parseGenericParameters(Method method, Class<?> genericType) {
return result;
}

private Class<?> getSuperClassTypeArgument(ResourceMethod method) {
private static Class<?> getSuperClassTypeArgument(ResourceMethod method) {
Type genericType = method.getResource().getType().getGenericSuperclass();

if (genericType instanceof ParameterizedType) {
Expand Down
Expand Up @@ -41,7 +41,7 @@ public String[] parameterNamesFor(AccessibleObject method) {
}

@SuppressWarnings({ "rawtypes" })
private Type[] parameterTypes(AccessibleObject methodOrConstructor) {
private static Type[] parameterTypes(AccessibleObject methodOrConstructor) {
if (methodOrConstructor instanceof Method) {
return ((Method)methodOrConstructor).getGenericParameterTypes();
} else if (methodOrConstructor instanceof Constructor<?>) {
Expand Down
Expand Up @@ -98,7 +98,7 @@ private List<Target<Object>> createTargets(ResourceMethod method) {
return targets;
}

private int methodArity(Method method) {
private static int methodArity(Method method) {
return method.getGenericParameterTypes().length;
}

Expand Down
Expand Up @@ -73,7 +73,7 @@ public void setProperty(Map context, Object array, Object key, Object value) thr
super.setProperty(context, array, key, value);
}

private Object copyOf(Object array, int desiredLength, int currentLength) {
private static Object copyOf(Object array, int desiredLength, int currentLength) {
Object newArray = Array.newInstance(array.getClass().getComponentType(), desiredLength + 1);
for (int i = 0; i < currentLength; i++) {
Array.set(newArray, i, Array.get(array, i));
Expand Down
Expand Up @@ -96,7 +96,7 @@ public void setProperty(Map context, Object target, Object key, Object value) th
super.setProperty(context, target, key, value);
}

private Class getActualType(Type genericType) {
private static Class getActualType(Type genericType) {
Class type;
if (genericType instanceof ParameterizedType) {
type = (Class) ((ParameterizedType) genericType).getActualTypeArguments()[0];
Expand Down
Expand Up @@ -95,7 +95,7 @@ public Object nullPropertyValue(Map context, Object target, Object property) {
return instance;
}

private Object instantiateArray(Class<?> baseType) {
private static Object instantiateArray(Class<?> baseType) {
return Array.newInstance(baseType.getComponentType(), 0);
}

Expand Down
Expand Up @@ -88,7 +88,7 @@ private Type extractArrayType(Object target) {
return target.getClass().getComponentType();
}

private Type extractFieldType(Member member) {
private static Type extractFieldType(Member member) {
return ((Field) member).getGenericType();
}

Expand Down
Expand Up @@ -111,7 +111,7 @@ public String fillUri(String[] paramNames, Object... paramValues) {
return base.replaceAll("\\.\\*", "");
}

private Object selectParam(String key, String[] paramNames, Object[] paramValues) {
private static Object selectParam(String key, String[] paramNames, Object[] paramValues) {
for (int i = 0; i < paramNames.length; i++) {
if (key.matches("^" + paramNames[i] + "(\\..*|$)")) {
return paramValues[i];
Expand Down
Expand Up @@ -198,7 +198,7 @@ private void addParametersInfo(Method method) {
}
}

private String[] sanitize(String[] parameters) {
private static String[] sanitize(String[] parameters) {
String[] sanitized = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
sanitized[i] = parameters[i].replaceAll("(\\:.*|\\*)$", "");
Expand Down
Expand Up @@ -95,7 +95,7 @@ public ResourceMethod parse(String uri, HttpMethod method, MutableRequest reques
return route.resourceMethod(request, uri);
}

private void checkIfThereIsAnotherRoute(String uri, HttpMethod method, Iterator<Route> iterator, Route route) {
private static void checkIfThereIsAnotherRoute(String uri, HttpMethod method, Iterator<Route> iterator, Route route) {
if (iterator.hasNext()) {
Route otherRoute = iterator.next();
if (route.getPriority() == otherRoute.getPriority()) {
Expand Down
Expand Up @@ -59,7 +59,7 @@ public Map<String, Class<?>> getParameterTypes(Method method, String[] parameter
}
return result;
}
private String upperFirst(String item) {
private static String upperFirst(String item) {
return item.substring(0, 1).toUpperCase() + item.substring(1);
}

Expand Down
Expand Up @@ -190,7 +190,7 @@ protected String extractPrefix(Class<?> type) {
}
}

private String fixLeadingSlash(String uri) {
private static String fixLeadingSlash(String uri) {
if (!uri.startsWith("/")) {
return "/" + uri;
}
Expand Down
Expand Up @@ -51,7 +51,7 @@ public String nameFor(Type generic) {
return nameFor((Class<?>) generic);
}

private String nameFor(Class<?> raw) {
private static String nameFor(Class<?> raw) {
if (raw.isArray()) {
return nameFor(raw.getComponentType()) + "List";
}
Expand All @@ -61,7 +61,7 @@ private String nameFor(Class<?> raw) {
return StringUtils.lowercaseFirst(name);
}

private String nameFor(TypeVariable<?> variable) {
private static String nameFor(TypeVariable<?> variable) {
return StringUtils.lowercaseFirst(variable.getName());
}

Expand Down
Expand Up @@ -111,7 +111,7 @@ public void intercept(InterceptorStack stack, ResourceMethod method, Object reso

}

private String mime(String contentType) {
private static String mime(String contentType) {
if (contentType.contains(";")) {
return contentType.split(";")[0];
}
Expand Down
Expand Up @@ -155,7 +155,7 @@ protected void registerBundledComponents(ComponentRegistry registry) {
}
}

private void registerAll(ComponentRegistry registry, Map<Class<?>, Class<?>> scope) {
private static void registerAll(ComponentRegistry registry, Map<Class<?>, Class<?>> scope) {
for (Map.Entry<Class<?>, Class<?>> entry : scope.entrySet()) {
registry.register(entry.getKey(), entry.getValue());
registry.register(entry.getValue(), entry.getValue());
Expand Down
Expand Up @@ -44,7 +44,7 @@ public Constructor[] determineCandidateConstructors(Class beanClass, String bean
}

@SuppressWarnings({ "rawtypes" })
private Constructor checkIfThereIsOnlyOneNonDefaultConstructor(Class beanClass) {
private static Constructor checkIfThereIsOnlyOneNonDefaultConstructor(Class beanClass) {
Constructor[] constructors = beanClass.getDeclaredConstructors();
if (constructors.length == 1) {
if (constructors[0].getParameterTypes().length > 0) {
Expand Down
Expand Up @@ -53,7 +53,7 @@ public <T> T instanceFor(Class<T> clazz) {
}
}

private <T> T useDefaultConstructor(Class<T> clazz) {
private static <T> T useDefaultConstructor(Class<T> clazz) {
try {
return clazz.newInstance();
} catch (Exception e) {
Expand Down Expand Up @@ -96,15 +96,15 @@ private <T> T tryAllConstructors(Class<T> type, Constructor<?>[] constructors) {
* @param parameterTypes of the constructor to be called, in order.
* @return parameter instances for the given types.
*/
private Object[] proxyParameters(Class<?>[] parameterTypes) {
private static Object[] proxyParameters(Class<?>[] parameterTypes) {
return new Object[parameterTypes.length];
}

/**
* @param constructors from the type to be proxified
* @return null when there isn't a default (null) constructor
*/
private Constructor<?> findDefaultConstructor(Constructor<?>[] constructors) {
private static Constructor<?> findDefaultConstructor(Constructor<?>[] constructors) {
for (Constructor<?> constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
return constructor;
Expand Down
Expand Up @@ -118,7 +118,7 @@ private boolean allows(T resource, Method method) {
return false;
}

private String lowerFirstChar(String simpleName) {
private static String lowerFirstChar(String simpleName) {
if(simpleName.length()==1) {
return simpleName.toLowerCase();
}
Expand Down
Expand Up @@ -71,7 +71,7 @@ public void marshal(Object root, HierarchicalStreamWriter writer,
}
}

private Object getRoot(Object root) {
private static Object getRoot(Object root) {
if (root instanceof ConfigurableHypermediaResource) {
return ((ConfigurableHypermediaResource) root).getModel();
}
Expand Down
Expand Up @@ -61,7 +61,7 @@ private void writeTag(Object root, Method m, HierarchicalStreamWriter writer, Ma
writer.endNode();
}

private String nameFor(Method m) {
private static String nameFor(Method m) {
String name = m.getName();
if (name.startsWith("is")) {
return StringUtils.lowercaseFirst(name.substring(2));
Expand Down
Expand Up @@ -89,7 +89,7 @@ public Class<WebAppBootstrap> generate(Collection<String> components, ClasspathR
}
}

private String createMethodDef(Collection<String> components) {
private static String createMethodDef(Collection<String> components) {
StringBuilder methodDef = new StringBuilder()
.append("public void configure (br.com.caelum.vraptor.ComponentRegistry registry){");

Expand Down
Expand Up @@ -107,7 +107,7 @@ private void scanPackage(String basePackage, AnnotationDB db, ClasspathResolver
} while (urls.hasMoreElements());
}

private String toFileName(String resource, URL url) {
private static String toFileName(String resource, URL url) {
String file = url.getFile().substring(0, url.getFile().length() - resource.length() - 1).replaceAll("(!)(/)?$", "");

if (!file.startsWith("file:")) {
Expand Down Expand Up @@ -138,7 +138,7 @@ private void addBasePackagesStereotypes(Map<String, Set<String>> basePackagesAnn
}
}

private boolean packagesContains(List<String> basePackages, String clazz) {
private static boolean packagesContains(List<String> basePackages, String clazz) {
for (String basePackage : basePackages) {
if (clazz.startsWith(basePackage)) {
return true;
Expand All @@ -153,7 +153,7 @@ private void addWebInfClassesStereotypes(Map<String, Set<String>> webInfClassesA
results.addAll(myStereotypes);
}

private void addVRaptorStereotypes(HashSet<String> results) {
private static void addVRaptorStereotypes(HashSet<String> results) {
for (Class<? extends Annotation> stereotype : BaseComponents.getStereotypes()) {
results.add(stereotype.getName());
}
Expand Down
Expand Up @@ -65,7 +65,7 @@ private void parseInclude(Multimap<Class<?>, String> excludesMap, Entry<String,
excludesMap.remove(parentType, fieldName);
}

private String getNameFor(String name) {
private static String getNameFor(String name) {
String[] path = name.split("\\.");
return path[path.length-1];
}
Expand Down
Expand Up @@ -69,7 +69,7 @@ public boolean shouldSerializeMember(Class definedIn, String fieldName) {
return should;
}

private boolean isCompatiblePath(Entry<String, Class<?>> path, Class definedIn, String fieldName) {
private static boolean isCompatiblePath(Entry<String, Class<?>> path, Class definedIn, String fieldName) {
return path.getValue().equals(definedIn) && (path.getKey().equals(fieldName) || path.getKey().endsWith("." + fieldName));
}

Expand Down
Expand Up @@ -126,7 +126,7 @@ private Locale getLocale() {
return localization.getLocale() == null ? Locale.getDefault() : localization.getLocale();
}

private boolean hasProperties(String... properties) {
private static boolean hasProperties(String... properties) {
return properties != null && properties.length > 0;
}

Expand Down
Expand Up @@ -144,7 +144,7 @@ private MimeType convertToMimeType(String string) {
return new MimeType(string, 1);
}

private double extractQualifier(String string) {
private static double extractQualifier(String string) {
double qualifier = DEFAULT_QUALIFIER_VALUE;
if (string.contains("q=")) {
Matcher matcher = Pattern.compile("\\s*q=(.+)\\s*").matcher(string);
Expand Down
Expand Up @@ -67,7 +67,7 @@ protected String extractControllerFromName(String baseName) {
return baseName;
}

private String lowerFirstCharacter(String baseName) {
private static String lowerFirstCharacter(String baseName) {
return baseName.toLowerCase().substring(0, 1) + baseName.substring(1, baseName.length());
}
}
Expand Up @@ -44,7 +44,7 @@ public Object[] consumeParameters(ResourceMethod method) {
return args;
}

private String nameFor(ResourceMethod method) {
private static String nameFor(ResourceMethod method) {
return KEY_START + method.getMethod();
}

Expand Down

0 comments on commit c6a64b3

Please sign in to comment.