Author: timotei
Date: Tue Jul 26 17:27:38 2011
New Revision: 50413

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50413&view=rev
Log:
eclipse plugin: Implement the adding of new found variables

Modified:
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.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/WMLVariable.java

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java?rev=50413&r1=50412&r2=50413&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java 
(original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java 
Tue Jul 26 17:27:38 2011
@@ -39,7 +39,7 @@
      */
     public static final int INDEX_STEP = 100000;
 
-    protected static final QualifiedName PDL_INDEX = new QualifiedName( 
Constants.PLUGIN_ID, "pdl_index" ); //$NON-NLS-1$
+    public static final QualifiedName PDL_INDEX = new QualifiedName( 
Constants.PLUGIN_ID, "pdl_index" ); //$NON-NLS-1$
 
     private DependencyListNode previous_;
     private DependencyListNode next_;

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java?rev=50413&r1=50412&r2=50413&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java 
Tue Jul 26 17:27:38 2011
@@ -51,6 +51,7 @@
 import org.wesnoth.Constants;
 import org.wesnoth.Logger;
 import org.wesnoth.Messages;
+import org.wesnoth.builder.DependencyListNode;
 import org.wesnoth.preprocessor.PreprocessorUtils;
 import org.wesnoth.projects.ProjectUtils;
 import org.wesnoth.templates.ReplaceableParameter;
@@ -609,6 +610,26 @@
         return containersToAdd;
     }
 
+    /**
+     * Gets the associated dependency index for the specified file
+     * @param file The file to get the index for
+     * @return An index or {@link Integer.MAX_VALUE}
+     */
+    public static int getDependencyIndex( IFile file )
+    {
+        int index = Integer.MAX_VALUE;
+        try {
+            index  = Integer.parseInt( file.getPersistentProperty( 
DependencyListNode.PDL_INDEX ) );
+        }
+        catch ( CoreException e ) {
+            // not interested
+        }
+        catch (NumberFormatException e) {
+            // not interested
+        }
+
+        return index;
+    }
 
     /**
      * This is a WML files comparator, based on the WML parsing rules.

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=50413&r1=50412&r2=50413&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:27:38 2011
@@ -11,6 +11,8 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.emf.common.util.TreeIterator;
 import org.eclipse.emf.ecore.EObject;
+import org.eclipse.xtext.nodemodel.ICompositeNode;
+import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
 import org.wesnoth.utils.ResourceUtils;
 import org.wesnoth.utils.WMLUtils;
 import org.wesnoth.wml.WMLKey;
@@ -51,6 +53,9 @@
      */
     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;
@@ -101,7 +106,25 @@
 
     protected void handleSetVariable( EObject context )
     {
+        WMLVariable variable = new WMLVariable( );
+        ICompositeNode node = NodeModelUtils.getNode( context ) ;
 
+        variable.setLocation( file_.getLocation( ).toOSString( ) );
+        variable.setScopeStartIndex( ResourceUtils.getDependencyIndex( file_ ) 
);
+        variable.setOffset( node.getTotalOffset( ) );
+
+        if ( context instanceof WMLKey ) {
+            variable.setName( WMLUtils.getKeyValue( ( ( WMLKey ) context 
).getValue( ) ) );
+        } else if ( context instanceof WMLMacroCall ) {
+            WMLMacroCall macro = ( WMLMacroCall ) context;
+            if ( macro.getParameters( ).size( ) > 0 ) {
+                variable.setName( WMLUtils.toString( macro.getParameters( 
).get( 0 ) ) );
+            }
+        }
+
+        if ( ! variable.getName( ).isEmpty( ) ) {
+            config_.getVariables( ).put( variable.getName( ), variable );
+        }
     }
 
     protected void handleUnsetVariable( EObject context )

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=50413&r1=50412&r2=50413&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:27:38 2011
@@ -17,6 +17,8 @@
        private String location_;
        private int offset_;
        private boolean isArray_;
+       private int scopeStartIndex_;
+       private int scopeEndIndex_;
 
        public WMLVariable()
        {
@@ -28,6 +30,9 @@
                name_ = name;
                location_ = location;
                offset_ = offset;
+
+               scopeStartIndex_ = Integer.MAX_VALUE;
+               scopeEndIndex_ = Integer.MAX_VALUE;
        }
 
        public String getName()
@@ -62,4 +67,21 @@
        {
                isArray_ = isArray;
        }
+
+       public int getScopeEndIndex()
+    {
+        return scopeEndIndex_;
+    }
+       public int getScopeStartIndex()
+    {
+        return scopeStartIndex_;
+    }
+       public void setScopeEndIndex( int scopeEndIndex )
+    {
+        scopeEndIndex_ = scopeEndIndex;
+    }
+       public void setScopeStartIndex( int scopeStartIndex )
+    {
+        scopeStartIndex_ = scopeStartIndex;
+    }
 }


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

Reply via email to