Author: timotei
Date: Tue Jul 26 17:40:24 2011
New Revision: 50447

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50447&view=rev
Log:
eclipse plugin: Implement the suggesting of
parsed lua tags & keys :D

Modified:
    trunk/utils/umc_dev/changelog
    trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/contentassist/WMLProposalProvider.java
    trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java
    trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/WML.ecore
    trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/WMLTag.java
    trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/impl/WMLTagImpl.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectCache.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleLuaParser.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleWMLParser.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/WMLConfig.java

Modified: trunk/utils/umc_dev/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/changelog?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- trunk/utils/umc_dev/changelog (original)
+++ trunk/utils/umc_dev/changelog Tue Jul 26 17:40:24 2011
@@ -15,6 +15,8 @@
        * Improved the content assist for:
                - variables
                - events
+               - tags & keys - now the lua defined tags and keys are recognized
+               and suggested to the user
 
 1.0.3
        * Fixed bug #18080

Modified: trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/WMLUiModule.java Tue 
Jul 26 17:40:24 2011
@@ -49,8 +49,6 @@
 @SuppressWarnings("all")
 public class WMLUiModule extends org.wesnoth.ui.AbstractWMLUiModule
 {
-       public final static boolean DEBUG = false;
-
        public WMLUiModule(AbstractUIPlugin plugin) {
                super(plugin);
        }

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=50447&r1=50446&r2=50447&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:40:24 2011
@@ -30,7 +30,6 @@
 import org.wesnoth.projects.ProjectUtils;
 import org.wesnoth.schema.SchemaParser;
 import org.wesnoth.templates.TemplateProvider;
-import org.wesnoth.ui.WMLUiModule;
 import org.wesnoth.ui.editor.WMLEditor;
 import org.wesnoth.ui.labeling.WMLLabelProvider;
 import org.wesnoth.utils.ResourceUtils;
@@ -93,7 +92,6 @@
         projectCache_ = ProjectUtils.getCacheForProject( file.getProject( ) );
 
         // load the schema so we know what to suggest for autocomplete
-        SchemaParser.reloadSchemas( false );
         schemaParser_ = SchemaParser.getInstance( 
WesnothInstallsUtils.getInstallNameForResource( file ) );
 
         dependencyIndex_ = ResourceUtils.getDependencyIndex( file );
@@ -105,7 +103,7 @@
        {
                super.completeWMLKey_Name(model, assignment, context, acceptor);
                refresh( );
-               dbg("completing wmlkeyname"); //$NON-NLS-1$
+
                addKeyNameProposals(model, context, acceptor);
        }
 
@@ -115,7 +113,7 @@
        {
                super.complete_WMLKeyValue(model, ruleCall, context, acceptor);
                refresh( );
-               dbg("completing wmlkeyvalue - rule"); //$NON-NLS-1$
+
                addKeyValueProposals(model, context, acceptor);
        }
 
@@ -125,7 +123,7 @@
        {
                super.complete_WMLTag(model, ruleCall, context, acceptor);
                refresh( );
-               dbg("completing wmltag - rule"); //$NON-NLS-1$
+
                addTagProposals(model, true, context, acceptor);
        }
 
@@ -135,7 +133,7 @@
        {
                super.completeWMLTag_Name(model, assignment, context, acceptor);
                refresh( );
-               dbg("completing wmltagname"); //$NON-NLS-1$
+
                addTagProposals(model, false, context, acceptor);
        }
 
@@ -145,7 +143,7 @@
        {
                super.completeWMLMacroCall_Name(model, assignment, context, 
acceptor);
                refresh( );
-               dbg("completing wmlmacrocallname"); //$NON-NLS-1$
+
                addMacroCallProposals(model, false, context, acceptor);
        }
 
@@ -155,7 +153,7 @@
        {
                super.complete_WMLMacroCall(model, ruleCall, context, acceptor);
                refresh( );
-               dbg("completing wmlmacrocall - rule"); //$NON-NLS-1$
+
                addMacroCallProposals(model, true, context, acceptor);
        }
 
@@ -183,7 +181,6 @@
        {
                if ( model == null || !( model instanceof WMLKey ) )
                    return;
-               dbg(model);
                WMLKey key = (WMLKey)model;
                String keyName = key.getName( );
 
@@ -273,7 +270,12 @@
 
                if (tag != null)
                {
-                   WMLTag schemaTag = 
schemaParser_.getTags().get(tag.getName());
+                   WMLTag schemaTag = schemaParser_.getTags().get( 
tag.getName() );
+                   // try getting the custom ones
+                   if ( schemaTag == null ) {
+                       schemaTag = projectCache_.getWMLTags( ).get( 
tag.getName( ) );
+                   }
+
                        if ( schemaTag != null)
                        {
                                for( WMLKey key : schemaTag.getWMLKeys( ) )
@@ -343,18 +345,21 @@
                                                                ruleProposal, 
context));
                                }
                        }
-                       else
-                               dbg("!!! no tag found with that name:" + 
parentTag.getName()); //$NON-NLS-1$
                }
                else // we are at the root
                {
                        WMLTag rootTag = schemaParser_.getTags().get("root"); 
//$NON-NLS-1$
-                       dbg( "root node. adding tags: "+ 
rootTag.getExpressions( ).size() ); //$NON-NLS-1$
                        for( WMLTag tag : rootTag.getWMLTags( ) )
                        {
                                acceptor.accept( createTagProposal( tag, "", 
ruleProposal, context ) ); //$NON-NLS-1$
                        }
                }
+
+        // parsed custom tags
+        for( WMLTag tag : projectCache_.getWMLTags( ).values( ) )
+        {
+            acceptor.accept( createTagProposal( tag, "", ruleProposal, context 
) ); //$NON-NLS-1$
+        }
        }
 
        /**
@@ -397,16 +402,4 @@
                return createCompletionProposal(proposal, new 
StyledString(displayString),
                                        image, priority, 
contentAssistContext.getPrefix(), contentAssistContext);
        }
-
-       /**
-        * Method for debugging the auto completion
-        * @param str
-        */
-       @SuppressWarnings( "unused" )
-    private void dbg(Object str)
-       {
-               if (!(WMLUiModule.DEBUG))
-                       return;
-               System.out.println(str.toString());
-       }
 }

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/editor/WMLEditor.java 
Tue Jul 26 17:40:24 2011
@@ -53,12 +53,13 @@
 import org.wesnoth.Logger;
 import org.wesnoth.WesnothPlugin;
 import org.wesnoth.ui.Messages;
-import org.wesnoth.ui.WMLUiModule;
 
 import com.google.inject.Inject;
 
 public class WMLEditor extends XtextEditor
 {
+    private final static boolean DEBUG = false;
+
        protected static final String AUTOLINK_PROJECT_NAME = 
"_AutoLinked_CFGExternalFiles_"; //$NON-NLS-1$
        protected static final String ENCODING_UTF8 = "utf-8"; //$NON-NLS-1$
 
@@ -70,7 +71,7 @@
        public WMLEditor()
        {
                super();
-               if (WMLUiModule.DEBUG)
+               if ( DEBUG )
                        
org.apache.log4j.Logger.getLogger(XtextEditor.class).setLevel(Level.DEBUG);
                // activate the wesnoth plugin
                WesnothPlugin.getDefault();

Modified: trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/WML.ecore
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/WML.ecore?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/WML.ecore (original)
+++ trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/WML.ecore Tue Jul 26 
17:40:24 2011
@@ -11,7 +11,7 @@
   <eClassifiers xsi:type="ecore:EClass" name="WMLTag" 
eSuperTypes="platform:/resource/org.wesnoth/src-gen/org/wesnoth/WML.ecore#//WMLRootExpression">
     <eOperations name="getWMLTags">
       <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel";>
-        <details key="body" value="&#xA;        EList&lt;WMLTag> result = new 
org.eclipse.emf.common.util.BasicEList&lt;WMLTag>();&#xA;        for ( 
WMLExpression expression : getExpressions( ) ) {&#xA;            if ( 
expression.isWMLTag( ) )&#xA;                result.add( expression.asWMLTag( ) 
);&#xA;        }&#xA;&#xA;        return result;"/>
+        <details key="body" value="EList&lt;WMLTag> result = new 
org.eclipse.emf.common.util.BasicEList&lt;WMLTag>();&#xA;        for ( 
WMLExpression expression : getExpressions( ) ) {&#xA;            if ( 
expression.isWMLTag( ) )&#xA;                result.add( expression.asWMLTag( ) 
);&#xA;        }&#xA;&#xA;        return result;"/>
       </eAnnotations>
       <eGenericType eClassifier="ecore:EDataType 
http://www.eclipse.org/emf/2002/Ecore#//EEList";>
         <eTypeArguments eClassifier="ecore:EClass 
platform:/resource/org.wesnoth/src-gen/org/wesnoth/WML.ecore#//WMLTag"/>

Modified: trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/WMLTag.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/WMLTag.java?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/WMLTag.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/WMLTag.java Tue Jul 
26 17:40:24 2011
@@ -186,7 +186,7 @@
    * <!-- begin-user-doc -->
    * <!-- end-user-doc -->
    * @model kind="operation" many="false"
-   *        annotation="http://www.eclipse.org/emf/2002/GenModel body='\n      
  EList<WMLTag> result = new 
org.eclipse.emf.common.util.BasicEList<WMLTag>();\n        for ( WMLExpression 
expression : getExpressions( ) ) {\n            if ( expression.isWMLTag( ) )\n 
               result.add( expression.asWMLTag( ) );\n        }\n\n        
return result;'"
+   *        annotation="http://www.eclipse.org/emf/2002/GenModel 
body='EList<WMLTag> result = new 
org.eclipse.emf.common.util.BasicEList<WMLTag>();\n        for ( WMLExpression 
expression : getExpressions( ) ) {\n            if ( expression.isWMLTag( ) )\n 
               result.add( expression.asWMLTag( ) );\n        }\n\n        
return result;'"
    * @generated
    */
   EList<WMLTag> getWMLTags();

Modified: 
trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/impl/WMLTagImpl.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/impl/WMLTagImpl.java?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/impl/WMLTagImpl.java 
(original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src-gen/org/wesnoth/wml/impl/WMLTagImpl.java 
Tue Jul 26 17:40:24 2011
@@ -313,8 +313,7 @@
    */
   public EList<WMLTag> getWMLTags()
   {
-    
-            EList<WMLTag> result = new 
org.eclipse.emf.common.util.BasicEList<WMLTag>();
+    EList<WMLTag> result = new 
org.eclipse.emf.common.util.BasicEList<WMLTag>();
             for ( WMLExpression expression : getExpressions( ) ) {
                 if ( expression.isWMLTag( ) )
                     result.add( expression.asWMLTag( ) );

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=50447&r1=50446&r2=50447&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:40:24 2011
@@ -30,6 +30,7 @@
 import org.wesnoth.preprocessor.PreprocessorUtils;
 import org.wesnoth.utils.ResourceUtils;
 import org.wesnoth.wml.WMLConfig;
+import org.wesnoth.wml.WMLTag;
 import org.wesnoth.wml.WMLVariable;
 
 /**
@@ -266,4 +267,18 @@
 
         saveCache( );
     }
+
+    /**
+     * Returns the parsed WML Tags from all configs of this project
+     * @return A list of Tags
+     */
+    public Map<String, WMLTag> getWMLTags()
+    {
+        Map<String, WMLTag> res = new HashMap<String, WMLTag>();
+        for ( WMLConfig config : configFiles_.values( ) ) {
+            res.putAll( config.getWMLTags( ) );
+        }
+
+        return res;
+    }
 }

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/schema/SchemaParser.java 
Tue Jul 26 17:40:24 2011
@@ -10,7 +10,7 @@
 
 import java.io.File;
 import java.io.Serializable;
-import java.util.Collections;
+import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
@@ -330,7 +330,13 @@
         */
        private void sortChildren( WMLTag tag)
        {
-           Collections.sort( tag.getExpressions( ), new CardinalityComparator( 
) );
+           WMLExpression[] expressions = ( WMLExpression[] ) 
tag.getExpressions( ).toArray( );
+           Arrays.sort( expressions, new CardinalityComparator( ) );
+           tag.getExpressions( ).clear( );
+
+           for ( WMLExpression expression : expressions ) {
+            tag.getExpressions( ).add( expression );
+        }
 
            for (  WMLTag subTag : tag.getWMLTags( ) ) {
                sortChildren( subTag );

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleLuaParser.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleLuaParser.java?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleLuaParser.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleLuaParser.java 
Tue Jul 26 17:40:24 2011
@@ -12,8 +12,9 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.io.StringReader;
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.wesnoth.Logger;
 import org.wesnoth.utils.StringUtils;
@@ -24,7 +25,7 @@
  */
 public class SimpleLuaParser
 {
-    private List<WMLTag> tags_;
+    private Map<String, WMLTag> tags_;
     private Reader reader_;
 
     private final static String TAG_REGEX = "wml_actions\\..+\\( *cfg *\\)";
@@ -33,7 +34,7 @@
 
     public SimpleLuaParser( String contents )
     {
-        tags_ = new ArrayList<WMLTag> ( );
+        tags_ = new HashMap<String, WMLTag>( );
         reader_ = new StringReader( contents == null ? "" : contents );
     }
 
@@ -61,7 +62,7 @@
                             token.lastIndexOf( '(' ) );
 
                     currentTag = WmlFactory2.eINSTANCE.createWMLTag( tagName );
-                    tags_.add( currentTag );
+                    tags_.put( tagName, currentTag );
                 }
 
                 // parse the attributes
@@ -94,9 +95,9 @@
 
     /**
      * Returns the parsed tags from the lua code
-     * @return A list with Tags
+     * @return A map with Tags
      */
-    public List< WMLTag > getTags()
+    public Map<String, WMLTag > getTags()
     {
         return tags_;
     }

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleWMLParser.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleWMLParser.java?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleWMLParser.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/SimpleWMLParser.java 
Tue Jul 26 17:40:24 2011
@@ -72,6 +72,9 @@
         TreeIterator<EObject> itor = root.eAllContents( );
         WMLTag currentTag = null;
         String currentTagName = "";
+
+        // clear tags
+        config_.getWMLTags( ).clear( );
 
         while ( itor.hasNext( ) ) {
             EObject object = itor.next( );
@@ -119,7 +122,8 @@
                 SimpleLuaParser luaParser = new SimpleLuaParser(
                         ( ( WMLLuaCode ) object ).getValue( ) );
                 luaParser.parse( );
-                tags_.addAll( luaParser.getTags( ) );
+
+                config_.getWMLTags( ).putAll( luaParser.getTags( ) );
             }
         }
         //TODO: parse custom events

Modified: trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/WMLConfig.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/WMLConfig.java?rev=50447&r1=50446&r2=50447&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/WMLConfig.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/WMLConfig.java Tue Jul 
26 17:40:24 2011
@@ -9,6 +9,8 @@
 package org.wesnoth.wml;
 
 import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
 
 
 /**
@@ -35,16 +37,27 @@
        public boolean IsCampaign;
 
        private String filename_;
+       private Map<String, WMLTag> tags_;
 
        public WMLConfig(String filename)
        {
                filename_ = filename;
+               tags_ = new HashMap<String, WMLTag>( );
        }
 
        public String getFilename()
        {
                return filename_;
        }
+
+    /**
+     * Returns the parsed WML Tags from this config file
+     * @return A list of Tags
+     */
+    public Map<String, WMLTag> getWMLTags()
+    {
+        return tags_;
+    }
 
        @Override
        public String toString()


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

Reply via email to