Skip to content

Commit

Permalink
Use diamond operator where possible (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Jun 13, 2024
1 parent 108c634 commit f48d59f
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static Object handle(StaplerRequest request, Annotation[] annotations, String pa
return null; // probably we should report an error
}

private static final ClassValue<AnnotationHandler> HANDLERS = new ClassValue<AnnotationHandler>() {
private static final ClassValue<AnnotationHandler> HANDLERS = new ClassValue<>() {
@Override
protected AnnotationHandler computeValue(Class<?> at) {
InjectedParameter ip = at.getAnnotation(InjectedParameter.class);
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/kohsuke/stapler/AttributeKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final void remove() {
* Creates a new request-scoped {@link AttributeKey}.
*/
public static <T> AttributeKey<T> requestScoped() {
return new AttributeKey<T>() {
return new AttributeKey<>() {
@Override
public T get(HttpServletRequest req) {
return (T) req.getAttribute(name);
Expand All @@ -76,7 +76,7 @@ public void remove(HttpServletRequest req) {
* Creates a new session-scoped {@link AttributeKey}.
*/
public static <T> AttributeKey<T> sessionScoped() {
return new AttributeKey<T>() {
return new AttributeKey<>() {
@Override
public T get(HttpServletRequest req) {
HttpSession s = req.getSession(false);
Expand Down Expand Up @@ -105,7 +105,7 @@ public void remove(HttpServletRequest req) {
* Creates a new {@link ServletContext}-scoped {@link AttributeKey}.
*/
public static <T> AttributeKey<T> appScoped() {
return new AttributeKey<T>() {
return new AttributeKey<>() {
@Override
public T get(HttpServletRequest req) {
return (T) getContext(req).getAttribute(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private List<MethodMirror> findMethods(
}

Method[] declaredMethods = c.getDeclaredMethods();
Arrays.sort(declaredMethods, new Comparator<Method>() {
Arrays.sort(declaredMethods, new Comparator<>() {
@Override
public int compare(Method m1, Method m2) {
boolean m1d = m1.getAnnotation(Deprecated.class) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
abstract class ClassLoaderValue<T> {

private final ClassValue<T> storage = new ClassValue<T>() {
private final ClassValue<T> storage = new ClassValue<>() {
@Override
protected T computeValue(Class<?> type) {
return ClassLoaderValue.this.computeValue(type.getClassLoader());
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Object bindAndInvoke(Object o, StaplerRequest req, StaplerResponse rsp, Object..
throw new AssertionError(e); // impossible
}

PARSE_METHODS = new ClassValue<Function>() {
PARSE_METHODS = new ClassValue<>() {
@Override
public Function computeValue(Class<?> from) {
// MethdFunction for invoking a static method as a static method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static MetaClassLoader get(ClassLoader cl) {
/**
* All {@link MetaClass}es.
*/
private static final ClassLoaderValue<MetaClassLoader> classMap = new ClassLoaderValue<MetaClassLoader>() {
private static final ClassLoaderValue<MetaClassLoader> classMap = new ClassLoaderValue<>() {
@Override
protected MetaClassLoader computeValue(ClassLoader cl) {
return new MetaClassLoader(cl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public SingleLinkedList<T> grow(T item) {

@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
return new Iterator<>() {
SingleLinkedList<T> next = SingleLinkedList.this;

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/TearOffSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @author Kohsuke Kawaguchi
*/
public abstract class TearOffSupport {
private final ClassValue<Object> tearOffs = new ClassValue<Object>() {
private final ClassValue<Object> tearOffs = new ClassValue<>() {
@Override
protected Object computeValue(Class<?> type) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static <T> Iterator<T> limit(final Iterator<T> iterator, final int limitSize) {
if (limitSize < 0) {
throw new IllegalArgumentException("limit is negative");
}
return new Iterator<T>() {
return new Iterator<>() {
private int count;

@Override
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/kohsuke/stapler/export/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public List<Property> getProperties() {
/**
* Does a property exist strictly in this class?
*/
/*package*/ final Predicate<String> HAS_PROPERTY_NAME = new Predicate<String>() {
/*package*/ final Predicate<String> HAS_PROPERTY_NAME = new Predicate<>() {
@Override
public boolean test(@Nullable String name) {
return propertyNames.contains(name);
Expand All @@ -149,7 +149,7 @@ public boolean test(@Nullable String name) {
/**
* Does a property exist strictly in this class or its ancestors?
*/
/*package*/ final Predicate<String> HAS_PROPERTY_NAME_IN_ANCESTRY = new Predicate<String>() {
/*package*/ final Predicate<String> HAS_PROPERTY_NAME_IN_ANCESTRY = new Predicate<>() {
@Override
public boolean test(@Nullable String name) {
for (Model m = Model.this; m != null; m = m.superModel) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/export/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public <T> Iterable<T> apply(final Iterable<T> s) {
if (s instanceof List) {
return apply((List<T>) s);
} else {
return new Iterable<T>() {
return new Iterable<>() {
@Override
public Iterator<T> iterator() {
Iterator<T> itr = s.iterator();
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/kohsuke/stapler/export/TypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public final T visit(Type t, P param) {
/**
* Implements the logic for {@link #erasure(Type)}.
*/
private static final TypeVisitor<Class, Void> eraser = new TypeVisitor<Class, Void>() {
private static final TypeVisitor<Class, Void> eraser = new TypeVisitor<>() {
@Override
public Class onClass(Class c, Void unused) {
return c;
Expand Down Expand Up @@ -130,7 +130,7 @@ public static <T> Class<T> erasure(Type t) {
return eraser.visit(t, null);
}

private static final TypeVisitor<Type, Class> baseClassFinder = new TypeVisitor<Type, Class>() {
private static final TypeVisitor<Type, Class> baseClassFinder = new TypeVisitor<>() {
@Override
public Type onClass(Class c, Class sup) {
// t is a raw type
Expand Down Expand Up @@ -213,7 +213,7 @@ private Type bind(Type t, GenericDeclaration decl, ParameterizedType args) {
}
};

private static final TypeVisitor<Type, BinderArg> binder = new TypeVisitor<Type, BinderArg>() {
private static final TypeVisitor<Type, BinderArg> binder = new TypeVisitor<>() {
@Override
public Type onClass(Class c, BinderArg args) {
return c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ConstructorProcessor extends AbstractProcessorImpl {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
try {
ElementScanner9<Void, Void> scanner = new ElementScanner9<Void, Void>() {
ElementScanner9<Void, Void> scanner = new ElementScanner9<>() {
Set<Element> enclosingElementsWritten = new HashSet<>();
boolean messagePrinted;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public Object getMapElement(Object o, String key) {
return ((Map) o).get(key);
}

public static final KlassNavigator<Class> JAVA = new KlassNavigator<Class>() {
public static final KlassNavigator<Class> JAVA = new KlassNavigator<>() {
@Override
public URL getResource(Class clazz, String resourceName) {
ClassLoader cl = clazz.getClassLoader();
Expand Down Expand Up @@ -186,7 +186,7 @@ public Class toJavaClass(Class clazz) {
@Override
public List<MethodRef> getDeclaredMethods(Class clazz) {
final Method[] methods = clazz.getDeclaredMethods();
return new AbstractList<MethodRef>() {
return new AbstractList<>() {
@Override
public MethodRef get(int index) {
return MethodRef.wrap(methods[index]);
Expand All @@ -202,7 +202,7 @@ public int size() {
@Override
public List<FieldRef> getDeclaredFields(Class clazz) {
final Field[] fields = clazz.getDeclaredFields();
return new AbstractList<FieldRef>() {
return new AbstractList<>() {
@Override
public FieldRef get(int index) {
return FieldRef.wrap(fields[index]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public final class JellyBuilder extends GroovyObjectSupport {

private JellyContext context;

private final ClassValue<GroovyClosureScript> taglibs = new ClassValue<GroovyClosureScript>() {
private final ClassValue<GroovyClosureScript> taglibs = new ClassValue<>() {
@Override
protected GroovyClosureScript computeValue(Class<?> type) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ProtectedClass(Class c) {
this.c = c;
}

public static KlassNavigator<ProtectedClass> NAVIGATOR = new KlassNavigator<ProtectedClass>() {
public static KlassNavigator<ProtectedClass> NAVIGATOR = new KlassNavigator<>() {

@Override
public boolean isArray(ProtectedClass clazz) {
Expand Down

0 comments on commit f48d59f

Please sign in to comment.