All Downloads are FREE. Search and download functionalities are using the official Maven repository.

editor.ValueCompletionIntellisense Maven / Gradle / Ivy

package editor;

import java.util.ArrayList;
import java.util.List;
import java.util.WeakHashMap;

/**
 */
public class ValueCompletionIntellisense
{
  private static final ValueCompletionIntellisense INSTANCE = new ValueCompletionIntellisense();

  private static final WeakHashMap> HANDLERS_BY_EDITOR = new WeakHashMap>();

  private static final List> HANDLER_TYPES =
    new ArrayList>();

  static
  {
    HANDLER_TYPES.add( MemberAccessValueCompletion.class );
    HANDLER_TYPES.add( BeanMethodCallValueCompletion.class );
    HANDLER_TYPES.add( BooleanValueCompletion.class );
    HANDLER_TYPES.add( NumberValueCompletion.class );
    HANDLER_TYPES.add( EnumerationValueCompletion.class );
    HANDLER_TYPES.add( StringValueCompletion.class );
  }

  public static ValueCompletionIntellisense instance()
  {
    return INSTANCE;
  }

  private ValueCompletionIntellisense()
  {
  }

  public boolean complete( GosuEditor gsEditor )
  {
    List handlers = HANDLERS_BY_EDITOR.get( gsEditor );
    if( handlers == null )
    {
      handlers = initHandlers( gsEditor );
    }
    for( IValueCompletionHandler handler : handlers )
    {
      if( handler.handleCompleteValue() )
      {
        return true;
      }
    }
    return false;
  }

  private List initHandlers( GosuEditor gsEditor )
  {
    List handlers = new ArrayList( HANDLER_TYPES.size() );
    for( Class type : HANDLER_TYPES )
    {
      try
      {
        IValueCompletionHandler handler = type.newInstance();
        handlers.add( handler );
        handler.setGosuEditor( gsEditor );
      }
      catch( Exception e )
      {
        throw new RuntimeException( e );
      }
    }
    HANDLERS_BY_EDITOR.put( gsEditor, handlers );
    return handlers;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy