Changeset 81


Ignore:
Timestamp:
10/20/05 18:28:22 (19 years ago)
Author:
remar
Message:
  • implemented getClasses
Location:
trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaPackage.java

    r77 r81  
    4949/**
    5050 * @author Elmir Jagudin
    51  *
     51 * @author Andreas Remar
    5252 */
    5353public class ModelicaPackage extends ModelicaElement implements
     
    5656    String baseName;
    5757    String elementName;
     58    String fullName;
    5859   
    5960    Vector<IModelicaPackage> packages;
     
    6162
    6263    boolean hasReceivedPackages = false;
     64    boolean hasReceivedClasses = false;
    6365   
    6466    ModelicaPackage(String baseName, String elementName)
     
    6668        this.baseName = baseName;
    6769        this.elementName = elementName;
     70       
     71        if(baseName == null)
     72        {
     73            fullName = elementName;
     74        }
     75        else
     76        {
     77            fullName = baseName + "." + elementName;
     78        }
    6879       
    6980        packages = new Vector<IModelicaPackage>();
     
    7889        if(hasReceivedPackages == true)
    7990        {
    80             return (IModelicaPackage[]) packages.toArray();
     91            if(packages.size() != 0)
     92            {
     93                IModelicaPackage impPackages[] = new IModelicaPackage[packages.size()];
     94                return packages.toArray(impPackages);
     95            }
     96            else
     97            {
     98                return null;
     99            }
    81100        }
    82101       
    83102        String retval = null;
    84         if(baseName == null)
    85         {
    86             //System.out.println("getPackages("+elementName+")");
    87             retval = ModeqCommunicationImplementation.sendExpression("getPackages("+elementName+")");
    88         }
    89         else
    90         {
    91             //System.out.println("getPackages("+baseName+"."+elementName+")");
    92             retval = ModeqCommunicationImplementation.sendExpression("getPackages("+baseName+"."+elementName+")");         
    93         }
    94        
    95         /* check that a list is returned, otherwise this is probably an error */
    96         if(retval.charAt(0) != '{' || retval.charAt(retval.length()) != '}')
    97             return null;
    98 
    99         retval = retval.substring(1, retval.length() - 2);
    100         String[] retvals = retval.split(",");
    101        
    102         for(String s : retvals)
     103        retval = ModeqCommunicationImplementation.sendExpression("getPackages("+fullName+")");
     104       
     105        String[] tokens = parseList(retval);
     106
     107        if(tokens == null)
     108        {
     109            hasReceivedPackages = true;
     110            return null;
     111        }
     112       
     113        for(String s : tokens)
    103114        {
    104115            if(s.equals("") == false)
    105116            {
    106                 if(baseName == null && s != null)
    107                     addPackage(new ModelicaPackage(elementName, s));
    108                 else if(s != null)
    109                     addPackage(new ModelicaPackage(baseName+"."+elementName, s));
     117                addPackage(new ModelicaPackage(fullName, s));
    110118            }
    111119        }
     
    129137    public IModelicaClass[] getClasses()
    130138    {
    131         // TODO Call getClassNames, then compare list with list of packages, and remove matches
    132         return null;
     139        if(hasReceivedClasses == true)
     140        {
     141            if(classes.size() != 0)
     142            {
     143                IModelicaClass modelicaClasses[] = new IModelicaClass[classes.size()];
     144                return classes.toArray(modelicaClasses);
     145            }
     146            else
     147            {
     148                return null;
     149            }
     150        }
     151       
     152        String retval = null;
     153        retval = ModeqCommunicationImplementation.sendExpression("getClassNames("+fullName+")");
     154
     155       
     156   
     157        String[] tokens = parseList(retval);
     158       
     159        if(tokens == null)
     160        {
     161            hasReceivedClasses = true;
     162            return null;
     163        }
     164       
     165        for(String str : tokens)
     166        {
     167            if(str.equals(""))
     168                continue;
     169            retval = ModeqCommunicationImplementation.sendExpression("isPackage("+fullName+"."+str+")");
     170
     171            if(retval.contains("false"))
     172            {
     173                /* fullName.str is NOT a package, add it to the list of classes */
     174                addClass(new ModelicaClass(str, fullName));
     175            }
     176        }
     177
     178        hasReceivedClasses = true;
     179
     180        if(classes.size() != 0)
     181        {
     182            IModelicaClass modelicaClasses[] = new IModelicaClass[classes.size()];
     183            return classes.toArray(modelicaClasses);
     184        }
     185        else
     186        {
     187            return null;
     188        }
    133189    }
    134190
     
    145201        packages.add(modelicaPackage);
    146202    }
     203   
     204    public void addClass(IModelicaClass modelicaClass)
     205    {
     206        classes.add(modelicaClass);
     207    }
     208
     209    public String[] parseList(String str)
     210    {
     211        /* remove whitespace before and after */
     212        str = str.trim();
     213       
     214        /* check that a list is parsed, otherwise this is probably an error */
     215        if(str.charAt(0) != '{' || str.charAt(str.length() - 1) != '}')
     216            return null;
     217
     218        /* remove {} and split into tokens */
     219        str = str.substring(1, str.length() - 1);
     220        String[] retvals = str.split(",");
     221       
     222        return retvals;
     223    }
    147224}
Note: See TracChangeset for help on using the changeset viewer.