JavaScript autocomplete with useBeanproperties=true

General Discussion on RSyntaxTextArea.

Moderator: robert

JavaScript autocomplete with useBeanproperties=true

Postby ggesmundo » Mon Oct 21, 2013 6:58 pm

Hello Robert,

First I would like to thank you for the efforts that have gone into this project. I am integrating RSyntaxTextArea and the Language support projects into a data integration framework. It uses the Rhino engine for scripting data transformations and other purposes. I have spent the last couple of weeks getting to know the code and would like to offer an update for JavaScript auto complete with useBeanproperties = true. I discovered that it would only auto complete Java variables if they were declared using a fully qualified class name. I tried both importClass and importPackage but an unqualified name is not recognized.

I made the following changes to get the qualified name from the JarManager when a new TypeDeclaration is created:

Modified Class:

changed: private List classFileSources;
to: private static List classFileSources;

added method: getQualifiedName(String name)
Code: Select all
  * Gets the fully qualified name for a class if it can be located
  * in one of the jars on the build path.
  * @param name the class name to locate.
  * @return String fully qualified class name or the name if the class
  * could not be located.
 public static String getQualifiedName(String name) {
    String lowerCaseText = name.toLowerCase();
   for (int i=0; i < classFileSources.size(); i++) {
      JarReader jar = (JarReader) classFileSources.get(i);
      List classFiles = jar.getClassesWithNamesStartingWith(lowerCaseText);
      if (classFiles!=null) {
         for (Iterator j=classFiles.iterator(); j.hasNext(); ) {
         ClassFile cf = (ClassFile);
         if (cf.getClassName(false).equals(name))
            return cf.getClassName(true);
   return name;

Modified Class:
Modified Method: createNewTypeDeclaration(String newName) as follows:
Code: Select all
public static TypeDeclaration createNewTypeDeclaration(String newName) {
   // create a new Type
   // added code
   if (newName.indexOf(".")  ==  -1) {
      newName = JarManager.getQualifiedName(newName);
   // end of added code

   String pName = newName.indexOf('.') > 0 ? newName.substring(0,
               newName.lastIndexOf('.')) : "";
   String cName = newName.indexOf('.') > 0 ? newName.substring(
               newName.lastIndexOf('.') + 1, newName.length())
               : newName;
   return new TypeDeclaration(pName, cName, newName);

The following now works as expected:

importPackage(com.virtualplex.dbparams); // contains DataSetParam

var dataSetParam = new DataSetParam(dataSetName, tableSchema, tableName);
dataSetParam. <<< the auto complete dialog popups when '.' is entered.

The only potential issue I can see with this is the static modifier on classFileSources, which could be an issue if there are multiple instances of the editor running in a VM and they require different jars on the build path. In my case, there can be multiple instances but the same jars are loaded in all cases.

Again, awesome project and thanks,
Posts: 1
Joined: Mon Oct 21, 2013 4:54 pm

Re: JavaScript autocomplete with useBeanproperties=true

Postby robert » Tue Nov 12, 2013 2:12 pm

Hi ggesmundo,

I don't use the JS language support too much, and it is contributed by another user, so you may get better visibility if you post this as an issue on GitHub (or submit a pull request). The author will then get notification of the issue and might respond (I don't think he monitors this forum). I can then also take a look and if they look simple enough I'll commit them if he doesn't. :)
User avatar
Posts: 852
Joined: Sat May 10, 2008 5:16 pm

Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 3 guests