Created
September 26, 2013 18:33
-
-
Save maryokhin/6718560 to your computer and use it in GitHub Desktop.
enum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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