Skip to content

Commit

Permalink
Move @Nullable on return type back to a separate line
Browse files Browse the repository at this point in the history
  • Loading branch information
alllex committed Nov 17, 2023
1 parent 1ee248c commit f9e792c
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ private static abstract class MappedPropertyImpl implements MappedProperty {
private boolean cache;
private Object cachedValue;

public @Nullable Object getValue(org.gradle.api.plugins.Convention convention, IConventionAware conventionAwareObject) {
@Nullable
public Object getValue(org.gradle.api.plugins.Convention convention, IConventionAware conventionAwareObject) {
if (!cache) {
return doGetValue(convention, conventionAwareObject);
}
Expand All @@ -184,6 +185,7 @@ public void cache() {
cachedValue = null;
}

abstract @Nullable Object doGetValue(org.gradle.api.plugins.Convention convention, IConventionAware conventionAwareObject);
@Nullable
abstract Object doGetValue(org.gradle.api.plugins.Convention convention, IConventionAware conventionAwareObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ public DynamicInvokeResult tryGetProperty(String name) {
return DynamicInvokeResult.notFound();
}

public @Nullable Object propertyMissing(String name) {
@Nullable
public Object propertyMissing(String name) {
return getProperty(name);
}

Expand Down Expand Up @@ -333,7 +334,8 @@ public DynamicInvokeResult tryInvokeMethod(String name, @Nullable Object... args
return DynamicInvokeResult.notFound();
}

public @Nullable Object methodMissing(String name, Object args) {
@Nullable
public Object methodMissing(String name, Object args) {
return invokeMethod(name, (Object[]) args);
}

Expand Down Expand Up @@ -411,8 +413,9 @@ protected Map<String, Object> delegate() {
return delegate;
}

@Nullable
@Override
public @Nullable Object get(@Nullable Object key) {
public Object get(@Nullable Object key) {
logConventionDeprecation();
return super.get(key);
}
Expand All @@ -423,8 +426,9 @@ public Object getOrDefault(Object key, Object defaultValue) {
return super.getOrDefault(key, defaultValue);
}

@Nullable
@Override
public @Nullable Object remove(@Nullable Object key) {
public Object remove(@Nullable Object key) {
logConventionDeprecation();
return super.remove(key);
}
Expand All @@ -441,8 +445,9 @@ public void forEach(BiConsumer<? super String, ? super Object> action) {
super.forEach(action);
}

@Nullable
@Override
public @Nullable Object replace(String key, Object value) {
public Object replace(String key, Object value) {
logConventionDeprecation();
return super.replace(key, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public String getDisplayName() {
return dynamicDelegate.getDisplayName();
}

@Nullable
@Override
public @Nullable Class<?> getPublicType() {
public Class<?> getPublicType() {
return dynamicDelegate.getPublicType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public <T> T getByType(TypeOf<T> type) {
return getHolderByType(type).get();
}

public <T> @Nullable T findByType(TypeOf<T> type) {
@Nullable
public <T> T findByType(TypeOf<T> type) {
ExtensionHolder<T> found = findHolderByType(type);
return found != null ? found.get() : null;
}
Expand All @@ -88,14 +89,16 @@ private <T> ExtensionHolder<T> getHolderByType(TypeOf<T> type) {
"Extension of type '" + type.getSimpleName() + "' does not exist. Currently registered extension types: " + registeredExtensionTypeNames());
}

private <T> @Nullable ExtensionHolder<T> findHolderByType(TypeOf<T> type) {
@Nullable
private <T> ExtensionHolder<T> findHolderByType(TypeOf<T> type) {
ExtensionHolder<T> firstHolderWithExactPublicType = firstHolderWithExactPublicType(type);
return firstHolderWithExactPublicType != null
? firstHolderWithExactPublicType
: firstHolderWithAssignableType(type);
}

private <T> @Nullable ExtensionHolder<T> firstHolderWithExactPublicType(TypeOf<T> type) {
@Nullable
private <T> ExtensionHolder<T> firstHolderWithExactPublicType(TypeOf<T> type) {
for (ExtensionHolder<?> extensionHolder : extensions.values()) {
if (type.equals(extensionHolder.getPublicType())) {
return uncheckedCast(extensionHolder);
Expand All @@ -104,7 +107,8 @@ private <T> ExtensionHolder<T> getHolderByType(TypeOf<T> type) {
return null;
}

private <T> @Nullable ExtensionHolder<T> firstHolderWithAssignableType(TypeOf<T> type) {
@Nullable
private <T> ExtensionHolder<T> firstHolderWithAssignableType(TypeOf<T> type) {
for (ExtensionHolder<?> extensionHolder : extensions.values()) {
if (type.isAssignableFrom(extensionHolder.getPublicType())) {
return uncheckedCast(extensionHolder);
Expand All @@ -121,7 +125,8 @@ public Object getByName(String name) {
throw unknownExtensionException(name);
}

public @Nullable Object findByName(String name) {
@Nullable
public Object findByName(String name) {
ExtensionHolder<?> extensionHolder = extensions.get(name);
return extensionHolder != null ? extensionHolder.get() : null;
}
Expand All @@ -136,6 +141,7 @@ private List<String> registeredExtensionTypeNames() {

/**
* Doesn't actually return anything. Always throws a {@link UnknownDomainObjectException}.
*
* @return Nothing.
*/
private UnknownDomainObjectException unknownExtensionException(final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public DynamicInvokeResult tryGetProperty(String name) {
return DynamicInvokeResult.notFound();
}

public @Nullable Class<?> getPublicType() {
@Nullable
public Class<?> getPublicType() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ public String getDisplayName() {
return bean.toString();
}

@Nullable
@Override
public @Nullable Class<?> getPublicType() {
public Class<?> getPublicType() {
return publicType != null ? publicType : bean.getClass();
}

Expand Down Expand Up @@ -299,7 +300,8 @@ protected DynamicInvokeResult getOpaqueProperty(String name) {
return DynamicInvokeResult.notFound();
}

private @Nullable MetaMethod findGetPropertyMissingMethod(MetaClass metaClass) {
@Nullable
private MetaMethod findGetPropertyMissingMethod(MetaClass metaClass) {
if (metaClass instanceof MetaClassImpl) {
// Reach into meta class to avoid lookup
try {
Expand All @@ -318,7 +320,8 @@ protected DynamicInvokeResult getOpaqueProperty(String name) {
return null;
}

private @Nullable MetaMethod findSetPropertyMissingMethod(MetaClass metaClass) {
@Nullable
private MetaMethod findSetPropertyMissingMethod(MetaClass metaClass) {
if (metaClass instanceof MetaClassImpl) {
// Reach into meta class to avoid lookup
try {
Expand All @@ -337,7 +340,8 @@ protected DynamicInvokeResult getOpaqueProperty(String name) {
return null;
}

private @Nullable MetaMethod findMethodMissingMethod(MetaClass metaClass) {
@Nullable
private MetaMethod findMethodMissingMethod(MetaClass metaClass) {
if (metaClass instanceof MetaClassImpl) {
// Reach into meta class to avoid lookup
try {
Expand All @@ -362,7 +366,8 @@ protected DynamicInvokeResult getOpaqueProperty(String name) {
* Since we do this in a hot code path, we also reuse the argument array used for the
* reflective call to save memory.
*/
protected @Nullable MetaProperty lookupProperty(MetaClass metaClass, String name) {
@Nullable
protected MetaProperty lookupProperty(MetaClass metaClass, String name) {
boolean isInstrumented = metaClass instanceof InstrumentedMetaClass
&& ((InstrumentedMetaClass) metaClass).interceptsPropertyAccess(name);

Expand Down Expand Up @@ -563,7 +568,8 @@ public DynamicInvokeResult invokeMethod(String name, Object... arguments) {
return invokeOpaqueMethod(metaClass, name, arguments);
}

protected @Nullable MetaMethod lookupMethod(MetaClass metaClass, String name, Class[] arguments) {
@Nullable
protected MetaMethod lookupMethod(MetaClass metaClass, String name, Class[] arguments) {
return metaClass.pickMethod(name, arguments);
}

Expand Down Expand Up @@ -681,8 +687,9 @@ private class ClassAdapter extends MetaClassAdapter {
classMetaData = GroovySystem.getMetaClassRegistry().getMetaClass(cl);
}

@Nullable
@Override
protected @Nullable MetaProperty lookupProperty(MetaClass metaClass, String name) {
protected MetaProperty lookupProperty(MetaClass metaClass, String name) {
MetaProperty metaProperty = super.lookupProperty(metaClass, name);
if (metaProperty != null) {
return metaProperty;
Expand All @@ -694,8 +701,9 @@ private class ClassAdapter extends MetaClassAdapter {
return null;
}

@Nullable
@Override
protected @Nullable MetaMethod lookupMethod(MetaClass metaClass, String name, Class[] arguments) {
protected MetaMethod lookupMethod(MetaClass metaClass, String name, Class[] arguments) {
MetaMethod metaMethod = super.lookupMethod(metaClass, name, arguments);
if (metaMethod != null) {
return metaMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public String toString() {
return _delegate.toString();
}

public @Nullable Object _original_owner() {
@Nullable
public Object _original_owner() {
return _original_owner;
}

Expand All @@ -53,8 +54,9 @@ protected DynamicInvokeResult _configure(String name) {
return DynamicInvokeResult.notFound();
}

@Nullable
@Override
public @Nullable Object invokeMethod(String name, Object paramsObj) {
public Object invokeMethod(String name, Object paramsObj) {
Object[] params = (Object[]) paramsObj;

boolean isAlreadyConfiguring = _configuring;
Expand Down Expand Up @@ -100,8 +102,9 @@ public void setProperty(String property, Object newValue) {
throw _delegate.setMissingProperty(property);
}

@Nullable
@Override
public @Nullable Object getProperty(String name) {
public Object getProperty(String name) {
boolean isAlreadyConfiguring = _configuring;
_configuring = true;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

public class AbstractDynamicObjectTest {
private final AbstractDynamicObject object = new AbstractDynamicObject() {
public @Nonnull String getDisplayName() {
@Nonnull
public String getDisplayName() {
return "<display-name>";
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ private DynamicInvokeResult(@Nullable Object value) {
this.value = value;
}

public @Nullable Object getValue() {
@Nullable
public Object getValue() {
if (isFound()) {
return value;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,13 @@ protected boolean hasWithName(String name) {
return index.get(name) != null || index.getPending(name) != null;
}

protected @Nullable T findByNameWithoutRules(String name) {
@Nullable
protected T findByNameWithoutRules(String name) {
return index.get(name);
}

protected @Nullable ProviderInternal<? extends T> findByNameLaterWithoutRules(String name) {
@Nullable
protected ProviderInternal<? extends T> findByNameLaterWithoutRules(String name) {
return index.getPending(name);
}

Expand Down Expand Up @@ -636,8 +638,9 @@ public <S extends T> Index<S> filter(Spec<String> nameFilter, CollectionFilter<S
return new FilteredIndex<>(this, nameFilter, elementFilter);
}

@Nullable
@Override
public @Nullable ProviderInternal<? extends T> getPending(String name) {
public ProviderInternal<? extends T> getPending(String name) {
return pendingMap.get(name);
}

Expand Down Expand Up @@ -729,8 +732,9 @@ public <S extends T> Index<S> filter(Spec<String> nameFilter, CollectionFilter<S
);
}

@Nullable
@Override
public @Nullable ProviderInternal<? extends T> getPending(String name) {
public ProviderInternal<? extends T> getPending(String name) {
ProviderInternal<?> provider = delegate.getPending(name);
if (isPendingSatisfyingFilters(name, provider)) {
return Cast.uncheckedCast(provider);
Expand Down Expand Up @@ -826,7 +830,8 @@ public Class<?> getType() {
}
}

private @Nullable NamedDomainObjectProvider<? extends T> findDomainObject(String name) {
@Nullable
private NamedDomainObjectProvider<? extends T> findDomainObject(String name) {
NamedDomainObjectProvider<? extends T> provider = searchForDomainObject(name);
// Run the rules and try to find something again.
if (provider == null) {
Expand All @@ -838,7 +843,8 @@ public Class<?> getType() {
return provider;
}

private @Nullable NamedDomainObjectProvider<? extends T> searchForDomainObject(String name) {
@Nullable
private NamedDomainObjectProvider<? extends T> searchForDomainObject(String name) {
// Look for a realized object
T object = findByNameWithoutRules(name);
if (object != null) {
Expand Down Expand Up @@ -869,8 +875,9 @@ protected AbstractNamedDomainObjectProvider(String name, Class<I> type) {
this.type = type;
}

@Nullable
@Override
public @Nullable Class<I> getType() {
public Class<I> getType() {
return type;
}

Expand Down

0 comments on commit f9e792c

Please sign in to comment.