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

net.sourceforge.squirrel_sql.fw.completion.util.CompletionParser Maven / Gradle / Ivy

Go to download

The framework library contains utility classes that are generic and useful for building applications that introspect a database via JDBC. These are not intended to be SQuirreLSQL-specific and could be used by other projects JDBC front-end applications. This project is guaranteed to have no code dependencies on other SQuirreLSQL projects and could therefore be used when building a different JDBC front-end application.

There is a newer version: 3.5.0
Show newest version
package net.sourceforge.squirrel_sql.fw.completion.util;

import java.util.ArrayList;
import java.util.StringTokenizer;

public class CompletionParser
{
   private static final String DEREF_CHAR = ".";

   private ArrayList _tokens = new ArrayList();
   private String _stringToParse;
   private int _stringToParsePosition;
   private String _stringToReplace;
   private String _textTillCarret;


   public CompletionParser(String textTillCarret)
   {
      this(textTillCarret, false);
   }


   public CompletionParser(String textTillCarret, boolean completeQualified)
   {
      _textTillCarret = textTillCarret;
      _stringToParse = CompletionUtils.getStringToParse(textTillCarret);
      _stringToParsePosition = CompletionUtils.getStringToParsePosition ( textTillCarret );

      StringTokenizer st = new StringTokenizer(_stringToParse, DEREF_CHAR);
      _tokens = new ArrayList();
      while(st.hasMoreTokens())
      {
         _tokens.add(st.nextToken());
      }

      if(textTillCarret.endsWith(DEREF_CHAR) || 0 == _tokens.size())
      {
         _tokens.add("");
      }

      if(completeQualified)
      {
         _stringToReplace = _stringToParse;
      }
      else
      {
         _stringToReplace = _tokens.get(_tokens.size() - 1);
      }

   }


   /**
    * True when _stringToParse contains a DEREF_CHAR.
    */
   public boolean isQualified()
   {
      return 1 < _tokens.size();
   }


   public String getStringToParse()
   {
      return _stringToParse;
   }


   public String getToken(int index)
   {
      return _tokens.get(index);
   }

   public int size()
   {
      return _tokens.size();
   }


   public int getStringToParsePosition()
   {
      return _stringToParsePosition;
   }


   public String getStringToReplace()
   {
      return _stringToReplace;
   }


   public int getReplacementStart()
   {
      return _textTillCarret.length() - _stringToReplace.length();
   }

   public String getTextTillCarret()
   {
      return _textTillCarret;
   }

   public String getLastToken()
   {
      return _tokens.get(_tokens.size()-1);
   }

   public String getAllButFirst()
   {
      String ret = _tokens.get(1);
      for (int i = 2; i < _tokens.size(); i++)
      {
         ret += DEREF_CHAR + _tokens.get(i);
      }
      return ret;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy