Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  
  package com.google.code.joto.procesors;
  
  

Author(s):
epere4
liliana.nu
 
 public class MultitonProcessor
     implements CustomProcessor
 {

    
 
     public boolean canProcessThisObject objectToProcess )
     {
         return objectToProcess != null && hasFieldOrMethodForThisInstanceobjectToProcess );
     }

    
 
     public void processThisObject objectToProcessReverseEngineerData sharedDataint depthLevel,
                              ProcessMoreCallback callback )
         throws Exception
     {
         FieldAndMethodCandidates candidates = getFieldAndMethodCandidatesForObjectobjectToProcess );
 
         sharedData.concat( ReverseEngineerHelper.getTypeAsStringobjectToProcess ), "." );
         if (candidates.candidateMethod != null) {
             sharedData.concatcandidates.candidateMethod.getName(), "()" );
         }
         else
         {
             sharedData.concatcandidates.candidateField.getName() );
         }
     }
 
     private boolean hasFieldOrMethodForThisInstanceObject objectToProcess )
     {
         FieldAndMethodCandidates candidates = getFieldAndMethodCandidatesForObjectobjectToProcess );
 
         return candidates.candidateField != null || candidates.candidateMethod != null;
     }
 
     {
         FieldAndMethodCandidates candidates = new FieldAndMethodCandidates();
 
         Class<? extends Objectclazz = objectToProcess.getClass();
         while ( clazz != null && ( candidates.candidateField == null && candidates.candidateMethod == null ) )
         {
             if ( candidates.candidateField == null )
             {
                 candidates.candidateField = getCandidateFieldForClassclazzobjectToProcess );
             }
             if ( candidates.candidateMethod == null )
             {
                 candidates.candidateMethod = getCandidateMethodForClassclazzobjectToProcess );
             }
             clazz = clazz.getSuperclass();
         }
         return candidates;
     }
 
     private Method getCandidateMethodForClassClass<? extends ObjectclazzObject objectToProcess )
     {
         Method[] methods = clazz.getDeclaredMethods();
         for ( Method method : methods )
         {
             if ( Modifier.isPublicmethod.getModifiers() ) && Modifier.isStaticmethod.getModifiers() )
                 && hasNoParametersmethod ) && returnTypeInstanceOfObjectToProcessTypemethodobjectToProcess ) )
             {
                 if ( ReverseEngineerReflectionUtil.invokeMethodmethodnull ) == objectToProcess )
                 {
                     return method;
                 }
             }
         }
         return null;
     }
 
     private Field getCandidateFieldForClassClass<? extends ObjectclazzObject objectToProcess )
     {
         Field[] fields = clazz.getDeclaredFields();
         for ( Field field : fields )
        {
            if ( Modifier.isStaticfield.getModifiers() ) )
            {
                if ( ReverseEngineerReflectionUtil.getFieldValuenullfield ) == objectToProcess )
                {
                    return field;
                }
            }
        }
        return null;
    }
    private boolean returnTypeInstanceOfObjectToProcessTypeMethod methodObject objectToProcess )
    {
        return objectToProcess.getClass().isAssignableFrommethod.getReturnType() );
    }
    private boolean hasNoParametersMethod method )
    {
        return method.getParameterTypes().length == 0;
    }
    private static class FieldAndMethodCandidates
    {
        public Field candidateField;
        public Method candidateMethod;
    }
New to GrepCode? Check out our FAQ X