Skip to content

Instantly share code, notes, and snippets.

@maryokhin
Created September 26, 2013 18:33
Show Gist options
  • Save maryokhin/6718560 to your computer and use it in GitHub Desktop.
Save maryokhin/6718560 to your computer and use it in GitHub Desktop.
enum
public enum AttributeNameEnum {
TypeCheckValid(SignatureAttribute.class,1,2,3),
Signature,
GLOBAL_SIGNATURE,
Name,
Type,
EnvironmentClass,
EnvironmentMethod,
Environment,
VariableName,
OperandsCount,
QualifiedScope,
Def;
private List<Integer> toApplayList;
private Class attributeInstanseClass;
private AttributeNameEnum(Class clazz, Integer ... constansArray){
attributeInstanseClass = clazz;
toApplayList = Arrays.asList(constansArray);
}
@SuppressWarnings("unchecked")
public static Map<AttributeNameEnum, Attribute> getAttributesForNode(AttributedNode node) {
HashMap<AttributeNameEnum, Attribute> result = new HashMap<AttributeNameEnum, Attribute>();
for(AttributeNameEnum currentName: AttributeNameEnum.values()){
if(currentName.toApplayList.contains(node.getType())){
try {
Constructor<Attribute> constructor = currentName.attributeInstanseClass.getConstructor(AttributedNode.class);
Attribute attributeInstance = constructor.newInstance(node);
result.put(currentName,attributeInstance);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment