Fix scala supporting SidedProxy. It should work now.
This commit is contained in:
parent
6c0bb61425
commit
3446f1ce26
4 changed files with 60 additions and 28 deletions
|
@ -108,34 +108,13 @@ public class FMLModContainer implements ModContainer
|
|||
private String modLanguage;
|
||||
private ILanguageAdapter languageAdapter;
|
||||
|
||||
public static interface ILanguageAdapter {
|
||||
public Object getNewInstance(FMLModContainer container, Class<?> objectClass, ClassLoader classLoader) throws Exception;
|
||||
}
|
||||
|
||||
public static class ScalaAdapter implements ILanguageAdapter {
|
||||
@Override
|
||||
public Object getNewInstance(FMLModContainer container, Class<?> scalaObjectClass, ClassLoader classLoader) throws Exception
|
||||
{
|
||||
System.out.println("Scala class : "+ scalaObjectClass);
|
||||
Class<?> sObjectClass = Class.forName(scalaObjectClass.getName()+"$",true,classLoader);
|
||||
return sObjectClass.getField("MODULE$").get(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static class JavaAdapter implements ILanguageAdapter {
|
||||
@Override
|
||||
public Object getNewInstance(FMLModContainer container, Class<?> objectClass, ClassLoader classLoader) throws Exception
|
||||
{
|
||||
return objectClass.newInstance();
|
||||
}
|
||||
}
|
||||
public FMLModContainer(String className, File modSource, Map<String,Object> modDescriptor)
|
||||
{
|
||||
this.className = className;
|
||||
this.source = modSource;
|
||||
this.descriptor = modDescriptor;
|
||||
this.modLanguage = (String) modDescriptor.get("modLanguage");
|
||||
this.languageAdapter = "scala".equals(modLanguage) ? new ScalaAdapter() : new JavaAdapter();
|
||||
this.languageAdapter = "scala".equals(modLanguage) ? new ILanguageAdapter.ScalaAdapter() : new ILanguageAdapter.JavaAdapter();
|
||||
}
|
||||
|
||||
private ILanguageAdapter getLanguageAdapter()
|
||||
|
@ -489,7 +468,7 @@ public class FMLModContainer implements ModContainer
|
|||
{
|
||||
eventBus.post(new FMLFingerprintViolationEvent(source.isDirectory(), source, ImmutableSet.copyOf(this.sourceFingerprints), expectedFingerprint));
|
||||
}
|
||||
ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide());
|
||||
ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), getLanguageAdapter());
|
||||
processFieldAnnotations(event.getASMHarvestedData());
|
||||
}
|
||||
catch (Throwable e)
|
||||
|
|
52
fml/common/cpw/mods/fml/common/ILanguageAdapter.java
Normal file
52
fml/common/cpw/mods/fml/common/ILanguageAdapter.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package cpw.mods.fml.common;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public interface ILanguageAdapter {
|
||||
public Object getNewInstance(FMLModContainer container, Class<?> objectClass, ClassLoader classLoader) throws Exception;
|
||||
public boolean supportsStatics();
|
||||
public void setProxy(Field target, Class<?> proxyTarget, Object proxy) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException;
|
||||
|
||||
public static class ScalaAdapter implements ILanguageAdapter {
|
||||
@Override
|
||||
public Object getNewInstance(FMLModContainer container, Class<?> scalaObjectClass, ClassLoader classLoader) throws Exception
|
||||
{
|
||||
Class<?> sObjectClass = Class.forName(scalaObjectClass.getName()+"$",true,classLoader);
|
||||
return sObjectClass.getField("MODULE$").get(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsStatics()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProxy(Field target, Class<?> proxyTarget, Object proxy) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException
|
||||
{
|
||||
Field field = proxyTarget.getField("INSTANCE");
|
||||
Object scalaObject = field.get(null);
|
||||
target.set(scalaObject, proxy);
|
||||
}
|
||||
}
|
||||
public static class JavaAdapter implements ILanguageAdapter {
|
||||
@Override
|
||||
public Object getNewInstance(FMLModContainer container, Class<?> objectClass, ClassLoader classLoader) throws Exception
|
||||
{
|
||||
return objectClass.newInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsStatics()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProxy(Field target, Class<?> proxyTarget, Object proxy) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException,
|
||||
SecurityException
|
||||
{
|
||||
target.set(null, proxy);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ import cpw.mods.fml.relauncher.Side;
|
|||
*/
|
||||
public class ProxyInjector
|
||||
{
|
||||
public static void inject(ModContainer mod, ASMDataTable data, Side side)
|
||||
public static void inject(ModContainer mod, ASMDataTable data, Side side, ILanguageAdapter languageAdapter)
|
||||
{
|
||||
FMLLog.fine("Attempting to inject @SidedProxy classes into %s", mod.getModId());
|
||||
Set<ASMData> targets = data.getAnnotationsFor(mod).get(SidedProxy.class.getName());
|
||||
|
@ -49,7 +49,7 @@ public class ProxyInjector
|
|||
String targetType = side.isClient() ? target.getAnnotation(SidedProxy.class).clientSide() : target.getAnnotation(SidedProxy.class).serverSide();
|
||||
Object proxy=Class.forName(targetType, true, mcl).newInstance();
|
||||
|
||||
if ((target.getModifiers() & Modifier.STATIC) == 0 )
|
||||
if (languageAdapter.supportsStatics() && (target.getModifiers() & Modifier.STATIC) == 0 )
|
||||
{
|
||||
FMLLog.severe("Attempted to load a proxy type %s into %s.%s, but the field is not static", targetType, targ.getClassName(), targ.getObjectName());
|
||||
throw new LoaderException();
|
||||
|
@ -59,7 +59,7 @@ public class ProxyInjector
|
|||
FMLLog.severe("Attempted to load a proxy type %s into %s.%s, but the types don't match", targetType, targ.getClassName(), targ.getObjectName());
|
||||
throw new LoaderException();
|
||||
}
|
||||
target.set(null, proxy);
|
||||
languageAdapter.setProxy(target, proxyTarget, proxy);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@ import com.google.common.eventbus.Subscribe;
|
|||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.ILanguageAdapter;
|
||||
import cpw.mods.fml.common.LoadController;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.LoaderException;
|
||||
|
@ -496,7 +497,7 @@ public class ModLoaderModContainer implements ModContainer
|
|||
{
|
||||
dummyHandler.setBaseMod(mod);
|
||||
}
|
||||
ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide());
|
||||
ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), new ILanguageAdapter.JavaAdapter());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue