1 11 package org.eclipse.jdt.internal.compiler.lookup; 12 13 import org.eclipse.jdt.internal.compiler.ast.*; 14 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; 15 import org.eclipse.jdt.internal.compiler.impl.Constant; 16 17 public class ElementValuePair { 18 char[] name; 19 public Object value; 20 public MethodBinding binding; 21 22 public static Object getValue(Expression expression) { 23 if (expression == null) 24 return null; 25 Constant constant = expression.constant; 26 if (constant != null && constant != Constant.NotAConstant) 28 return constant; 29 30 if (expression instanceof Annotation) 31 return ((Annotation) expression).getCompilerAnnotation(); 32 if (expression instanceof ArrayInitializer) { 33 Expression[] exprs = ((ArrayInitializer) expression).expressions; 34 int length = exprs == null ? 0 : exprs.length; 35 Object [] values = new Object [length]; 36 for (int i = 0; i < length; i++) 37 values[i] = getValue(exprs[i]); 38 return values; 39 } 40 if (expression instanceof ClassLiteralAccess) 41 return ((ClassLiteralAccess) expression).targetType; 42 if (expression instanceof Reference) { 43 FieldBinding fieldBinding = null; 44 if (expression instanceof FieldReference) { 45 fieldBinding = ((FieldReference) expression).fieldBinding(); 46 } else if (expression instanceof NameReference) { 47 Binding binding = ((NameReference) expression).binding; 48 if (binding != null && binding.kind() == Binding.FIELD) 49 fieldBinding = (FieldBinding) binding; 50 } 51 if (fieldBinding != null && (fieldBinding.modifiers & ClassFileConstants.AccEnum) > 0) 52 return fieldBinding; 53 } 54 return null; 56 } 57 58 public ElementValuePair(char[] name, Expression expression, MethodBinding binding) { 59 this(name, ElementValuePair.getValue(expression), binding); 60 } 61 62 public ElementValuePair(char[] name, Object value, MethodBinding binding) { 63 this.name = name; 64 this.value = value; 65 this.binding = binding; 66 } 67 68 71 public char[] getName() { 72 return this.name; 73 } 74 75 78 public MethodBinding getMethodBinding() { 79 return this.binding; 80 } 81 82 90 public Object getValue() { 91 return this.value; 92 } 93 94 void setMethodBinding(MethodBinding binding) { 95 this.binding = binding; 97 } 98 99 void setValue(Object value) { 100 this.value = value; 102 } 103 } 104 | Popular Tags |