Commit a079b303 authored by Lionel Seinturier's avatar Lionel Seinturier
Browse files

Improve typing.

parent 835190fa
......@@ -62,7 +62,7 @@ extends BasicComponentInterface implements ClassLoaderItf {
private ClassLoaderItf impl;
public Class loadClass( String name ) throws ClassNotFoundException {
public Class<?> loadClass( String name ) throws ClassNotFoundException {
if (impl == null)
throw new NullPointerException(
"Trying to invoke a method on a client interface, or on a server interface whose complementary interface is not bound.");
......
......@@ -38,5 +38,5 @@ public interface ClassLoaderItf {
* @return the corresponding class
* @throws ClassNotFoundException if the class can not be found
*/
public Class loadClass( String name ) throws ClassNotFoundException;
public Class<?> loadClass( String name ) throws ClassNotFoundException;
}
......@@ -23,7 +23,7 @@
package org.objectweb.fractal.juliac.runtime;
import java.util.Iterator;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;
import java.util.TreeSet;
......@@ -90,11 +90,11 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
Object contDesc = checkContentDesc(ctrlDesc,contentDesc);
String factoryClassName = getFactoryClassName(ct,ctrlDesc,contDesc);
Class cl = loadClassIE(factoryClassName);
Class<?> cl = loadClassIE(factoryClassName);
Object f = instanciateClass(cl);
if( ! (f instanceof Factory) ) {
String msg =
final String msg =
"Component initializer class "+factoryClassName+
" should implement "+Factory.class.getName();
throw new InstantiationException(msg);
......@@ -127,7 +127,7 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
throws InstantiationException {
if( !(type instanceof ComponentType) ) {
String msg = "type should implement ComponentType";
final String msg = "type should implement ComponentType";
throw new InstantiationException(msg);
}
......@@ -167,7 +167,7 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
}
if( !(controllerDesc instanceof String) ) {
String msg = "controllerDesc should be a String";
final String msg = "controllerDesc should be a String";
throw new InstantiationException(msg);
}
......@@ -190,6 +190,7 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
* @param contentDesc the content descriptor to analyze
* @return the extracted content descriptor
*/
@SuppressWarnings("unused")
protected Object checkContentDesc( String ctrlDesc, Object contentDesc )
/*
* thrown by sublcasses, e.g.
......@@ -230,7 +231,7 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
* rationale for this choice.
*/
InterfaceType[] its = ct.getFcInterfaceTypes();
Set names = new TreeSet();
Set<String> names = new TreeSet<>();
for (int i = 0; i < its.length; i++) {
InterfaceType it = its[i];
String name = it.getFcItfName();
......@@ -239,8 +240,7 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
StringBuffer sct = new StringBuffer("[");
boolean first = true;
for (Iterator iterator = names.iterator(); iterator.hasNext();) {
String name = (String) iterator.next();
for (String name : names) {
InterfaceType it = null;
try {
it = ct.getFcInterfaceType(name);
......@@ -288,7 +288,7 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
* A thread local object which may contain the class loader specified when
* calling {@link #newFcInstance(Type, Object, Object)}.
*/
private ThreadLocal tl = new ThreadLocal();
private ThreadLocal<ClassLoader> tl = new ThreadLocal<>();
/**
* Load the class whose name is specified.
......@@ -298,9 +298,9 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
* @throws ClassNotFoundException if the class can not be found
* @since 2.1.2
*/
public Class loadClass( String name ) throws ClassNotFoundException {
public Class<?> loadClass( String name ) throws ClassNotFoundException {
ClassLoader cl = getClassLoader();
Class c = cl.loadClass(name);
Class<?> c = cl.loadClass(name);
return c;
}
......@@ -322,9 +322,9 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
// Utility method
// -----------------------------------------------------------------
protected Class loadClassIE( String name ) throws InstantiationException {
protected Class<?> loadClassIE( String name ) throws InstantiationException {
try {
Class cl = loadClass(name);
Class<?> cl = loadClass(name);
return cl;
}
catch( ClassNotFoundException cnfe ) {
......@@ -332,17 +332,17 @@ implements TypeFactory, GenericFactory, ClassLoaderItf, Component {
}
}
protected Object instanciateClass( Class cl )
protected Object instanciateClass( Class<?> cl )
throws InstantiationException {
try {
Object o = cl.newInstance();
Object o = cl.getConstructor().newInstance();
return o;
}
catch( java.lang.InstantiationException ie ) {
throw new ChainedInstantiationException(ie,null,"");
}
catch( IllegalAccessException iae ) {
throw new ChainedInstantiationException(iae,null,"");
catch(
java.lang.InstantiationException | IllegalAccessException |
IllegalArgumentException | InvocationTargetException |
NoSuchMethodException e ) {
throw new ChainedInstantiationException(e,null,"");
}
}
......
......@@ -23,6 +23,8 @@
package org.objectweb.fractal.juliac.runtime;
import java.lang.reflect.InvocationTargetException;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
......@@ -49,12 +51,16 @@ public class Launcher {
/**
* Entry point for this program.
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
*/
public static void main(String[] args)
throws
ClassNotFoundException, InstantiationException, IllegalAccessException,
java.lang.InstantiationException, IllegalArgumentException,
NoSuchInterfaceException, IllegalLifeCycleException {
NoSuchInterfaceException, IllegalLifeCycleException,
InvocationTargetException, NoSuchMethodException {
if( args.length==0 || args.length>2 ) {
usage();
......@@ -65,8 +71,8 @@ public class Launcher {
* Retrieve the factory.
*/
String adl = args[0];
Class cl = Class.forName(adl);
Object o = cl.newInstance();
Class<?> cl = Class.forName(adl);
Object o = cl.getConstructor().newInstance();
if( o instanceof Factory ) {
......@@ -85,7 +91,7 @@ public class Launcher {
String itfname = args[1];
Object itf = root.getFcInterface(itfname);
if( !(itf instanceof Runnable) ) {
String msg =
final String msg =
"The "+itfname+
" interface should implement java.lang.Runnable";
throw new IllegalArgumentException(msg);
......@@ -101,7 +107,7 @@ public class Launcher {
((Runnable)o).run();
}
else {
String msg = "Illegal factory class: "+adl;
final String msg = "Illegal factory class: "+adl;
throw new IllegalArgumentException(msg);
}
}
......
......@@ -24,6 +24,9 @@
package org.objectweb.fractal.juliac.runtime;
import java.util.ArrayList;
import java.util.HashMap;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Type;
import org.objectweb.fractal.api.factory.InstantiationException;
......@@ -43,8 +46,8 @@ public class MembraneInitializer implements Factory {
protected InitializationContext initFcInitializationContext() {
InitializationContext ic = new InitializationContext();
ic.controllers = new java.util.ArrayList();
ic.interfaces = new java.util.HashMap();
ic.controllers = new ArrayList<>();
ic.interfaces = new HashMap<>();
return ic;
}
......@@ -71,23 +74,23 @@ public class MembraneInitializer implements Factory {
* @since 2.5
*/
protected Object getFcController(
InitializationContext ic, Object content, Class ctrlcl )
InitializationContext ic, Object content, Class<?> ctrlcl )
throws InstantiationException {
for( int i=0 ; i < ic.controllers.size() ; i++ ) {
Object ctrl = ic.controllers.get(i);
Class cl = ctrl.getClass();
Class<?> cl = ctrl.getClass();
if( ctrlcl.isAssignableFrom(cl) ) {
return ctrl;
}
}
Class cl = content.getClass();
Class<?> cl = content.getClass();
if( ctrlcl.isAssignableFrom(cl) ) {
return content;
}
String msg = "No such controller for "+ctrlcl.getName();
final String msg = "No such controller for "+ctrlcl.getName();
throw new InstantiationException(msg);
}
......@@ -110,6 +113,7 @@ public class MembraneInitializer implements Factory {
/**
* @since 2.6
*/
@SuppressWarnings("unused")
public Object newFcContent() throws InstantiationException
{
throw new UnsupportedOperationException();
......
......@@ -49,18 +49,22 @@ public class RuntimeException extends java.lang.RuntimeException {
this.cause = cause;
}
@Override
public String getMessage() {
return cause.getMessage();
}
@Override
public void printStackTrace() {
cause.printStackTrace();
}
@Override
public void printStackTrace( PrintStream ps ) {
cause.printStackTrace(ps);
}
@Override
public void printStackTrace( PrintWriter pw ) {
cause.printStackTrace(pw);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment