Ignore:
Timestamp:
11/07/11 00:54:51 (13 years ago)
Author:
masberg
Message:

Refactor TestInnerClass?, which adds a new package modelicafiles with .mo-files used by TestInnerClass? (and other tests in the future).

Location:
trunk/org.modelica.mdt.test/src/org/modelica/mdt/test
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestInnerClass.java

    r1072 r1076  
    4242package org.modelica.mdt.test;
    4343
     44import java.io.InputStream;
     45import java.util.Collection;
     46
    4447import org.eclipse.core.resources.IFile;
    4548import org.eclipse.core.resources.IProject;
     
    4952import org.eclipse.jface.text.IRegion;
    5053import org.eclipse.ui.model.IWorkbenchAdapter;
     54import org.modelica.mdt.core.IDefinitionLocation;
    5155import org.modelica.mdt.core.IModelicaClass;
    5256import org.modelica.mdt.core.IModelicaComponent;
     
    5559import org.modelica.mdt.core.IModelicaSourceFile;
    5660import org.modelica.mdt.core.IModelicaProject;
     61import org.modelica.mdt.core.ISourceRegion;
    5762import org.modelica.mdt.core.IStandardLibrary;
    5863import org.modelica.mdt.core.ModelicaCore;
     
    7075
    7176/**
    72  * test org.modelica.mdt.core.compiler.InnerClass class' code 
     77 * test org.modelica.mdt.core.compiler.InnerClass class' code
    7378 */
    74 public class TestInnerClass extends TestCase
    75 {
    76 
     79public class TestInnerClass extends TestCase {
    7780    /* the file on which we make the changing locations test */
    7881    private static final String CHANGING_FILE = "changing_file.mo";
    79    
     82
    8083    /* the test subject */
    8184    private InnerClass componentsBananza;
    8285    private InnerClass importRichModel;
    83    
     86
    8487    private IModelicaProject proj;
    85    
    86    
     88
    8789    @Override
    88     protected void setUp() throws Exception
    89     {
     90    protected void setUp() throws Exception {
    9091        Area51Projects.createProjects();
    91        
     92
    9293        /* navigate to the model 'component_bananza' */
    9394        proj = Utility.getProject(Area51Projects.MODELICA_PROJECT_NAME);
    94        
    95         IModelicaSourceFile file = 
    96             Utility.findModelicaFileInFolder(proj.getRootFolder(),
    97                 "component_model.mo");
    98        
     95
     96        IModelicaSourceFile file =
     97                Utility.findModelicaFileInFolder(proj.getRootFolder(),
     98                        "component_model.mo");
     99
    99100        componentsBananza = null;
    100         for (IModelicaElement el : file.getChildren())
    101         {
    102             if (el instanceof InnerClass)
    103             {
    104                 if (el.getElementName().equals("components_bananza"))
    105                 {
     101        for (IModelicaElement el : file.getChildren()) {
     102            if (el instanceof InnerClass) {
     103                String elementName = el.getElementName();
     104
     105                if (elementName.equals("components_bananza")) {
    106106                    componentsBananza = (InnerClass)el;
    107107                    break;
     
    110110        }
    111111
    112 
    113112        /* navigate to the model 'import_rich_model' */
    114         file = Utility.findModelicaFileInFolder(proj.getRootFolder(), 
     113        file = Utility.findModelicaFileInFolder(proj.getRootFolder(),
    115114                "import_rich_model.mo");
    116        
     115
    117116        importRichModel = null;
    118         for (IModelicaElement el : file.getChildren())
    119         {
    120             if (el instanceof InnerClass)
    121             {
    122                 if (el.getElementName().equals("import_rich_model"))
    123                 {
     117        for (IModelicaElement el : file.getChildren()) {
     118            if (el instanceof InnerClass) {
     119                String elementName = el.getElementName();
     120
     121                if (elementName.equals("import_rich_model")) {
    124122                    importRichModel = (InnerClass)el;
    125123                    break;
     
    131129                importRichModel);
    132130    }
    133    
     131
    134132    /**
    135133     * do some sanity checks on InnerClass children
    136134     */
    137135    public void testChildren()
    138         throws ConnectException, UnexpectedReplyException,
    139             InvocationError, CoreException, CompilerInstantiationException,
    140             BundleException
    141     {
    142         /*
    143          * we want to check if we can convert modelica elemnts to workbench
     136            throws ConnectException, UnexpectedReplyException,  InvocationError, CoreException, CompilerInstantiationException, BundleException {
     137        /*
     138         * we want to check if we can convert modelica elements to workbench
    144139         * object and get correct label and some image
    145140         * the adapter factory that handles modelica elements object
    146141         * is installed by the org.modelica.mdt.ui plugin,
    147          * make sure it is loaded before running tests 
    148          */
    149         Bundle bundle = Platform.getBundle("org.modelica.mdt.ui");     
     142         * make sure it is loaded before running tests
     143         */
     144        Bundle bundle = Platform.getBundle("org.modelica.mdt.ui");
    150145        bundle.start();
    151146
    152        
    153147        IModelicaComponent a_real = null;
    154148        IModelicaComponent an_undocumented_real = null;
     
    162156        IModelicaClass a_block = null;
    163157        IModelicaClass a_type = null;
    164         IModelicaClass a_function = null;       
    165        
     158        IModelicaClass a_function = null;
     159
    166160        /*
    167161         * fetch children to local variables
    168          * so we can perfort check on 'em
    169          */
    170         for (IModelicaElement elm : componentsBananza.getChildren())
    171         {
    172             if (elm instanceof IModelicaComponent)
    173             {
    174                 IModelicaComponent comp = (IModelicaComponent) elm;
    175                
    176                 if (comp.getElementName().endsWith("a_real"))
    177                 {
    178                     a_real = comp;
     162         * so we can perform checks on them
     163         */
     164        for (IModelicaElement elm : componentsBananza.getChildren()) {
     165            if (elm instanceof IModelicaComponent) {
     166                IModelicaComponent component = (IModelicaComponent)elm;
     167                String elementName = component.getElementName();
     168
     169                if (elementName.endsWith("a_real")) {
     170                    a_real = component;
    179171                }
    180                 else if (comp.getElementName().endsWith("an_undocumented_real"))
    181                 {
    182                     an_undocumented_real = comp;
     172                else if (elementName.endsWith("an_undocumented_real")) {
     173                    an_undocumented_real = component;
    183174                }
    184                 else if (comp.getElementName().endsWith("a_protected_real"))
    185                 {
    186                     a_protected_real = comp;
     175                else if (elementName.endsWith("a_protected_real")) {
     176                    a_protected_real = component;
    187177                }
    188                 else if (comp.getElementName().endsWith("a_protected_integer"))
    189                 {
    190                     a_protected_integer = comp;
     178                else if (elementName.endsWith("a_protected_integer")) {
     179                    a_protected_integer = component;
    191180                }
    192181            }
    193             else if (elm instanceof IModelicaClass)
    194             {
    195                 switch (((IModelicaClass)elm).getRestriction())
    196                 {
     182            else if (elm instanceof IModelicaClass) {
     183                IModelicaClass cls = ((IModelicaClass)elm);
     184                IModelicaClass.Restriction restriction = cls.getRestriction();
     185
     186                switch (restriction) {
    197187                case PACKAGE:
    198                     a_package = (IModelicaClass)elm;
     188                    a_package = cls;
    199189                    break;
    200190                case BLOCK:
    201                     a_block = (IModelicaClass)elm;
     191                    a_block = cls;
    202192                    break;
    203193                case CLASS:
    204                     a_class = (IModelicaClass)elm;
     194                    a_class = cls;
    205195                    break;
    206196                case CONNECTOR:
    207                     a_connector = (IModelicaClass)elm;
     197                    a_connector = cls;
    208198                    break;
    209199                case FUNCTION:
    210                     a_function = (IModelicaClass)elm;
     200                    a_function = cls;
    211201                    break;
    212202                case MODEL:
    213                     a_model = (IModelicaClass)elm;
     203                    a_model = cls;
    214204                    break;
    215205                case RECORD:
    216                     a_record = (IModelicaClass)elm;
     206                    a_record = cls;
    217207                    break;
    218208                case TYPE:
    219                     a_type = (IModelicaClass)elm;
     209                    a_type = cls;
    220210                    break;
    221211                }
    222212            }
    223213        }
    224        
    225         /* 
    226          * sanity checks on components_bananza.a_type 
     214
     215        /*
     216         * sanity checks on components_bananza.a_type
    227217         */
    228218        assertNotNull("components_bananza.a_type not found", a_type);
    229219        assertEquals("wrong element name", "a_type", a_type.getElementName());
    230         assertEquals("wrong element full name", 
    231                 "components_bananza.a_type", a_type.getFullName());     
    232         assertTrue("fishy file path", 
     220        assertEquals("wrong element full name",
     221                "components_bananza.a_type", a_type.getFullName());
     222        assertTrue("fishy file path",
    233223                a_type.getFilePath().endsWith("component_model.mo"));
    234224        IRegion reg = a_type.getLocation().getRegion();
    235225        assertEquals("wrong start offset", 342, reg.getOffset());
    236226        assertEquals("wrong length", 364-342+1, reg.getLength());
    237        
     227
    238228        /* check if element is adaptable */
    239229        assertTrue("element object must be adaptable",
    240230                (a_type instanceof IAdaptable));
    241        
    242         /* check if we can convert element to workbench adapter */
    243         IWorkbenchAdapter wbAdapter = 
    244             (IWorkbenchAdapter)a_type.getAdapter(IWorkbenchAdapter.class);
     231
     232        /* check if we can convert element to workbench adapter */
     233        IWorkbenchAdapter wbAdapter =
     234                (IWorkbenchAdapter)a_type.getAdapter(IWorkbenchAdapter.class);
    245235
    246236        assertNotNull("could not fetch workbench adapter", wbAdapter);
    247237        assertEquals("wrong label", "a_type",
    248238                wbAdapter.getLabel(a_type));
    249         assertNotNull("no image provided", 
     239        assertNotNull("no image provided",
    250240                wbAdapter.getImageDescriptor(a_type));
    251        
    252241
    253242        /*
     
    259248        assertEquals("wrong element full name", "components_bananza.a_package",
    260249                a_package.getFullName());
    261         assertTrue("fishy file path", 
     250        assertTrue("fishy file path",
    262251                a_package.getFilePath().endsWith("component_model.mo"));
    263252        reg = a_package.getLocation().getRegion();
     
    268257        assertTrue("element object must be adaptable",
    269258                (a_package instanceof IAdaptable));
    270        
     259
    271260        /* check if we can convert element to workbench adapter */
    272261        wbAdapter = (IWorkbenchAdapter)a_package.getAdapter(IWorkbenchAdapter.class);
     
    276265        assertEquals("wrong label", "a_package",
    277266                wbAdapter.getLabel(a_package));
    278         assertNotNull("no image provided", 
     267        assertNotNull("no image provided",
    279268                wbAdapter.getImageDescriptor(a_package));
    280        
     269
    281270        /*
    282271         * sanity checks on components_bananza.a_block
     
    287276        assertEquals("wrong element full name", "components_bananza.a_block",
    288277                a_block.getFullName());
    289         assertTrue("fishy file path", 
     278        assertTrue("fishy file path",
    290279                a_block.getFilePath().endsWith("component_model.mo"));
    291280        reg = a_block.getLocation().getRegion();
     
    296285        assertTrue("element object must be adaptable",
    297286                (a_block instanceof IAdaptable));
    298        
     287
    299288        /* check if we can convert element to workbench adapter */
    300289        wbAdapter = (IWorkbenchAdapter)a_block.getAdapter(IWorkbenchAdapter.class);
     
    303292        assertEquals("wrong label", "a_block",
    304293                wbAdapter.getLabel(a_block));
    305         assertNotNull("no image provided", 
     294        assertNotNull("no image provided",
    306295                wbAdapter.getImageDescriptor(a_block));
    307296
     
    313302        assertEquals("wrong element full name", "components_bananza.a_class",
    314303                a_class.getFullName());
    315         assertTrue("fishy file path", 
     304        assertTrue("fishy file path",
    316305                a_class.getFilePath().endsWith("component_model.mo"));
    317306        reg = a_class.getLocation().getRegion();
     
    322311        assertTrue("element object must be adaptable",
    323312                (a_class instanceof IAdaptable));
    324        
     313
    325314        /* check if we can convert element to workbench adapter */
    326315        wbAdapter = (IWorkbenchAdapter)a_class.getAdapter(IWorkbenchAdapter.class);
     
    329318        assertEquals("wrong label", "a_class",
    330319                wbAdapter.getLabel(a_class));
    331         assertNotNull("no image provided", 
     320        assertNotNull("no image provided",
    332321                wbAdapter.getImageDescriptor(a_class));
    333322
    334323        /*
    335          * sanity checks on components_bananza.a_connector 
     324         * sanity checks on components_bananza.a_connector
    336325         */
    337326        assertNotNull("components_bananza.a_connector not found", a_connector);
    338         assertEquals("wrong element name", "a_connector", 
     327        assertEquals("wrong element name", "a_connector",
    339328                a_connector.getElementName());
    340         assertEquals("wrong element full name", "components_bananza.a_connector", 
     329        assertEquals("wrong element full name", "components_bananza.a_connector",
    341330                a_connector.getFullName());
    342         assertTrue("fishy file path", 
     331        assertTrue("fishy file path",
    343332                a_connector.getFilePath().endsWith("component_model.mo"));
    344333        reg = a_connector.getLocation().getRegion();
     
    349338        assertTrue("element object must be adaptable",
    350339                (a_connector instanceof IAdaptable));
    351        
     340
    352341        /* check if we can convert element to workbench adapter */
    353342        wbAdapter = (IWorkbenchAdapter)a_connector.getAdapter(IWorkbenchAdapter.class);
     
    356345        assertEquals("wrong label", "a_connector",
    357346                wbAdapter.getLabel(a_connector));
    358         assertNotNull("no image provided", 
     347        assertNotNull("no image provided",
    359348                wbAdapter.getImageDescriptor(a_connector));
    360349
    361350        /*
    362          * sanity checks on components_bananza.a_function 
     351         * sanity checks on components_bananza.a_function
    363352         */
    364353        assertNotNull("components_bananza.a_function not found", a_function);
    365         assertEquals("wrong element name", "a_function", 
     354        assertEquals("wrong element name", "a_function",
    366355                a_function.getElementName());
    367         assertEquals("wrong element full name", "components_bananza.a_function", 
     356        assertEquals("wrong element full name", "components_bananza.a_function",
    368357                a_function.getFullName());
    369         assertTrue("fishy file path", 
     358        assertTrue("fishy file path",
    370359                a_function.getFilePath().endsWith("component_model.mo"));
    371360        reg = a_function.getLocation().getRegion();
     
    376365        assertTrue("element object must be adaptable",
    377366                (a_function instanceof IAdaptable));
    378        
     367
    379368        /* check if we can convert element to workbench adapter */
    380369        wbAdapter = (IWorkbenchAdapter)a_function.getAdapter(IWorkbenchAdapter.class);
     
    383372        assertEquals("wrong label", "a_function",
    384373                wbAdapter.getLabel(a_function));
    385         assertNotNull("no image provided", 
     374        assertNotNull("no image provided",
    386375                wbAdapter.getImageDescriptor(a_function));
    387376
    388         /* 
    389          * sanity checks on components_bananza.a_model 
     377        /*
     378         * sanity checks on components_bananza.a_model
    390379         */
    391380        assertNotNull("components_bananza.a_model not found", a_model);
    392381        assertEquals("wrong element name", "a_model", a_model.getElementName());
    393         assertEquals("wrong element full name", "components_bananza.a_model", 
     382        assertEquals("wrong element full name", "components_bananza.a_model",
    394383                a_model.getFullName());
    395         assertTrue("fishy file path", 
     384        assertTrue("fishy file path",
    396385                a_model.getFilePath().endsWith("component_model.mo"));
    397386        reg = a_model.getLocation().getRegion();
     
    402391        assertTrue("element object must be adaptable",
    403392                (a_model instanceof IAdaptable));
    404        
     393
    405394        /* check if we can convert element to workbench adapter */
    406395        wbAdapter = (IWorkbenchAdapter)a_model.getAdapter(IWorkbenchAdapter.class);
     
    409398        assertEquals("wrong label", "a_model",
    410399                wbAdapter.getLabel(a_model));
    411         assertNotNull("no image provided", 
     400        assertNotNull("no image provided",
    412401                wbAdapter.getImageDescriptor(a_model));
    413    
    414         /*
    415          * sanity checks on components_bananza.a_record 
     402
     403        /*
     404         * sanity checks on components_bananza.a_record
    416405         */
    417406        assertNotNull("components_bananza.a_record not found", a_record);
     
    419408        assertEquals("wrong element full name", "components_bananza.a_record",
    420409                a_record.getFullName());
    421         assertTrue("fishy file path", 
     410        assertTrue("fishy file path",
    422411                a_record.getFilePath().endsWith("component_model.mo"));
    423412        reg = a_record.getLocation().getRegion();
     
    428417        assertTrue("element object must be adaptable",
    429418                (a_record instanceof IAdaptable));
    430        
     419
    431420        /* check if we can convert element to workbench adapter */
    432421        wbAdapter = (IWorkbenchAdapter)a_record.getAdapter(IWorkbenchAdapter.class);
     
    435424        assertEquals("wrong label", "a_record",
    436425                wbAdapter.getLabel(a_record));
    437         assertNotNull("no image provided", 
     426        assertNotNull("no image provided",
    438427                wbAdapter.getImageDescriptor(a_record));
    439                
    440         /*
    441          * sanity checks on components_bananza.a_real 
     428
     429        /*
     430         * sanity checks on components_bananza.a_real
    442431         */
    443432        assertNotNull("components_bananza.a_real not found", a_real);
    444433        assertEquals("wrong element name", "a_real", a_real.getElementName());
    445         assertEquals("wrong element full name", "components_bananza.a_real", 
     434        assertEquals("wrong element full name", "components_bananza.a_real",
    446435                a_real.getFullName());
    447436        assertEquals("wrong visibility", a_real.getVisibility(),
     
    455444        assertTrue("element object must be adaptable",
    456445                (a_real instanceof IAdaptable));
    457        
     446
    458447        /* check if we can convert element to workbench adapter */
    459448        wbAdapter = (IWorkbenchAdapter)a_real.getAdapter(IWorkbenchAdapter.class);
     
    462451        assertEquals("wrong label", "a_real",
    463452                wbAdapter.getLabel(a_real));
    464         assertNotNull("no image provided", 
     453        assertNotNull("no image provided",
    465454                wbAdapter.getImageDescriptor(a_real));
    466        
    467         /*
    468          * sanity checks on components_bananza.a_undocumented_real 
    469          */
    470         assertNotNull("components_bananza.an_undocumented_real not found", 
     455
     456        /*
     457         * sanity checks on components_bananza.a_undocumented_real
     458         */
     459        assertNotNull("components_bananza.an_undocumented_real not found",
    471460                an_undocumented_real);
    472461        assertEquals("wrong element name", "an_undocumented_real",
    473462                an_undocumented_real.getElementName());
    474         assertEquals("wrong element full name", 
     463        assertEquals("wrong element full name",
    475464                "components_bananza.an_undocumented_real",
    476465                an_undocumented_real.getFullName());
     
    480469        assertEquals("wrong start offset", 64, reg.getOffset());
    481470        assertEquals("wrong length", 89-64+1, reg.getLength());
    482        
     471
    483472        /* check if element is adaptable */
    484473        assertTrue("element object must be adaptable",
    485474                (an_undocumented_real instanceof IAdaptable));
    486        
    487         /* check if we can convert element to workbench adapter */
    488         wbAdapter = 
    489             (IWorkbenchAdapter)an_undocumented_real.getAdapter(IWorkbenchAdapter.class);
     475
     476        /* check if we can convert element to workbench adapter */
     477        wbAdapter =
     478                (IWorkbenchAdapter)an_undocumented_real.getAdapter(IWorkbenchAdapter.class);
    490479
    491480        assertNotNull("could not fetch workbench adapter", wbAdapter);
    492481        assertEquals("wrong label", "an_undocumented_real",
    493482                wbAdapter.getLabel(an_undocumented_real));
    494         assertNotNull("no image provided", 
     483        assertNotNull("no image provided",
    495484                wbAdapter.getImageDescriptor(an_undocumented_real));
    496                
    497         /*
    498          * sanity checks on components_bananza.a_protected_integer 
    499          */
    500         assertNotNull("components_bananza.a_protected_integer not found", 
     485
     486        /*
     487         * sanity checks on components_bananza.a_protected_integer
     488         */
     489        assertNotNull("components_bananza.a_protected_integer not found",
    501490                a_protected_integer);
    502         assertEquals("wrong element name", "a_protected_integer", 
     491        assertEquals("wrong element name", "a_protected_integer",
    503492                a_protected_integer.getElementName());
    504         assertEquals("wrong element full name", 
    505                 "components_bananza.a_protected_integer", 
     493        assertEquals("wrong element full name",
     494                "components_bananza.a_protected_integer",
    506495                a_protected_integer.getFullName());
    507496        assertEquals("wrong visibility", a_protected_integer.getVisibility(),
     
    514503        assertTrue("element object must be adaptable",
    515504                (a_protected_integer instanceof IAdaptable));
    516        
    517         /* check if we can convert element to workbench adapter */
    518         wbAdapter =
    519             (IWorkbenchAdapter)a_protected_integer.getAdapter(IWorkbenchAdapter.class);
     505
     506        /* check if we can convert element to workbench adapter */
     507        wbAdapter = (IWorkbenchAdapter)a_protected_integer.getAdapter(IWorkbenchAdapter.class);
    520508
    521509        assertNotNull("could not fetch workbench adapter", wbAdapter);
    522510        assertEquals("wrong label", "a_protected_integer",
    523511                wbAdapter.getLabel(a_protected_integer));
    524         assertNotNull("no image provided", 
     512        assertNotNull("no image provided",
    525513                wbAdapter.getImageDescriptor(a_protected_integer));
    526                
    527         /*
    528          * sanity checks on components_bananza.a_protected_real 
    529          */
    530         assertNotNull("components_bananza.a_protected_real not found", 
     514
     515        /*
     516         * sanity checks on components_bananza.a_protected_real
     517         */
     518        assertNotNull("components_bananza.a_protected_real not found",
    531519                a_protected_real);
    532         assertEquals("wrong element name", "a_protected_real", 
     520        assertEquals("wrong element name", "a_protected_real",
    533521                a_protected_real.getElementName());
    534         assertEquals("wrong element full name", 
    535                 "components_bananza.a_protected_real", 
    536                 a_protected_real.getFullName());       
     522        assertEquals("wrong element full name",
     523                "components_bananza.a_protected_real",
     524                a_protected_real.getFullName());
    537525        assertEquals("wrong visibility", a_protected_real.getVisibility(),
    538526                IModelicaComponent.Visibility.PROTECTED);
     
    544532        assertTrue("element object must be adaptable",
    545533                (a_protected_real instanceof IAdaptable));
    546        
    547         /* check if we can convert element to workbench adapter */
    548         wbAdapter = 
    549             (IWorkbenchAdapter)a_protected_real.getAdapter(IWorkbenchAdapter.class);
     534
     535        /* check if we can convert element to workbench adapter */
     536        wbAdapter =
     537                (IWorkbenchAdapter)a_protected_real.getAdapter(IWorkbenchAdapter.class);
    550538
    551539        assertNotNull("could not fetch workbench adapter", wbAdapter);
    552540        assertEquals("wrong label", "a_protected_real",
    553541                wbAdapter.getLabel(a_protected_real));
    554         assertNotNull("no image provided", 
     542        assertNotNull("no image provided",
    555543                wbAdapter.getImageDescriptor(a_protected_real));
    556544    }
    557    
     545
    558546    /**
    559547     * do some sanity checks on InnerClass' imports
    560548     */
    561     public void testImports()
    562         throws ConnectException, UnexpectedReplyException, InvocationError,
    563             CompilerInstantiationException, CoreException
    564     {
     549    public void testImports()
     550            throws ConnectException, UnexpectedReplyException, InvocationError, CompilerInstantiationException, CoreException {
    565551        int importCounter = 0;
    566         IModelicaClass importedPackage;
    567         for (IModelicaImport imp : importRichModel.getImports())
    568         {
     552        Collection<IModelicaImport> imports = importRichModel.getImports();
     553
     554        for (IModelicaImport imp : imports) {
    569555            importCounter++;
    570            
     556
    571557            /*
    572              * we are expecting 8 import statments in following order:
     558             * we are expecting 8 import statements in following order:
    573559             * 1. qualified         (import Modelica)
    574560             * 2. qualified         (import Modelica.Math.sin)
     
    578564             * 6. local qualified   (import hepp.hopp)
    579565             * 7. local unqualified (import hepp.*)
    580              * 8. local single definition 
     566             * 8. local single definition
    581567             *                      (import root_package.root_package_model)
    582568             */
    583 
    584             switch (importCounter)
    585             {
    586             case 1: // import Modelica
     569            switch (importCounter) {
     570            case 1: {// import Modelica
    587571                assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType());
    588                 importedPackage = imp.getImportedPackage();
     572                IModelicaClass importedPackage = imp.getImportedPackage();
    589573                assertEquals("wrong imported package returned",
    590574                        "Modelica",
    591575                        importedPackage.getFullName());
    592576                break;
    593             case 2: // import Modelica.Math.sin
     577            }
     578            case 2: {// import Modelica.Math.sin
    594579                assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType());
    595                 importedPackage = imp.getImportedPackage();
     580                IModelicaClass importedPackage = imp.getImportedPackage();
    596581                assertEquals("wrong imported package returned",
    597582                        "Modelica.Math.sin",
    598583                        importedPackage.getFullName());
    599584                break;
    600             case 3: // import Modelica.*
     585            }
     586            case 3: {// import Modelica.*
    601587                assertEquals(IModelicaImport.Type.UNQUALIFIED, imp.getType());
    602                 importedPackage = imp.getImportedPackage();
     588                IModelicaClass importedPackage = imp.getImportedPackage();
    603589                assertEquals("wrong imported package returned",
    604590                        "Modelica",
    605591                        importedPackage.getFullName());
    606592                break;
    607             case 4: // import mm = Modelica.Math
     593            }
     594            case 4: {// import mm = Modelica.Math
    608595                assertEquals(IModelicaImport.Type.RENAMING, imp.getType());
    609596                assertEquals("mm", imp.getAlias());
    610597                break;
    611             case 5: // import foo = hepp
     598            }
     599            case 5: {// import foo = hepp
    612600                assertEquals(IModelicaImport.Type.RENAMING, imp.getType());
    613601                assertEquals("foo", imp.getAlias());
    614602                break;
    615             case 6: // import hepp.hopp
     603            }
     604            case 6: {// import hepp.hopp
    616605                assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType());
    617606                break;
    618             case 7: // import hepp.*
     607            }
     608            case 7: {// import hepp.*
    619609                assertEquals(IModelicaImport.Type.UNQUALIFIED, imp.getType());
    620610                break;
    621             case 8: // import root_package.root_package_model
     611            }
     612            case 8: {// import root_package.root_package_model
    622613                assertEquals(IModelicaImport.Type.QUALIFIED, imp.getType());
    623614                break;
    624             default:
    625                 fail("unexpectedly many imports found");
     615            }
     616            default: {
     617                fail("unexpectedly many imports found");
     618            }
    626619            }
    627620        }
    628        
    629         assertFalse("did not find all import statments", 
     621
     622        assertFalse("did not find all import statments",
    630623                importCounter < 4);
    631 
    632624    }
    633625
    634626    public void testIsEncapsulated()
    635         throws ConnectException, CompilerInstantiationException, UnexpectedReplyException,
    636             InvocationError, CoreException
    637     {
     627            throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError, CoreException {
    638628        IModelicaClass clazz;
    639         IStandardLibrary stdLib = 
     629        IStandardLibrary stdLib =
    640630                ModelicaCore.getModelicaRoot().getStandardLibrary(null);
    641        
     631
    642632        /*
    643633         * check correctness of isEncapsulated() in classes from standard library
     
    646636        assertNotNull(clazz);
    647637        assertTrue("wrong encapsulated status", clazz.isEncapsulated());
    648        
     638
    649639        clazz = stdLib.getPackage("Modelica.Math.acos");
    650640        assertNotNull(clazz);
     
    658648        assertNotNull(clazz);
    659649        assertTrue("wrong encapsulated status", clazz.isEncapsulated());
    660        
     650
    661651        clazz = stdLib.getPackage("Modelica");
    662652        assertNotNull(clazz);
    663653        assertFalse("wrong encapsulated status", clazz.isEncapsulated());
    664        
     654
    665655        /*
    666656         * check correctness of isEncapsulated() on classes from area51 project
    667657         */
    668        
     658
    669659        /* test inner packager */
    670660        clazz = proj.getClass("root_model");
     
    702692    }
    703693
    704     /** 
    705      * test that the when a class definiton is changed in the disk
    706      * it's location is updated
     694    /**
     695     * test that the when a class definition is changed in the disk
     696     * its location is updated
    707697     */
    708     public void testLocationUpdates() throws CoreException,
    709         ConnectException, CompilerInstantiationException,
    710             UnexpectedReplyException, InvocationError
    711     {       
    712        
    713         /* create initial class definitons */
    714         createClassDef();       
    715         /*
    716          * check the initial locations
    717          */
    718         IModelicaClass clazz;
    719         IRegion defReg;
    720        
    721         /* checks on EquationComponent */
    722         clazz = proj.getClass("EquationComponent");
    723         assertNotNull(clazz);
    724        
    725         defReg = clazz.getLocation().getRegion();
    726         assertEquals("wrong start offset", 111, defReg.getOffset());
    727         assertEquals("wrong length", 239-111+1, defReg.getLength());
     698    public void testLocationUpdates()
     699            throws CoreException, ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError {
     700        /* create initial class definitions */
     701        createClassDef();
     702
     703        /*
     704         * Check some initial locations.
     705         */
     706        testLocation("EquationComponent", 6, 1, 13, 22);
    728707
    729708        /* checks on EquationComponent.R */
    730         clazz = proj.getClass("EquationComponent.R");
    731         assertNotNull(clazz);
    732        
    733         defReg = clazz.getLocation().getRegion();
    734         assertEquals("wrong start offset", 137, defReg.getOffset());
    735         assertEquals("wrong length", 167-137+1, defReg.getLength());
    736        
    737        
    738         /* modify class defintions */
     709        testLocation("EquationComponent.R", 7, 3, 9, 8);
     710
     711        /* modify class definitions */
    739712        modifyClassDef();
    740        
    741         /*
    742          * check that locations where updated
    743          */
    744         /* checks on EquationComponent */
    745         clazz = proj.getClass("EquationComponent");
    746         assertNotNull(clazz);
    747        
    748         defReg = clazz.getLocation().getRegion();
    749         assertEquals("wrong start offset", 25, defReg.getOffset());
    750         assertEquals("wrong length", 179-25+1, defReg.getLength());
    751 
    752         /* checks on EquationComponent.R */
    753         clazz = proj.getClass("EquationComponent.R");
    754         assertNotNull(clazz);
    755        
    756         defReg = clazz.getLocation().getRegion();
    757         assertEquals("wrong start offset", 76, defReg.getOffset());
    758         assertEquals("wrong length", 106-76+1, defReg.getLength());
    759 
     713
     714        /*
     715         * check that locations where updated
     716         */
     717        testLocation("EquationComponent", 2, 1, 11, 22);
     718
     719        Utility.printFile(proj,  TestInnerClass.CHANGING_FILE);
     720        testLocation("EquationComponent.R", 4, 3, 6, 8);
    760721    }
    761    
     722
     723    private void testLocation(String className, int startLine, int startCol, int endLine, int endCol)
     724            throws ConnectException, CompilerInstantiationException, UnexpectedReplyException, InvocationError, CoreException {
     725        IModelicaClass cls = proj.getClass(className);
     726
     727        assertNotNull("IModelicaProject.getClass() returned null for \"" + className + "\".", cls);
     728
     729        IDefinitionLocation definitionLocation = cls.getLocation();
     730        ISourceRegion sourceRegion = definitionLocation.getSourceRegion();
     731
     732        int actualStartLine = sourceRegion.getStartLine();
     733        int actualStartCol = sourceRegion.getStartColumn();
     734        int actualEndLine = sourceRegion.getEndLine();
     735        int actualEndCol = sourceRegion.getEndColumn();
     736
     737        assertEquals("Expected start line did not match actual start line.", startLine, actualStartLine);
     738        assertEquals("Expected start column did not match actual start column.", startCol, actualStartCol);
     739        assertEquals("Expected end line did not match actual end line.", endLine, actualEndLine);
     740        assertEquals("Expected end column did not match actual end column.", endCol, actualEndCol);
     741    }
     742
    762743    /**
    763744     * utility function for the testLocationUpdates test
    764      *
     745     *
     746     * Creates the initial definitions in a source file
     747     */
     748    private void createClassDef() throws CoreException {
     749        IProject project = proj.getWrappedProject();
     750        IFile file = project.getFile(CHANGING_FILE);
     751
     752        InputStream stream = TestInnerClass.class.getResourceAsStream("/org/modelica/mdt/test/modelicafiles/TestInnerClass_changing_file_before.mo");
     753        file.create(stream, true, null);
     754    }
     755
     756    /**
     757     * utility function for the testLocationUpdates test
     758     *
    765759     * overwrites the initial definitions in a source file with
    766760     * some modifications
    767761     */
    768     private void modifyClassDef() throws CoreException
    769     {
    770         String contents =
    771             "// funny comment removed\n" +
    772             "class EquationComponent\n" +
    773             "  /* records are nice */\n" +
    774             "  record R\n" +
    775             "    Real x,y;\n" +
    776             "  end R;\n" +
    777             "\n" +
    778             "  R a,b,c;\n" +
    779             "equation\n" +
    780             "  a = if true then b else c;\n" +
    781             "end EquationComponent;";
    782 
     762    private void modifyClassDef() throws CoreException {
    783763        IProject project = proj.getWrappedProject();
    784764        IFile file = project.getFile(CHANGING_FILE);
    785        
    786         file.setContents(Utility.getByteStream(contents), true, true, null);
    787     }
    788 
    789     /**
    790      * utility function for the testLocationUpdates test
    791      *
    792      * Creates the initial definitions in a source file
    793      *
    794      */
    795     private void createClassDef() throws CoreException
    796     {
    797         String contents =
    798             "/*\n" +
    799             " * However, don't ever expect you can parse\n" +
    800             " * the error message from the compiler.\n" +
    801             " *    -- Adrian Pop\n" +
    802             " */\n" +
    803             "class EquationComponent\n" +
    804             "  record R\n" +
    805             "    Real x,y;\n" +
    806             "  end R;\n" +
    807             "  R a,b,c;\n" +
    808             "equation\n" +
    809             "  a = if true then b else c;\n" +
    810             "end EquationComponent;";
    811 
    812         IProject project = proj.getWrappedProject();
    813         IFile file = project.getFile(CHANGING_FILE);
    814        
    815         file.create(Utility.getByteStream(contents), true, null);
     765
     766        InputStream stream = TestInnerClass.class.getResourceAsStream("/org/modelica/mdt/test/modelicafiles/TestInnerClass_changing_file_after.mo");
     767        file.setContents(stream, IFile.FORCE, null);
    816768    }
    817769}
Note: See TracChangeset for help on using the changeset viewer.