Author: timotei
Date: Tue Jul 26 17:28:11 2011
New Revision: 50414

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50414&view=rev
Log:
eclipse plugin: Make the variables reside in the
project cache instead of the file

Modified:
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectCache.java
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLConfig.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLVariable.java

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectCache.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectCache.java?rev=50414&r1=50413&r2=50414&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectCache.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectCache.java 
Tue Jul 26 17:28:11 2011
@@ -30,6 +30,9 @@
 import org.wesnoth.wml.core.WMLConfig;
 import org.wesnoth.wml.core.WMLVariable;
 
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
 /**
  * A class that stores some project specific infos
  * for current session.
@@ -50,6 +53,7 @@
     private Map< String, WMLConfig > configFiles_;
     private Map< String, Define > defines_;
     private DependencyListBuilder dependTree_;
+    private Multimap<String, WMLVariable> variables_;
 
     private IProject project_;
 
@@ -57,8 +61,9 @@
     {
         project_ = project;
 
-        configFiles_ = new HashMap<String, WMLConfig>();
-        defines_ = new HashMap<String, Define>(0);
+        configFiles_ = new HashMap<String, WMLConfig>( );
+        defines_ = new HashMap<String, Define>( );
+        variables_ = ArrayListMultimap.create( );
 
         dependTree_ = new DependencyListBuilder( project_ );
 
@@ -115,17 +120,23 @@
                     tmp.ScenarioId = config.get( "scenario_id" ); //$NON-NLS-1$
                     tmp.CampaignId = config.get( "campaign_id" ); //$NON-NLS-1$
 
-                    for(IDialogSettings variable : 
config.getSection("variables").getSections()) //$NON-NLS-1$
-                    {
-                        if (variable.getName().startsWith("var") == false) 
//$NON-NLS-1$
-                            continue;
-                        tmp.getVariables().put(
-                                variable.get( "name" ),
-                                new WMLVariable(variable.get("name"), 
//$NON-NLS-1$
-                                        variable.get("location"), //$NON-NLS-1$
-                                        variable.getInt("offset"))); 
//$NON-NLS-1$
-                    }
                     configFiles_.put(config.get("filename"), tmp); 
//$NON-NLS-1$
+                }
+            }
+
+            if ( properties_.getSection( "variables" ) != null ){
+
+                for(IDialogSettings variable : 
properties_.getSection("variables").getSections()) //$NON-NLS-1$
+                {
+                    if (variable.getName().startsWith("var") == false) 
//$NON-NLS-1$
+                        continue;
+
+                    variables_.put( variable.get( "name" ),
+                            new WMLVariable(variable.get("name"), //$NON-NLS-1$
+                                    variable.get("location"), //$NON-NLS-1$
+                                    variable.getInt("offset"),
+                                    variable.getInt( "startIndex" ),
+                                    variable.getInt( "endIndex" ))); 
//$NON-NLS-1$
                 }
             }
 
@@ -183,6 +194,15 @@
         }
 
         return config;
+    }
+
+    /**
+     * Returns the variables found in this project
+     * @return A multimap containing all the variables
+     */
+    public Multimap<String, WMLVariable> getVariables()
+    {
+        return variables_;
     }
 
     /**
@@ -207,18 +227,21 @@
                 configSection.put("campaign_id", config.CampaignId); 
//$NON-NLS-1$
                 configSection.put("filename", config.getFilename()); 
//$NON-NLS-1$
 
-                IDialogSettings variablesSection = 
configSection.addNewSection("variables"); //$NON-NLS-1$
-                int varCnt = 0;
-                for(WMLVariable var : config.getVariables().values( ))
-                {
-                    IDialogSettings varSection = 
variablesSection.addNewSection("var" + varCnt); //$NON-NLS-1$
-                    varSection.put("name", var.getName()); //$NON-NLS-1$
-                    varSection.put("location", var.getLocation()); 
//$NON-NLS-1$
-                    varSection.put("offset", var.getOffset()); //$NON-NLS-1$
-
-                    ++varCnt;
-                }
                 ++configCnt;
+            }
+
+            IDialogSettings variablesSection = 
properties_.addNewSection("variables"); //$NON-NLS-1$
+            int varCnt = 0;
+            for(WMLVariable var : variables_.values( ))
+            {
+                IDialogSettings varSection = 
variablesSection.addNewSection("var" + varCnt); //$NON-NLS-1$
+                varSection.put("name", var.getName()); //$NON-NLS-1$
+                varSection.put("location", var.getLocation()); //$NON-NLS-1$
+                varSection.put("offset", var.getOffset()); //$NON-NLS-1$
+                varSection.put( "startIndex", var.getScopeStartIndex( ) );
+                varSection.put( "endIndex", var.getScopeEndIndex( ) );
+
+                ++varCnt;
             }
 
             // store properties

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java?rev=50414&r1=50413&r2=50414&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java 
(original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java 
Tue Jul 26 17:28:11 2011
@@ -13,6 +13,7 @@
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.xtext.nodemodel.ICompositeNode;
 import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
+import org.wesnoth.projects.ProjectCache;
 import org.wesnoth.utils.ResourceUtils;
 import org.wesnoth.utils.WMLUtils;
 import org.wesnoth.wml.WMLKey;
@@ -29,6 +30,7 @@
 {
     protected WMLConfig config_;
     protected IFile file_;
+    protected ProjectCache projectCache_;
 
     /**
      * Creates a new parser for the specified file
@@ -53,9 +55,6 @@
      */
     public void parse()
     {
-        // clear all variables before parsing them
-        config_.getVariables( ).clear( );
-
         WMLRoot root = ResourceUtils.getWMLRoot( file_ );
         TreeIterator<EObject> itor = root.eAllContents( );
         WMLTag currentTag = null;
@@ -123,7 +122,7 @@
         }
 
         if ( ! variable.getName( ).isEmpty( ) ) {
-            config_.getVariables( ).put( variable.getName( ), variable );
+            projectCache_.getVariables( ).put( variable.getName( ), variable );
         }
     }
 

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLConfig.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLConfig.java?rev=50414&r1=50413&r2=50414&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLConfig.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLConfig.java Tue 
Jul 26 17:28:11 2011
@@ -8,8 +8,6 @@
  
*******************************************************************************/
 package org.wesnoth.wml.core;
 
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Multimap;
 
 /**
  * A class that stores WML config file specific information
@@ -32,23 +30,16 @@
         */
        public boolean IsCampaign;
 
-       private Multimap<String, WMLVariable> variables_;
        private String filename_;
 
        public WMLConfig(String filename)
        {
-               variables_ = ArrayListMultimap.create( );
                filename_ = filename;
        }
 
        public String getFilename()
        {
                return filename_;
-       }
-
-       public Multimap<String, WMLVariable> getVariables()
-       {
-               return variables_;
        }
 
        @Override

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLVariable.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLVariable.java?rev=50414&r1=50413&r2=50414&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLVariable.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/WMLVariable.java 
Tue Jul 26 17:28:11 2011
@@ -25,15 +25,21 @@
                this("", "", 0); //$NON-NLS-1$ //$NON-NLS-2$
        }
 
-       public WMLVariable(String name, String location, int offset)
+       public WMLVariable( String name, String location, int offset )
        {
-               name_ = name;
-               location_ = location;
-               offset_ = offset;
+           this( name, location, offset, Integer.MAX_VALUE, Integer.MAX_VALUE 
);
+       }
 
-               scopeStartIndex_ = Integer.MAX_VALUE;
-               scopeEndIndex_ = Integer.MAX_VALUE;
-       }
+       public WMLVariable( String name, String location, int offset,
+               int startIndex, int endIndex )
+    {
+        name_ = name;
+        location_ = location;
+        offset_ = offset;
+
+        scopeStartIndex_ = startIndex;
+        scopeEndIndex_ = endIndex;
+    }
 
        public String getName()
        {


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to