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

editor.PathCompletionIntellisense Maven / Gradle / Ivy

There is a newer version: 1.18.1
Show newest version
package editor;

import gw.lang.parser.ISymbolTable;

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

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

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

  private static final List> HANDLER_TYPES = new ArrayList<>();
  static
  {
    HANDLER_TYPES.add( MemberPathCompletionHandler.class );
    HANDLER_TYPES.add( FeaturePathCompletionHandler.class );
    HANDLER_TYPES.add( StaticMemberPathCompletionHandler.class );
    HANDLER_TYPES.add( PackageCompletionHandler.class );
    HANDLER_TYPES.add( AnnotationCompletionHandler.class );
    HANDLER_TYPES.add( SymbolCompletionHandler.class );
    HANDLER_TYPES.add( InitializerCompletionHandler.class );
  }

  public static PathCompletionIntellisense instance()
  {
    return INSTANCE;
  }

  private PathCompletionIntellisense()
  {
  }

  public void complete( GosuEditor gsEditor, ISymbolTable transientSymTable )
  {
    List handlers = HANDLERS_BY_EDITOR.get( gsEditor );
    if( handlers == null )
    {
      handlers = initHandlers( gsEditor );
    }
    for( IPathCompletionHandler handler : handlers )
    {
      if( handler.handleCompletePath( transientSymTable ) )
      {
        break;
      }
    }
  }

  private List initHandlers( GosuEditor gsEditor )
  {
    List handlers = new ArrayList<>( HANDLER_TYPES.size() );
    for( Class type : HANDLER_TYPES )
    {
      try
      {
        IPathCompletionHandler 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 - 2024 Weber Informatics LLC | Privacy Policy