<s> package org . eclipse . jdt . internal . core ; import org . eclipse . jdt . core . * ; import org . eclipse . jdt . core . dom . ASTNode ; import org . eclipse . jdt . internal . compiler . lookup . Binding ; public class SourceField extends NamedMember implements IField { protected SourceField ( JavaElement parent , String name ) { super ( parent , name ) ; } public boolean equals ( Object o ) { if ( ! ( o instanceof SourceField ) ) return false ; return super . equals ( o ) ; } public ASTNode findNode ( org . eclipse . jdt . core . dom . CompilationUnit ast ) { ASTNode node = super . findNode ( ast ) ; if ( node == null ) return null ; if ( node . getNodeType ( ) == ASTNode . ENUM_CONSTANT_DECLARATION ) { return node ; } return node . getParent ( ) ; } public Object getConstant ( ) throws JavaModelException { Object constant = null ; SourceFieldElementInfo info = ( SourceFieldElementInfo ) getElementInfo ( ) ; final char [ ] constantSourceChars = info . initializationSource ; if ( constantSourceChars == null ) { return null ; } String constantSource = new String ( constantSourceChars ) ; String signature = info . getTypeSignature ( ) ; try { if ( signature . equals ( Signature . SIG_INT ) ) { constant = new Integer ( constantSource ) ; } else if ( signature . equals ( Signature . SIG_SHORT ) ) { constant = new Short ( constantSource ) ; } else if ( signature . equals ( Signature . SIG_BYTE ) ) { constant = new Byte ( constantSource ) ; } else if ( signature . equals ( Signature . SIG_BOOLEAN ) ) { constant = Boolean . valueOf ( constantSource ) ; } else if ( signature . equals ( Signature . SIG_CHAR ) ) { if ( constantSourceChars . length != 3 ) { return null ; } constant = new Character ( constantSourceChars [ 1 ] ) ; } else if ( signature . equals ( Signature . SIG_DOUBLE ) ) { constant = new Double ( constantSource ) ; } else if ( signature . equals ( Signature . SIG_FLOAT ) ) { constant = new Float ( constantSource ) ; } else if ( signature . equals ( Signature . SIG_LONG ) ) { if ( constantSource . endsWith ( "L" ) || constantSource . endsWith ( "l" ) ) { int index = constantSource . lastIndexOf ( "L" ) ; if ( index != - 1 ) { constant = new Long ( constantSource . substring ( 0 , index ) ) ; } else { constant = new Long ( constantSource . substring ( 0 , constantSource . lastIndexOf ( "l" ) ) ) ; } } else { constant = new Long ( constantSource ) ; } } else if ( signature . equals ( "QString;" ) ) { constant = constantSource ; } else if ( signature . equals ( "" ) ) { constant = constantSource ; } } catch ( NumberFormatException e ) { return null ; } return constant ; } public int getElementType ( ) { return FIELD ; } public String getKey ( ) { try { return getKey ( this , false ) ; } catch ( JavaModelException e ) { return null ; } } protected char getHandleMementoDelimiter ( ) { return JavaElement . JEM_FIELD ; } public IJavaElement getPrimaryElement ( boolean checkOwner ) { if ( checkOwner ) { CompilationUnit cu = ( CompilationUnit ) getAncestor ( COMPILATION_UNIT ) ; if ( cu . isPrimary ( ) ) return this ; } IJavaElement primaryParent = this . parent . getPrimaryElement ( false ) ; return ( ( IType ) primaryParent ) . getField ( this . name ) ; } public String getTypeSignature ( ) throws JavaModelException { SourceFieldElementInfo info = ( SourceFieldElementInfo ) getElementInfo ( ) ; return info . getTypeSignature ( ) ; } public boolean isEnumConstant ( ) throws JavaModelException { return Flags . isEnum ( getFlags ( ) ) ; } public boolean isResolved ( ) { return false ; } public JavaElement resolved ( Binding binding ) { SourceRefElement resolvedHandle = new ResolvedSourceField ( this . parent , this . name , new String ( binding . computeUniqueKey ( ) ) ) ; resolvedHandle . occurrenceCount = this . occurrenceCount ; return resolvedHandle ; } protected void toStringInfo ( int tab , StringBuffer buffer , Object info , boolean showResolvedInfo ) { buffer . append ( tabString ( tab ) ) ; if ( info == null ) { toStringName ( buffer ) ; buffer . append ( " (not open)" ) ; } else if ( info == NO_INFO ) { toStringName ( buffer ) ; } else { try { buffer . append ( Signature . toString ( getTypeSignature ( ) ) ) ; buffer . append ( " " ) ; toStringName ( buffer ) ; } catch ( JavaModelException e ) { buffer . append ( "" + getElementName ( ) ) ; } } } } </s>