Changeset 81
- Timestamp:
- 10/20/05 18:28:22 (19 years ago)
- 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 49 49 /** 50 50 * @author Elmir Jagudin 51 * 51 * @author Andreas Remar 52 52 */ 53 53 public class ModelicaPackage extends ModelicaElement implements … … 56 56 String baseName; 57 57 String elementName; 58 String fullName; 58 59 59 60 Vector<IModelicaPackage> packages; … … 61 62 62 63 boolean hasReceivedPackages = false; 64 boolean hasReceivedClasses = false; 63 65 64 66 ModelicaPackage(String baseName, String elementName) … … 66 68 this.baseName = baseName; 67 69 this.elementName = elementName; 70 71 if(baseName == null) 72 { 73 fullName = elementName; 74 } 75 else 76 { 77 fullName = baseName + "." + elementName; 78 } 68 79 69 80 packages = new Vector<IModelicaPackage>(); … … 78 89 if(hasReceivedPackages == true) 79 90 { 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 } 81 100 } 82 101 83 102 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) 103 114 { 104 115 if(s.equals("") == false) 105 116 { 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)); 110 118 } 111 119 } … … 129 137 public IModelicaClass[] getClasses() 130 138 { 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 } 133 189 } 134 190 … … 145 201 packages.add(modelicaPackage); 146 202 } 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 } 147 224 }
Note: See TracChangeset
for help on using the changeset viewer.