Ignore:
Timestamp:
01/31/12 00:40:51 (13 years ago)
Author:
masberg
Message:

Fix bug that caused some elements to retain their old position in the source file after an update.

File:
1 edited

Legend:

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

    r1238 r1262  
    245245        }
    246246
    247         for (final ElementInfo info : CompilerProxy.getElements(fullName)) {
     247        Collection<ElementInfo> fullNameElements = CompilerProxy.getElements(fullName);
     248        for (final ElementInfo info : fullNameElements) {
    248249            String elementType = info.getElementType();
    249250            IModelicaElement.Visibility vis;
     
    393394    public Collection<IModelicaElementChange> reload()
    394395            throws ConnectException, UnexpectedReplyException, InvocationError, CompilerInstantiationException, CoreException {
    395         /*
    396          * the reload strategy is as follows:
    397          */
    398 
    399         /*
    400          * all class attribute fields are just reset and
    401          * lazily reloaded as they are queried
    402          */
     396        // The reload strategy is as follows:
     397        // * all class attribute fields are just reset and
     398        //   lazily reloaded as they are queried
     399        // * new class component are fetched and compared to
     400        //   the old in order to generate a change events list.
     401        // * components that are not new or were removed are notified
     402        //   of the change to give them a chance to update their state
    403403        super.reload();
    404 
    405         /*
    406          * new class component are fetched and compared to
    407          * the old in order to generate a change events list.
    408          *
    409          * components that are not new or were removed are notified
    410          * of the change to give them a chance to update thier's state
    411          */
     404       
    412405        LinkedList<IModelicaElementChange> changes = new LinkedList<IModelicaElementChange>();
    413406
    414         if (children == null) {
    415             /* if children are not loaded, then we can't reload */
    416             return changes;
    417         }
    418 
    419         Hashtable<String, IModelicaElement> newChildren = loadElements();
    420 
    421         @SuppressWarnings("unchecked")
    422         Hashtable<String, IModelicaElement> oldChildren = (Hashtable<String, IModelicaElement>)children.clone();
    423 
    424         for (IModelicaElement element : newChildren.values()) {
    425             ModelicaElement oldElement = (ModelicaElement)oldChildren.remove(element.getElementName());
    426 
    427             if (oldElement == null) {
    428                 /* new element added */
    429                 children.put(element.getElementName(), element);
    430                 changes.add(new ModelicaElementChange(this, element, null));
    431             }
    432             else {
    433                 /* element present before, refresh ! */
    434                 // adrpo 2006-10-16
    435                 // - the IModelicaComponent doesn't have reload
    436                 //   so we have to set it here!
    437                 // - otherwise the image doesn't get updated
    438                 if (oldElement instanceof IModelicaComponent && element instanceof IModelicaComponent) {
    439                     ((ModelicaComponent)oldElement).setModelicaComponent((ModelicaComponent)element);
    440                 }
    441                 changes.addAll(oldElement.reload());
    442             }
    443         }
    444 
    445         /* now there is only removed elements in the oldChildren table */
    446         for (IModelicaElement element : oldChildren.values()) {
    447             children.remove(element.getElementName());
    448             changes.add(new ModelicaElementChange(element, ChangeType.REMOVED, null));
     407        // if children are not loaded, then we can't reload
     408        if (children != null) {
     409            Hashtable<String, IModelicaElement> newChildrenMap = loadElements();
     410
     411            @SuppressWarnings("unchecked")
     412            Hashtable<String, IModelicaElement> oldChildren = (Hashtable<String, IModelicaElement>)children.clone();
     413            Collection<IModelicaElement> newChildren = newChildrenMap.values();
     414
     415            for (IModelicaElement element : newChildren) {
     416                String elementName = element.getElementName();
     417                ModelicaElement oldElement = (ModelicaElement)oldChildren.remove(elementName);
     418
     419                if (oldElement == null) {
     420                    // new element added
     421                    ModelicaElementChange modelicaElementChange = new ModelicaElementChange(this, element, null);
     422                    changes.add(modelicaElementChange);
     423                }
     424                else {
     425                    /* element present before, refresh ! */
     426                    // adrpo 2006-10-16
     427                    // - the IModelicaComponent doesn't have reload
     428                    //   so we have to set it here!
     429                    // - otherwise the image doesn't get updated
     430                    if (oldElement instanceof IModelicaComponent && element instanceof IModelicaComponent) {
     431                        ((ModelicaComponent)oldElement).setModelicaComponent((ModelicaComponent)element);
     432                    }
     433                   
     434                    changes.addAll(oldElement.reload());
     435                }
     436            }
     437
     438            // now there is only removed elements in the oldChildren table
     439            for (IModelicaElement element : oldChildren.values()) {
     440                changes.add(new ModelicaElementChange(element, ChangeType.REMOVED, null));
     441            }
     442
     443            if (children.size() != newChildren.size()) {
     444                ErrorManager.logBug("org.modelica.mdt.core", "Problem in InnerClass.reload(), children and newChildren don't have the same size.");
     445            }
     446
     447            children = newChildrenMap;
    449448        }
    450449
     
    468467            ErrorManager.logError(e);
    469468        }
    470        
     469
    471470        IFile f = null;
    472471
Note: See TracChangeset for help on using the changeset viewer.