You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/01/22 07:03:24 UTC

[isis] branch master updated: ISIS-1842 add generic types where missing + suppress warnings

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 7abbfa3  ISIS-1842 add generic types where missing + suppress warnings
7abbfa3 is described below

commit 7abbfa3e4077b94a21132d809e7f2494153efe90
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Jan 22 08:03:21 2018 +0100

    ISIS-1842 add generic types where missing + suppress warnings
---
 .../apache/isis/applib/AppManifestAbstract2.java   |  3 +-
 .../isis/applib/ModuleOrBuilderAbstract.java       | 29 +++++----
 .../isis/applib/fixturescripts/FixtureScript.java  |  4 +-
 .../ClassDiscoveryServiceUsingReflections.java     | 71 ++++++++++++----------
 .../applib/services/command/CommandDefault.java    |  2 +-
 .../isis/applib/services/iactn/Interaction.java    | 24 ++++----
 .../apache/isis/schema/utils/CommonDtoUtils.java   |  6 +-
 .../background/BackgroundCommandExecution.java     |  2 +-
 .../background/BackgroundServiceDefault.java       |  2 +-
 .../runtime/system/TestObjectWithCollection.java   |  4 +-
 10 files changed, 82 insertions(+), 65 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/AppManifestAbstract2.java b/core/applib/src/main/java/org/apache/isis/applib/AppManifestAbstract2.java
index f42ff25..4ecd2d7 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/AppManifestAbstract2.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/AppManifestAbstract2.java
@@ -125,7 +125,8 @@ public abstract class AppManifestAbstract2 extends AppManifestAbstract implement
             withConfigurationProperties(Module.Util.transitiveIndividualConfigPropsOf(module));
         }
 
-        private static Class[] asClasses(final List<Module> dependencies) {
+        @SuppressWarnings("unchecked") //[ahuber] it's safe to assume correct type casting here 
+		private static Class<? extends Module>[] asClasses(final List<Module> dependencies) {
             final List<Class<? extends Module>> list = new ArrayList<>();
             for (Module dependency : dependencies) {
                 Class<? extends Module> aClass = dependency.getClass();
diff --git a/core/applib/src/main/java/org/apache/isis/applib/ModuleOrBuilderAbstract.java b/core/applib/src/main/java/org/apache/isis/applib/ModuleOrBuilderAbstract.java
index e138f06..a0a6ecf 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/ModuleOrBuilderAbstract.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/ModuleOrBuilderAbstract.java
@@ -34,7 +34,7 @@ import com.google.common.collect.Sets;
  *
  * @param <B>
  */
-abstract class ModuleOrBuilderAbstract<B extends ModuleOrBuilderAbstract> {
+abstract class ModuleOrBuilderAbstract<B extends ModuleOrBuilderAbstract<B>> {
 
     final Set<Class<?>> additionalModules = Sets.newLinkedHashSet();
     final Set<Class<?>> additionalServices  = Sets.newLinkedHashSet();
@@ -43,17 +43,17 @@ abstract class ModuleOrBuilderAbstract<B extends ModuleOrBuilderAbstract> {
     final List<PropertyResource> propertyResources = Lists.newArrayList();
 
     ModuleOrBuilderAbstract() {}
-
+    
     public B withAdditionalModules(final Class<?>... modules) {
         return withAdditionalModules(Arrays.asList(modules));
     }
 
     public B withAdditionalModules(final List<Class<?>> modules) {
         if(modules == null) {
-            return (B)this;
+            return self();
         }
         this.additionalModules.addAll(modules);
-        return (B)this;
+        return self();
     }
 
     public B withAdditionalServices(final Class<?>... additionalServices) {
@@ -62,17 +62,17 @@ abstract class ModuleOrBuilderAbstract<B extends ModuleOrBuilderAbstract> {
 
     public B withAdditionalServices(final List<Class<?>> additionalServices) {
         if(additionalServices == null) {
-            return (B)this;
+            return self();
         }
         this.additionalServices.addAll(additionalServices);
-        return (B)this;
+        return self();
     }
 
     public B withConfigurationProperties(final Map<String,String> configurationProperties) {
         for (Map.Entry<String, String> keyValue : configurationProperties.entrySet()) {
             withConfigurationProperty(keyValue.getKey(), keyValue.getValue());
         }
-        return (B)this;
+        return self();
     }
 
     public B withConfigurationPropertiesFile(final String propertiesFile) {
@@ -83,12 +83,12 @@ abstract class ModuleOrBuilderAbstract<B extends ModuleOrBuilderAbstract> {
         for (PropertyResource propertyResource : propertyResources) {
             withConfigurationPropertyResource(propertyResource);
         }
-        return (B)this;
+        return self();
     }
 
     public B withConfigurationPropertyResource(final PropertyResource propertyResource) {
         addPropertyResource(propertyResource);
-        return (B)this;
+        return self();
     }
 
     public B withConfigurationPropertiesFile(
@@ -99,7 +99,7 @@ abstract class ModuleOrBuilderAbstract<B extends ModuleOrBuilderAbstract> {
         for (final String otherFile : furtherPropertiesFiles) {
             addPropertyResource(propertiesFileContext, otherFile);
         }
-        return (B)this;
+        return self();
     }
 
     private void addPropertyResource(final Class<?> propertiesFileContext, final String propertiesFile) {
@@ -112,7 +112,7 @@ abstract class ModuleOrBuilderAbstract<B extends ModuleOrBuilderAbstract> {
 
     public B withConfigurationProperty(final String key, final String value) {
         individualConfigProps.put(key, value);
-        return (B)this;
+        return self();
     }
 
     @XmlTransient
@@ -124,5 +124,12 @@ abstract class ModuleOrBuilderAbstract<B extends ModuleOrBuilderAbstract> {
     public List<PropertyResource> getPropertyResources() {
         return propertyResources;
     }
+    
+    // -- HELPER
+    
+    @SuppressWarnings("unchecked") //[ahuber] it's safe to assume this object is an instance of B
+	private B self() {
+    	return (B) this;
+    }
 
 }
diff --git a/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/FixtureScript.java b/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/FixtureScript.java
index 779ade8..16bf8ea 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/FixtureScript.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/fixturescripts/FixtureScript.java
@@ -613,7 +613,7 @@ public abstract class FixtureScript
                 previouslyExecutedScript = fixtureScriptByClass.get(childFixtureScript.getClass());
                 if (previouslyExecutedScript == null) {
                     if (childFixtureScript instanceof WithPrereqs) {
-                        final WithPrereqs withPrereqs = (WithPrereqs) childFixtureScript;
+                        final WithPrereqs<?,?> withPrereqs = (WithPrereqs<?,?>) childFixtureScript;
                         withPrereqs.execPrereqs(this);
                     }
                 }
@@ -661,7 +661,7 @@ public abstract class FixtureScript
             FixtureScript previouslyExecutedScript = fixtureScriptByValue.get(childFixtureScript);
             if (previouslyExecutedScript == null) {
                 if (childFixtureScript instanceof WithPrereqs) {
-                    final WithPrereqs withPrereqs = (WithPrereqs) childFixtureScript;
+                    final WithPrereqs<?,?> withPrereqs = (WithPrereqs<?,?>) childFixtureScript;
                     withPrereqs.execPrereqs(this);
                 }
             }
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/classdiscovery/ClassDiscoveryServiceUsingReflections.java b/core/applib/src/main/java/org/apache/isis/applib/services/classdiscovery/ClassDiscoveryServiceUsingReflections.java
index d1374d2..2ce5197 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/classdiscovery/ClassDiscoveryServiceUsingReflections.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/classdiscovery/ClassDiscoveryServiceUsingReflections.java
@@ -18,6 +18,7 @@
  */
 package org.apache.isis.applib.services.classdiscovery;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
@@ -44,45 +45,53 @@ import org.apache.isis.applib.fixturescripts.FixtureScript;
  * </p>
  */
 @DomainService(
-        nature = NatureOfService.DOMAIN,
-        menuOrder = "" + Integer.MAX_VALUE
-)
+		nature = NatureOfService.DOMAIN,
+		menuOrder = "" + Integer.MAX_VALUE
+		)
 public class ClassDiscoveryServiceUsingReflections
-            extends AbstractService 
-            implements ClassDiscoveryService {
+extends AbstractService 
+implements ClassDiscoveryService {
 
 
-    @Programmatic
-    @Override
-    public <T> Set<Class<? extends T>> findSubTypesOfClasses(Class<T> type, String packagePrefix) {
+	@Programmatic
+	@Override
+	public <T> Set<Class<? extends T>> findSubTypesOfClasses(Class<T> type, String packagePrefix) {
 
-        if(type == FixtureScript.class) {
-            Set fixtureScriptTypes = AppManifest.Registry.instance().getFixtureScriptTypes();
-            if (fixtureScriptTypes != null) {
-                return fixtureScriptTypes;
-            }
-        }
+		if(type == FixtureScript.class) {
+			return getFixtureScriptTypes();
+		}
 
-        // no appManifest or not asking for FixtureScripts
-        Vfs.setDefaultURLTypes(getUrlTypes());
+		// no appManifest or not asking for FixtureScripts
+		Vfs.setDefaultURLTypes(getUrlTypes());
 
-        final Reflections reflections = new Reflections(
-                ClasspathHelper.forClassLoader(Thread.currentThread().getContextClassLoader()),
-                ClasspathHelper.forClass(Object.class),
-                ClasspathHelper.forPackage(packagePrefix),
-                new SubTypesScanner(false)
-        );
-        return reflections.getSubTypesOf(type);
-    }
+		final Reflections reflections = new Reflections(
+				ClasspathHelper.forClassLoader(Thread.currentThread().getContextClassLoader()),
+				ClasspathHelper.forClass(Object.class),
+				ClasspathHelper.forPackage(packagePrefix),
+				new SubTypesScanner(false)
+				);
+		return reflections.getSubTypesOf(type);
+	}
 
-    // //////////////////////////////////////
+	// //////////////////////////////////////
 
-    /**
-     * Has <tt>public</tt> visibility only so can be reused by other services (including Isis runtime itself).
-     */
-    public static List<Vfs.UrlType> getUrlTypes() {
-        return AppManifest.Registry.instance().getUrlTypes();
-    }
+	/**
+	 * Has <tt>public</tt> visibility only so can be reused by other services (including Isis runtime itself).
+	 */
+	public static List<Vfs.UrlType> getUrlTypes() {
+		return AppManifest.Registry.instance().getUrlTypes();
+	}
+
+	// -- HELPER
+
+	@SuppressWarnings({ "unchecked", "rawtypes" })
+	private static <T> Set<Class<? extends T>> getFixtureScriptTypes() {
+		Set fixtureScriptTypes = AppManifest.Registry.instance().getFixtureScriptTypes();
+		if (fixtureScriptTypes != null) {
+			return fixtureScriptTypes;
+		}
+		return Collections.emptySet();
+	}
 
 
 }
\ No newline at end of file
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/command/CommandDefault.java b/core/applib/src/main/java/org/apache/isis/applib/services/command/CommandDefault.java
index 3a9047d..33f104f 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/command/CommandDefault.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/command/CommandDefault.java
@@ -204,7 +204,7 @@ public class CommandDefault implements Command {
     }
 
     @Override
-    public ActionDomainEvent popActionDomainEvent() {
+    public ActionDomainEvent<?> popActionDomainEvent() {
         return !actionDomainEvents.isEmpty() ? actionDomainEvents.removeLast() : null;
     }
 
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/iactn/Interaction.java b/core/applib/src/main/java/org/apache/isis/applib/services/iactn/Interaction.java
index d665088..f5c082c 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/iactn/Interaction.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/iactn/Interaction.java
@@ -100,16 +100,16 @@ public class Interaction implements HasTransactionId {
 
     //region > push/pop/current/get/clear Execution(s)
 
-    private final List<Execution> executionGraphs = Lists.newArrayList();
-    private Execution currentExecution;
-    private Execution priorExecution;
+    private final List<Execution<?,?>> executionGraphs = Lists.newArrayList();
+    private Execution<?,?> currentExecution;
+    private Execution<?,?> priorExecution;
 
 
     /**
      * The execution that preceded the current one.
      */
     @Programmatic
-    public Execution getPriorExecution() {
+    public Execution<?,?> getPriorExecution() {
         return priorExecution;
     }
 
@@ -120,7 +120,7 @@ public class Interaction implements HasTransactionId {
      * (Modelled after {@link Callable}), is the implementation
      * by which the framework actually performs the interaction.
      */
-    public interface MemberExecutor<T extends Execution> {
+    public interface MemberExecutor<T extends Execution<?,?>> {
         @Programmatic
         Object execute(final T currentExecution);
     }
@@ -161,7 +161,7 @@ public class Interaction implements HasTransactionId {
         return executeInternal(memberExecutor, propertyEdit);
     }
 
-    private <T extends Execution> Object executeInternal(
+    private <T extends Execution<?,?>> Object executeInternal(
             final MemberExecutor<T> memberExecutor,
             final T execution) {
 
@@ -192,7 +192,7 @@ public class Interaction implements HasTransactionId {
      * The current (most recently pushed) {@link Execution}.
      */
     @Programmatic
-    public Execution getCurrentExecution() {
+    public Execution<?,?> getCurrentExecution() {
         return currentExecution;
     }
 
@@ -205,7 +205,7 @@ public class Interaction implements HasTransactionId {
      * </p>
      */
     @Programmatic
-    private Execution push(final Execution execution) {
+    private Execution<?,?> push(final Execution<?,?> execution) {
 
         if(currentExecution == null) {
             // new top-level execution
@@ -232,18 +232,18 @@ public class Interaction implements HasTransactionId {
      * </p>
      */
     @Programmatic
-    private Execution pop(final Timestamp completedAt) {
+    private Execution<?,?> pop(final Timestamp completedAt) {
         if(currentExecution == null) {
             throw new IllegalStateException("No current execution to pop");
         }
-        final Execution popped = currentExecution;
+        final Execution<?,?> popped = currentExecution;
         popped.setCompletedAt(completedAt);
 
         moveCurrentTo(currentExecution.getParent());
         return popped;
     }
 
-    private void moveCurrentTo(final Execution newExecution) {
+    private void moveCurrentTo(final Execution<?,?> newExecution) {
         priorExecution = currentExecution;
         currentExecution = newExecution;
     }
@@ -259,7 +259,7 @@ public class Interaction implements HasTransactionId {
      * </p>
      */
     @Programmatic
-    public List<Execution> getExecutions() {
+    public List<Execution<?,?>> getExecutions() {
         return Collections.unmodifiableList(executionGraphs);
     }
 
diff --git a/core/applib/src/main/java/org/apache/isis/schema/utils/CommonDtoUtils.java b/core/applib/src/main/java/org/apache/isis/schema/utils/CommonDtoUtils.java
index 79eefb1..ba11784 100644
--- a/core/applib/src/main/java/org/apache/isis/schema/utils/CommonDtoUtils.java
+++ b/core/applib/src/main/java/org/apache/isis/schema/utils/CommonDtoUtils.java
@@ -138,7 +138,7 @@ public final class CommonDtoUtils {
             final Object val,
             final BookmarkService bookmarkService) {
         if(val instanceof Collection) {
-            final Collection collection = (Collection) val;
+            final Collection<?> collection = (Collection<?>) val;
             final CollectionDto collectionDto = asCollectionDto(collection, valueType, bookmarkService);
             valueDto.setCollection(collectionDto);
             return valueDto;
@@ -225,7 +225,7 @@ public final class CommonDtoUtils {
             return valueDto;
         }
         case ENUM: {
-            final Enum argValue = (Enum) val;
+            final Enum<?> argValue = (Enum<?>) val;
             if(argValue == null) {
                 return null;
             }
@@ -258,7 +258,7 @@ public final class CommonDtoUtils {
     }
 
     private static CollectionDto asCollectionDto(
-            final Iterable iterable,
+            final Iterable<?> iterable,
             final ValueType valueType,
             final BookmarkService bookmarkService) {
         final CollectionDto collectionDto = new CollectionDto();
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java
index 6e5ee19..751d85e 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundCommandExecution.java
@@ -188,7 +188,7 @@ public abstract class BackgroundCommandExecution extends AbstractIsisSessionTemp
 
                 // it's possible that there is no priorExecution, specifically if there was an exception
                 // invoking the action.  We therefore need to guard that case.
-                final Interaction.Execution priorExecution = backgroundInteraction.getPriorExecution();
+                final Interaction.Execution<?,?> priorExecution = backgroundInteraction.getPriorExecution();
                 final Timestamp completedAt =
                         priorExecution != null
                                 ? priorExecution.getCompletedAt()
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
index 8b279d6..62c5376 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
@@ -142,7 +142,7 @@ public class BackgroundServiceDefault implements BackgroundService2 {
             if(mixedInIfAny == null) {
                 newInstance = proxySubclass.newInstance();
             } else {
-                Constructor constructor = findConstructor(proxySubclass, mixedInIfAny);
+                Constructor<?> constructor = findConstructor(proxySubclass, mixedInIfAny);
                 newInstance = (T) constructor.newInstance(mixedInIfAny);
             }
             final ProxyObject proxyObject = (ProxyObject) newInstance;
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectWithCollection.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectWithCollection.java
index a6b55d3..004bd95 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectWithCollection.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/TestObjectWithCollection.java
@@ -23,10 +23,10 @@ import java.util.Vector;
 
 public class TestObjectWithCollection extends RuntimeTestPojo {
     
-    private final Vector arrayList;
+    private final Vector<Object> arrayList;
     private final boolean throwException;
 
-    public TestObjectWithCollection(final Vector arrayList, final boolean throwException) {
+    public TestObjectWithCollection(final Vector<Object> arrayList, final boolean throwException) {
         this.arrayList = arrayList;
         this.throwException = throwException;
     }

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.