|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2005 BEA Systems, Inc. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* tyeung@bea.com - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.jdt.core.dom; |
| 12 |
|
| 13 |
import org.eclipse.jdt.internal.compiler.impl.Constant; |
| 14 |
import org.eclipse.jdt.internal.compiler.lookup.TypeIds; |
| 15 |
|
| 16 |
/** |
| 17 |
* Internal class. |
| 18 |
*/ |
| 19 |
class ResolvedMemberValuePair implements IResolvedMemberValuePair |
| 20 |
{ |
| 21 |
static final ResolvedMemberValuePair[] NoPair = new ResolvedMemberValuePair[0]; |
| 22 |
private static final Object NoValue = new Object(); |
| 23 |
private final org.eclipse.jdt.internal.compiler.lookup.IElementValuePair internalPair; |
| 24 |
private Object value = null; |
| 25 |
private final BindingResolver bindingResolver; |
| 26 |
|
| 27 |
ResolvedMemberValuePair(final org.eclipse.jdt.internal.compiler.lookup.IElementValuePair pair, |
| 28 |
BindingResolver resolver) |
| 29 |
{ |
| 30 |
this.internalPair = pair; |
| 31 |
this.bindingResolver = resolver; |
| 32 |
} |
| 33 |
|
| 34 |
private void init() |
| 35 |
{ |
| 36 |
final org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = this.internalPair.getType(); |
| 37 |
this.value = buildDOMValue(this.internalPair.getValue(), type, this.bindingResolver); |
| 38 |
if( this.value == null ) |
| 39 |
this.value = NoValue; |
| 40 |
} |
| 41 |
|
| 42 |
static Object buildDOMValue(final Object internalObject, |
| 43 |
org.eclipse.jdt.internal.compiler.lookup.TypeBinding type, |
| 44 |
BindingResolver resolver) |
| 45 |
{ |
| 46 |
if( internalObject == null || type == null ) return null; |
| 47 |
switch(type.id) |
| 48 |
{ |
| 49 |
case TypeIds.T_boolean: |
| 50 |
return new Boolean( ((Constant)internalObject).booleanValue() ); |
| 51 |
case TypeIds.T_byte: |
| 52 |
return new Byte( ((Constant)internalObject).byteValue() ); |
| 53 |
case TypeIds.T_char: |
| 54 |
return new Character( ((Constant)internalObject).charValue() ); |
| 55 |
case TypeIds.T_double: |
| 56 |
return new Double( ((Constant)internalObject).doubleValue() ); |
| 57 |
case TypeIds.T_float: |
| 58 |
return new Float( ((Constant)internalObject).floatValue() ); |
| 59 |
case TypeIds.T_int: |
| 60 |
return new Integer( ((Constant)internalObject).intValue() ); |
| 61 |
case TypeIds.T_long: |
| 62 |
return new Long( ((Constant)internalObject).longValue() ); |
| 63 |
case TypeIds.T_short: |
| 64 |
return new Short( ((Constant)internalObject).shortValue() ); |
| 65 |
case TypeIds.T_JavaLangString: |
| 66 |
return internalObject; |
| 67 |
case TypeIds.T_JavaLangClass: |
| 68 |
return resolver.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)internalObject); |
| 69 |
} |
| 70 |
|
| 71 |
if( type.isAnnotationType() ){ |
| 72 |
return new ResolvedAnnotation( |
| 73 |
(org.eclipse.jdt.internal.compiler.lookup.IAnnotationInstance)internalObject, |
| 74 |
resolver); |
| 75 |
} |
| 76 |
else if( type.isEnum() ){ |
| 77 |
return resolver.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding)internalObject); |
| 78 |
} |
| 79 |
else if( type.isArrayType() ){ |
| 80 |
final Object[] iElements = (Object[])internalObject; |
| 81 |
final int len = iElements.length; |
| 82 |
Object[] values = null; |
| 83 |
if( len > 0){ |
| 84 |
final org.eclipse.jdt.internal.compiler.lookup.TypeBinding elementType = |
| 85 |
((org.eclipse.jdt.internal.compiler.lookup.ArrayBinding)type).leafComponentType; |
| 86 |
values = new Object[len]; |
| 87 |
for( int i=0; i<len; i++ ){ |
| 88 |
values[i] = buildDOMValue(iElements[i], elementType, resolver); |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
throw new IllegalStateException(); // should never get here. |
| 93 |
} |
| 94 |
|
| 95 |
public String getName() { |
| 96 |
final char[] membername = this.internalPair.getMemberName(); |
| 97 |
return membername == null ? null : new String(membername); |
| 98 |
} |
| 99 |
|
| 100 |
public IMethodBinding getMemberBinding() { |
| 101 |
return this.bindingResolver.getMethodBinding(this.internalPair.getMethodBinding()); |
| 102 |
} |
| 103 |
|
| 104 |
public Object getValue() { |
| 105 |
if( value == null ) |
| 106 |
init(); |
| 107 |
return value == NoValue ? null : this.value; |
| 108 |
} |
| 109 |
} |