Author: timotei
Date: Tue Jul 26 17:28:48 2011
New Revision: 50416

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50416&view=rev
Log:
eclipse plugin: Add the parsed variables to the
variables proposal list

Modified:
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/contentassist/WMLProposalProvider.java
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.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.ui/src/org/wesnoth/ui/contentassist/WMLProposalProvider.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/contentassist/WMLProposalProvider.java?rev=50416&r1=50415&r2=50416&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/contentassist/WMLProposalProvider.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/contentassist/WMLProposalProvider.java
 Tue Jul 26 17:28:48 2011
@@ -8,6 +8,8 @@
  
*******************************************************************************/
 package org.wesnoth.ui.contentassist;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map.Entry;
 
@@ -33,16 +35,23 @@
 import org.wesnoth.ui.WMLUiModule;
 import org.wesnoth.ui.editor.WMLEditor;
 import org.wesnoth.ui.labeling.WMLLabelProvider;
+import org.wesnoth.utils.ResourceUtils;
 import org.wesnoth.utils.StringUtils;
 import org.wesnoth.utils.WMLUtils;
 import org.wesnoth.wml.WMLKey;
 import org.wesnoth.wml.WMLTag;
 import org.wesnoth.wml.core.WMLConfig;
+import org.wesnoth.wml.core.WMLVariable;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
 
 public class WMLProposalProvider extends AbstractWMLProposalProvider
 {
     protected SchemaParser schemaParser_;
     protected ProjectCache projectCache_;
+    protected int dependencyIndex_;
 
     protected static final int KEY_VALUE_PRIORITY = 1700;
     protected static final int KEY_NAME_PRIORITY = 1500;
@@ -86,6 +95,8 @@
         // load the schema so we know what to suggest for autocomplete
         SchemaParser.reloadSchemas( false );
         schemaParser_ = SchemaParser.getInstance( 
WesnothInstallsUtils.getInstallNameForResource( file ) );
+
+        dependencyIndex_ = ResourceUtils.getDependencyIndex( file );
        }
 
        @Override
@@ -217,7 +228,26 @@
                        }
                    } else {
                        // add variables
-                       List<String> variables = TemplateProvider.getInstance( 
).getCAC( "variables" );
+                       List<String> variables = new ArrayList<String>();
+                variables.addAll( TemplateProvider.getInstance( ).getCAC( 
"variables" ) );
+
+                       // filter variables by index
+                       Collection<String> projectVariables = 
Collections2.transform(
+                               projectCache_.getVariables( ).values( ),
+                        new Function<WMLVariable, String> () {
+
+                    @Override
+                    public String apply( WMLVariable from )
+                    {
+                        if ( from.getScopeStartIndex( ) <= dependencyIndex_ &&
+                             dependencyIndex_ <= from.getScopeEndIndex( ) )
+                            return from.getName( );
+                        return null;
+                    }
+                } );
+
+                       variables.addAll( Collections2.filter( projectVariables,
+                       Predicates.notNull( ) ) );
 
                        for ( String variable : variables ) {
                            acceptor.accept( createCompletionProposal( "$" + 
variable, context ) );
@@ -282,7 +312,7 @@
 
                        String parentIndent = ""; //$NON-NLS-1$
                        if (context.getCurrentNode().getOffset() > 0)
-                               parentIndent = 
NodeModelUtils.findLeafNodeAtOffset(node.getParent(),
+                               parentIndent = 
NodeModelUtils.findLeafNodeAtOffset(node,
                                                
context.getCurrentNode().getOffset() -
                                                // if we have a non-rule 
proposal, subtract 1
                                                (ruleProposal ? 0 : 1) 
).getText();
@@ -347,14 +377,14 @@
                if (ruleProposal)
                        proposal.append("["); //$NON-NLS-1$
                proposal.append(tag.getName());
-               proposal.append("]\n"); //$NON-NLS-1$
+               proposal.append("\n"); //$NON-NLS-1$
                for(TagKey key : tag.getKeyChildren())
                {
                        if (key.isRequired())
                                proposal.append(String.format("\t%s%s=\n", 
//$NON-NLS-1$
                                                indent, key.getName()));
                }
-               proposal.append(String.format("%s[/%s]",indent, 
tag.getName())); //$NON-NLS-1$
+               proposal.append(String.format("%s[/%s",indent, tag.getName())); 
//$NON-NLS-1$
                return createCompletionProposal(proposal.toString(), 
tag.getName(),
                        WML_TAG_IMAGE, context, TAG_PRIORITY);
        }

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.java?rev=50416&r1=50415&r2=50416&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.java 
(original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/templates/TemplateProvider.java 
Tue Jul 26 17:28:48 2011
@@ -194,14 +194,14 @@
        /**
         * Gets the Content Assist Config list for the specified type
         * @param type The type of the CAC
-        * @return A list of String values
+        * @return A list of String values. The returned list is read-only
         */
        public List<String> getCAC( String type )
        {
            List<String> result = cacs_.get( type );
 
            if ( result == null )
-               return new ArrayList<String>( 0 );
+               return new ArrayList<String>( );
 
            return result;
        }

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=50416&r1=50415&r2=50416&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:48 2011
@@ -14,6 +14,7 @@
 import org.eclipse.xtext.nodemodel.ICompositeNode;
 import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
 import org.wesnoth.projects.ProjectCache;
+import org.wesnoth.projects.ProjectUtils;
 import org.wesnoth.utils.ResourceUtils;
 import org.wesnoth.utils.WMLUtils;
 import org.wesnoth.wml.WMLKey;
@@ -37,8 +38,7 @@
      */
     public SimpleWMLParser( IFile file )
     {
-        file_ = file;
-        config_ = new WMLConfig( file.getProjectRelativePath( ).toString( ) );
+        this( file, new WMLConfig( file.getProjectRelativePath( ).toString( ) 
) );
     }
 
     /**
@@ -48,6 +48,7 @@
     {
         config_ = Preconditions.checkNotNull( config );
         file_ = file;
+        projectCache_ = ProjectUtils.getCacheForProject( file.getProject( ) );
     }
 
     /**
@@ -64,7 +65,6 @@
 
         while ( itor.hasNext( ) ) {
             EObject object = itor.next( );
-            System.out.println( object );
 
             if ( object instanceof WMLTag ) {
                 currentTag = ( WMLTag ) object;
@@ -95,8 +95,7 @@
             }
             else if ( object instanceof WMLMacroCall ) {
                 WMLMacroCall macroCall = ( WMLMacroCall ) object;
-                String macroCallName = macroCall.getName( );
-                if ( macroCallName.equals( "VARIABLE" ) ) {
+                if ( macroCall.getName( ).equals( "VARIABLE" ) ) {
                     handleSetVariable( object );
                 }
             }
@@ -125,6 +124,7 @@
 
         if ( ! variable.getName( ).isEmpty( ) ) {
             projectCache_.getVariables( ).put( variable.getName( ), variable );
+            System.out.println( "added variable: " + variable );
         }
     }
 

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=50416&r1=50415&r2=50416&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:48 2011
@@ -27,7 +27,7 @@
 
        public WMLVariable( String name, String location, int offset )
        {
-           this( name, location, offset, Integer.MAX_VALUE, Integer.MAX_VALUE 
);
+           this( name, location, offset, Integer.MIN_VALUE, Integer.MAX_VALUE 
);
        }
 
        public WMLVariable( String name, String location, int offset,
@@ -90,4 +90,13 @@
     {
         scopeStartIndex_ = scopeStartIndex;
     }
+
+       @Override
+       public String toString()
+       {
+           return "Variable - Name: " + name_ +
+                   "; Location:" + location_ +
+                   "; Offset:" + offset_ +
+                   "; Scope: " + scopeStartIndex_ + " -> " + scopeEndIndex_;
+       }
 }


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

Reply via email to