Added copyrights

Reformated code
Rearrnaged code
Changed the integration registry into a real singleton independent about its instantiation by other classes
This commit is contained in:
thatsIch
2014-11-13 14:48:04 +01:00
parent ae397b0256
commit b37d995d35
4 changed files with 174 additions and 99 deletions
@@ -1,10 +1,27 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.transformer.asm;
import java.util.Iterator;
import java.util.List;
import net.minecraft.launchwrapper.IClassTransformer;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
@@ -13,17 +30,19 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import net.minecraft.launchwrapper.IClassTransformer;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.transformer.annotations.integration;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
public class ASMIntegration implements IClassTransformer
{
private final IntegrationRegistry integrationModules = new IntegrationRegistry();
public ASMIntegration() {
public ASMIntegration()
{
/**
* Side, Display Name, ModID ClassPostFix
@@ -31,9 +50,9 @@ public class ASMIntegration implements IClassTransformer
for ( IntegrationType type : IntegrationType.values() )
{
integrationModules.add( type );
IntegrationRegistry.INSTANCE.add( type );
}
// integrationModules.add( IntegrationSide.BOTH, "Thermal Expansion", "ThermalExpansion", IntegrationType.TE );
// integrationModules.add( IntegrationSide.BOTH, "Mystcraft", "Mystcraft", IntegrationType.Mystcraft );
// integrationModules.add( IntegrationSide.BOTH, "Greg Tech", "gregtech_addon", IntegrationType.GT );
@@ -46,7 +65,7 @@ public class ASMIntegration implements IClassTransformer
}
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass)
public byte[] transform( String name, String transformedName, byte[] basicClass )
{
if ( basicClass == null || transformedName.startsWith( "appeng.transformer" ) )
return basicClass;
@@ -70,7 +89,7 @@ public class ASMIntegration implements IClassTransformer
return writer.toByteArray();
}
}
catch (Throwable t)
catch ( Throwable t )
{
t.printStackTrace();
}
@@ -78,13 +97,13 @@ public class ASMIntegration implements IClassTransformer
return basicClass;
}
private boolean removeOptionals(ClassNode classNode)
private boolean removeOptionals( ClassNode classNode )
{
boolean changed = false;
if ( classNode.visibleAnnotations != null )
{
for (AnnotationNode an : classNode.visibleAnnotations)
for ( AnnotationNode an : classNode.visibleAnnotations )
{
if ( hasAnnotation( an, integration.Interface.class ) )
{
@@ -93,9 +112,9 @@ public class ASMIntegration implements IClassTransformer
}
else if ( hasAnnotation( an, integration.InterfaceList.class ) )
{
for (Object o : ((List) an.values.get( 1 )))
for ( Object o : ( ( List ) an.values.get( 1 ) ) )
{
if ( stripInterface( classNode, integration.InterfaceList.class, (AnnotationNode) o ) )
if ( stripInterface( classNode, integration.InterfaceList.class, ( AnnotationNode ) o ) )
changed = true;
}
}
@@ -103,13 +122,13 @@ public class ASMIntegration implements IClassTransformer
}
Iterator<MethodNode> i = classNode.methods.iterator();
while (i.hasNext())
while ( i.hasNext() )
{
MethodNode mn = i.next();
if ( mn.visibleAnnotations != null )
{
for (AnnotationNode an : mn.visibleAnnotations)
for ( AnnotationNode an : mn.visibleAnnotations )
{
if ( hasAnnotation( an, integration.Method.class ) )
{
@@ -127,12 +146,12 @@ public class ASMIntegration implements IClassTransformer
return changed;
}
private boolean hasAnnotation(AnnotationNode ann, Class annotation)
private boolean hasAnnotation( AnnotationNode ann, Class annotation )
{
return ann.desc.equals( Type.getDescriptor( annotation ) );
}
private boolean stripMethod(ClassNode classNode, MethodNode mn, Iterator<MethodNode> i, Class class1, AnnotationNode an)
private boolean stripMethod( ClassNode classNode, MethodNode mn, Iterator<MethodNode> i, Class class1, AnnotationNode an )
{
if ( an.values.size() != 2 )
throw new RuntimeException( "Unable to handle Method annotation on " + classNode.name );
@@ -140,12 +159,12 @@ public class ASMIntegration implements IClassTransformer
String iName = null;
if ( an.values.get( 0 ).equals( "iname" ) )
iName = (String) an.values.get( 1 );
iName = ( String ) an.values.get( 1 );
if ( iName != null )
{
IntegrationType type = IntegrationType.valueOf( iName );
if ( !IntegrationRegistry.instance.isEnabled( type ) )
if ( !IntegrationRegistry.INSTANCE.isEnabled( type ) )
{
log( "Removing Method " + mn.name + " from " + classNode.name + " because " + iName + " integration is disabled." );
i.remove();
@@ -160,7 +179,7 @@ public class ASMIntegration implements IClassTransformer
return false;
}
private boolean stripInterface(ClassNode classNode, Class class1, AnnotationNode an)
private boolean stripInterface( ClassNode classNode, Class class1, AnnotationNode an )
{
if ( an.values.size() != 4 )
throw new RuntimeException( "Unable to handle Interface annotation on " + classNode.name );
@@ -169,20 +188,20 @@ public class ASMIntegration implements IClassTransformer
String iName = null;
if ( an.values.get( 0 ).equals( "iface" ) )
iFace = (String) an.values.get( 1 );
iFace = ( String ) an.values.get( 1 );
else if ( an.values.get( 2 ).equals( "iface" ) )
iFace = (String) an.values.get( 3 );
iFace = ( String ) an.values.get( 3 );
if ( an.values.get( 0 ).equals( "iname" ) )
iName = (String) an.values.get( 1 );
iName = ( String ) an.values.get( 1 );
else if ( an.values.get( 2 ).equals( "iname" ) )
iName = (String) an.values.get( 3 );
iName = ( String ) an.values.get( 3 );
IntegrationType type = IntegrationType.valueOf( iName );
if ( iName != null && iFace != null )
{
if ( !IntegrationRegistry.instance.isEnabled( type ) )
if ( !IntegrationRegistry.INSTANCE.isEnabled( type ) )
{
log( "Removing Interface " + iFace + " from " + classNode.name + " because " + iName + " integration is disabled." );
classNode.interfaces.remove( iFace.replace( '.', '/' ) );
@@ -197,7 +216,7 @@ public class ASMIntegration implements IClassTransformer
return false;
}
private void log(String string)
private void log( String string )
{
FMLRelaunchLog.log( "AE2-CORE", Level.INFO, string );
}