PDA

View Full Version : HolyHalfDead's Application


HolyHalfDead
02-12-2008, 07:46 AM
Name: Alexander "HolyHalfDead"
Age: 21
Location: Texas
Skills: I'm well versed with Linux/Windows (prefer linux). OOP is simplistic to me. Pretty much all (good) video game engines are based off the quake engine, so I assume, heh-assert, I'm decent with them. I code in C++/Java most often, although Pascal derivatives such as Delphi are interesting from time to time
Experience: Hardly anything legal.
Examples: Edit: Although not under any license currently, I still maintain intellectual property rights.
package bytecode;

import bytecode.attributes.*;
import bytecode.constants.ConstantClass;
import bytecode.constants.ConstantPool;
import bytecode.constants.ConstantUTF8;
import bytecode.members.Field;
import bytecode.members.Method;

/**
* The base object for java class files in an OOP accessible context. This is the base for the bytecode editing framework for use as a base lib in projects needing on the fly morphing and/or creation of java code based on user defined intelligence within other java applications.
*
* IE: for(ClassFile cf : classes) { if(!cf.isPublic()) cf.setPublic(true); }
* Effectively morphs all classfiles accessor bits to public allowing java.lang.reflect packages to actively read data from the application once executed through the ClassLoader api.
* @author Alex
*/
@SuppressWarnings({"FinalPrivateMethod"})
public final class ClassFile {
int version_minor;
int version_major;
ConstantPool constant_pool;
int access_flags;
int index_this;
int index_super;
int interfaces[];
Field fields[];
Method methods[];
AttributeList attributes;

public final AttributeList getAttributes() {
return attributes;
}

public final void setAttributes(AttributeList attributes) {
this.attributes = attributes;
}

public final AttributeInnerClasses getInnerClasses() {
return attributes.get("InnerClasses");
}

public final void setInnerClasses(AttributeInnerClasses ic) {
attributes.put("InnerClasses", ic);
}

public final AttributeEnclosingMethod getEnclosingMethod() {
return attributes.get("EnclosingMethod");
}

public final void setEnclosingMethod(AttributeEnclosingMethod em) {
attributes.put("EnclosingMethod", em);
}

public final AttributeSignature getSignature() {
return attributes.get("Signature");
}

public final void setSignature(int index) {
attributes.put("Signature", new AttributeSignature(index));
}

public final int getSourceFileIndex() {
return ((AttributeSourceFile) attributes.get("SourceFile")).getIndex();
}

public final String getSourceFile() {
return constant_pool.getUTF8(getSourceFileIndex());
}

public final void setSourceFile(int index) {
attributes.put("SourceFile", new AttributeSourceFile(index));
}

public final boolean isDeprecated() {
return attributes.contains("Deprecated");
}

public final void setDeprecated(boolean toggle) {
if (toggle) {
attributes.put("Deprecated", new AttributeDeprecated());
} else {
attributes.remove("Deprecated");
}
}

public final boolean isSyntheticAttribute() {
return attributes.contains("Synthetic");
}

public final void setSyntheticAttribute(boolean toggle) {
if (toggle) {
attributes.put("Synthetic", new AttributeSynthetic());
} else {
attributes.remove("Synthetic");
}
}

public final Method[] getMethods() {
return methods;
}

public final Field[] getFields() {
return fields;
}

public final String[] getInterfaces() {
String ifaces[] = new String[interfaces.length];
for (int i = 0; i < ifaces.length; i++) {
ConstantClass constantclass = constant_pool.get(interfaces[i]);
ConstantUTF8 constantutf8 = constant_pool.get(constantclass.index);
ifaces[i] = constantutf8.value.replaceAll("/", ".");
}
return ifaces;
}

public final String getName() {
ConstantClass constantclass = constant_pool.get(index_this);
ConstantUTF8 constantutf8 = constant_pool.get(constantclass.index);
return constantutf8.value.replaceAll("/", ".");
}

public final int getNameIndex() {
return index_this;
}

public final String getSuperName() {
ConstantClass constantclass = constant_pool.get(index_super);
ConstantUTF8 constantutf8 = constant_pool.get(constantclass.index);
return constantutf8.value.replaceAll("/", ".");
}

public final String getVersion() {
return version_major + "." + version_minor;
}

public final void setVersion(String version) {
if (version != null && version.length() > 2) {
if (version.matches("[0-9]{1,2}\\.[0-9]{1,2}")) {
String versions[] = version.split("\\.");
version_major = Integer.parseInt(versions[0]);
version_minor = Integer.parseInt(versions[1]);
}
}
}

public final ConstantPool getConstantPool() {
return constant_pool;
}

public final void setConstantPool(ConstantPool cp) {
constant_pool = cp;
}

private final void setAccessFlag(boolean toggle, int accessflag) {
if ((accessflag & accessflag) != 0) {
if (!toggle) {
access_flags ^= accessflag;
}
} else {
if (toggle) {
access_flags ^= accessflag;
}
}
}

public final boolean isPublic() {
return (access_flags & Constants.ACCESS_PUBLIC) != 0;
}

public final void setPublic(boolean toggle) {
setAccessFlag(toggle, Constants.ACCESS_PUBLIC);
}

public final boolean isFinal() {
return (access_flags & Constants.ACCESS_FINAL) != 0;
}

public final void setFinal(boolean toggle) {
setAccessFlag(toggle, Constants.ACCESS_FINAL);
if (toggle) {
setAbstract(false);
}
}

public final boolean isSuper() {
return (access_flags & Constants.ACCESS_SUPER) != 0;
}

public final void setSuper(boolean toggle) {
setAccessFlag(toggle, Constants.ACCESS_SUPER);
}

public final boolean isInterface() {
return (access_flags & Constants.ACCESS_INTERFACE) != 0;
}

public final void setInterface(boolean toggle) {
setAccessFlag(toggle, Constants.ACCESS_INTERFACE);
if (toggle) {
setAbstract(true);
setFinal(false);
setSuper(false);
setEnum(false);
}
}

public final boolean isAnnotation() {
return (access_flags & Constants.ACCESS_ANNOTATION) != 0;
}

public final void setAnnotation(boolean toggle) {
setAccessFlag(toggle, Constants.ACCESS_ANNOTATION);
if (toggle) {
setInterface(true);
}
}

public final boolean isAbstract() {
return (access_flags & Constants.ACCESS_ABSTRACT) != 0;
}

public final void setAbstract(boolean toggle) {
setAccessFlag(toggle, Constants.ACCESS_ABSTRACT);
if (toggle) {
setFinal(false);
}
}

public final boolean isSynthetic() {
return (access_flags & Constants.ACCESS_SYNTHETIC) != 0;
}

public final void setSynthetic(boolean toggle) {
setAccessFlag(toggle, Constants.ACCESS_SYNTHETIC);
}

public final boolean isEnum() {
return (access_flags & Constants.ACCESS_ENUM) != 0;
}

public final void setEnum(boolean toggle) {
setAccessFlag(toggle, Constants.ACCESS_ENUM);
}

}

frikazoyd
02-12-2008, 10:29 AM
In the code you posted, why is nearly 3/4 of the code just accessor functions when all of the variables are public?