Author: timotei
Date: Sat Aug 6 23:13:24 2011
New Revision: 50633
URL: http://svn.gna.org/viewcvs/wesnoth?rev=50633&view=rev
Log:
eclipse plugin: Implement proposal for custom event names
Modified:
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/contentassist/WMLProposalProvider.java
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/projects/ProjectCache.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/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=50633&r1=50632&r2=50633&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
Sat Aug 6 23:13:24 2011
@@ -165,14 +165,12 @@
for( Entry< String, Define > define: projectCache_.getDefines( )
.entrySet( ) ) {
StringBuilder proposal = new StringBuilder( 10 );
- if( ruleProposal == true )
- {
+ if( ruleProposal == true ) {
proposal.append( "{" ); //$NON-NLS-1$
}
proposal.append( define.getKey( ) );
- for( String arg: define.getValue( ).getArguments( ) )
- {
+ for( String arg: define.getValue( ).getArguments( ) ) {
proposal.append( " " + arg ); //$NON-NLS-1$
}
proposal.append( "}" ); //$NON-NLS-1$
@@ -193,7 +191,7 @@
String keyName = key.getName( );
// handle the next_scenario and first_scenario
- if( keyName.equals( "next_scenario" ) || //$NON-NLS-1$
+ if( keyName.equals( "next_scenario" ) || //$NON-NLS-1$
keyName.equals( "first_scenario" ) ) //$NON-NLS-1$
{
for( WMLConfig config: projectCache_.getWMLConfigs( ).values( ) ) {
@@ -201,8 +199,8 @@
continue;
}
acceptor.accept( createCompletionProposal( config.ScenarioId,
- config.ScenarioId, SCENARIO_VALUE_IMAGE,
- context, KEY_VALUE_PRIORITY ) );
+ config.ScenarioId, SCENARIO_VALUE_IMAGE, context,
+ KEY_VALUE_PRIORITY ) );
}
}
else if( model.eContainer( ) != null
@@ -381,7 +379,7 @@
/**
* Returns the proposal for the specified tag, usign the specified indent
- *
+ *
* @param tag
* The tag from which to construct the proposal
* @param indent
@@ -395,8 +393,7 @@
boolean ruleProposal, ContentAssistContext context )
{
StringBuilder proposal = new StringBuilder( );
- if( ruleProposal )
- {
+ if( ruleProposal ) {
proposal.append( "[" ); //$NON-NLS-1$
}
proposal.append( tag.getName( ) );
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=50633&r1=50632&r2=50633&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
Sat Aug 6 23:13:24 2011
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <[email protected]>
- *
+ *
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -38,7 +38,7 @@
* A class that stores some project specific infos
* for current session.
* Some of the fields of this cache can be saved to disk
- *
+ *
* @see ProjectCache#saveCache()
*/
public class ProjectCache implements Serializable
@@ -56,7 +56,6 @@
private Map< String, WMLConfig > configFiles_;
private DependencyListBuilder dependTree_;
private Map< String, WMLVariable > variables_;
- private Set< String > events_;
public ProjectCache( IProject project )
{
@@ -66,7 +65,6 @@
defines_ = new HashMap< String, Define >( );
variables_ = new HashMap< String, WMLVariable >( );
properties_ = new HashMap< String, String >( );
- events_ = new HashSet< String >( );
dependTree_ = new DependencyListBuilder( project_ );
@@ -80,7 +78,7 @@
/**
* Gets the properties map for this project.
- *
+ *
* @return A map with properties of the project
*/
public Map< String, String > getProperties( )
@@ -92,7 +90,7 @@
* Gets the map with the WMLConfigs
* The key represent the filenames of the files
* and the value the scenarioId from that file
- *
+ *
* @return A map with key the file path and value the WMLConfig
*/
public Map< String, WMLConfig > getWMLConfigs( )
@@ -103,9 +101,9 @@
/**
* Gets the WMLConfig by the specified file project-relative path.
* If the WMLConfig doesn't exist it will be created
- *
+ *
* @param path
- * The project-relative path for the file.
+ * The project-relative path for the file.
* @return
*/
public WMLConfig getWMLConfig( String path )
@@ -121,7 +119,7 @@
/**
* Returns the variables found in this project
- *
+ *
* @return A multimap containing all the variables
*/
public Map< String, WMLVariable > getVariables( )
@@ -172,7 +170,7 @@
* Saves:
* - properties
* - existing scenarios
- *
+ *
* @return
*/
public boolean saveCache( )
@@ -195,10 +193,10 @@
/**
* Reads the defines files for this project
- *
+ *
* @param force
- * Read the defines even if the defines file's contents
- * haven't changed since last time read.
+ * Read the defines even if the defines file's contents
+ * haven't changed since last time read.
*/
public void readDefines( boolean force )
{
@@ -217,22 +215,12 @@
/**
* Returns the defines associated with this project
- *
+ *
* @return
*/
public Map< String, Define > getDefines( )
{
return defines_;
- }
-
- /**
- * Returns the list of events available in the project
- *
- * @return A set with events as strings
- */
- public Set< String > getEvents( )
- {
- return events_;
}
/**
@@ -246,9 +234,9 @@
/**
* Sets the new install used in the project
- *
+ *
* @param newInstallName
- * The new install name
+ * The new install name
*/
public void setInstallName( String newInstallName )
{
@@ -259,7 +247,7 @@
/**
* Returns the current dependency tree builder for this project
- *
+ *
* @return A dependency tree
*/
public DependencyListBuilder getDependencyList( )
@@ -272,10 +260,10 @@
*/
public void clear( )
{
- properties_ = new HashMap< String, String >( );
-
+ properties_.clear( );
configFiles_.clear( );
defines_.clear( );
+ variables_.clear( );
dependTree_ = new DependencyListBuilder( project_ );
definesTimestamp_ = - 1;
@@ -284,8 +272,24 @@
}
/**
+ * Returns the parsed Event names from the config files
+ *
+ * @return A set with event names
+ */
+ public Set< String > getEvents( )
+ {
+ Set< String > result = new HashSet< String >( );
+
+ for( WMLConfig config: configFiles_.values( ) ) {
+ result.addAll( config.getEvents( ) );
+ }
+
+ return result;
+ }
+
+ /**
* Returns the parsed WML Tags from all configs of this project
- *
+ *
* @return A list of Tags
*/
public Map< String, WMLTag > getWMLTags( )
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=50633&r1=50632&r2=50633&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
Sat Aug 6 23:13:24 2011
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2011 by Timotei Dolean <[email protected]>
- *
+ *
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,8 +13,6 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.TreeIterator;
@@ -34,17 +32,16 @@
*/
public class SimpleWMLParser
{
- protected WMLConfig config_;
- protected WMLRoot root_;
- protected ProjectCache projectCache_;
- protected int dependencyIndex_;
- protected List< WMLTag > tags_;
+ protected WMLConfig config_;
+ protected WMLRoot root_;
+ protected ProjectCache projectCache_;
+ protected int dependencyIndex_;
/**
* Creates a new parser for the specified file
- *
+ *
* @param file
- * The file which to parse
+ * The file which to parse
*/
public SimpleWMLParser( IFile file )
{
@@ -55,14 +52,14 @@
/**
* Creates a new parser and fills the specified config file
- *
+ *
* @param file
- * The file which to parse
+ * The file which to parse
* @param config
- * The config to fill
+ * The config to fill
* @param projCache
- * The project cache (can be null) on which to reflect
- * the parsed data
+ * The project cache (can be null) on which to reflect
+ * the parsed data
*/
public SimpleWMLParser( IFile file, WMLConfig config, ProjectCache
projCache )
{
@@ -70,8 +67,6 @@
root_ = ResourceUtils.getWMLRoot( file );
projectCache_ = projCache;
- tags_ = new ArrayList< WMLTag >( );
-
dependencyIndex_ = ResourceUtils.getDependencyIndex( file );
}
@@ -101,6 +96,8 @@
// clear tags
config_.getWMLTags( ).clear( );
+ config_.getEvents( ).clear( );
+
String currentFileLocation = root_.eResource( ).getURI( )
.toFileString( );
if( currentFileLocation == null ) {
@@ -146,6 +143,20 @@
|| currentTagName.equals( "clear_variables" )
) {
handleUnsetVariable( object );
}
+ else if( currentTagName.equals( "event" ) ) {
+ String eventName = key.getValue( );
+
+ if( eventName.charAt( 0 ) == '"' ) {
+ eventName = eventName.substring( 1 );
+ }
+
+ if( eventName.charAt( eventName.length( ) - 1 ) ==
'"' ) {
+ eventName = eventName.substring( 0,
+ eventName.length( ) - 1 );
+ }
+
+ config_.getEvents( ).add( eventName );
+ }
}
}
}
@@ -168,7 +179,6 @@
config_.getWMLTags( ).putAll( luaParser.getTags( ) );
}
}
- // TODO: parse custom events
}
protected String getVariableNameByContext( EObject context )
@@ -190,7 +200,6 @@
return variableName;
}
-
protected void handleSetVariable( EObject context )
{
if( projectCache_ == null ) {
@@ -213,8 +222,7 @@
int nodeOffset = NodeModelUtils.getNode( context ).getTotalOffset( );
for( Scope scope: variable.getScopes( ) ) {
- if( scope.contains( dependencyIndex_, nodeOffset ) )
- {
+ if( scope.contains( dependencyIndex_, nodeOffset ) ) {
return; // nothing to do
}
}
@@ -257,18 +265,8 @@
}
/**
- * Returns the parsed tags
- *
- * @return A list of tags
- */
- public List< WMLTag > getParsedTags( )
- {
- return tags_;
- }
-
- /**
* Returns the parsed WMLConfig
- *
+ *
* @return Returns the parsed WMLConfig
*/
public WMLConfig getParsedConfig( )
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=50633&r1=50632&r2=50633&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 Sat Aug
6 23:13:24 2011
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <[email protected]>
- *
+ *
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,7 +10,9 @@
import java.io.Serializable;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
/**
@@ -23,7 +25,7 @@
public String ScenarioId;
/**
* True if there was a [scenario] tag present in the file.
- *
+ *
* However The {@link WMLConfig#ScenarioId} may be null
*/
public boolean IsScenario;
@@ -31,18 +33,21 @@
public String CampaignId;
/**
* True if there was a [campaign] tag present in the file.
- *
+ *
* However The {@link WMLConfig#CampaignId} may be null
*/
public boolean IsCampaign;
private String filename_;
+
private Map< String, WMLTag > tags_;
+ private Set< String > events_;
public WMLConfig( String filename )
{
filename_ = filename;
tags_ = new HashMap< String, WMLTag >( );
+ events_ = new HashSet< String >( );
}
public String getFilename( )
@@ -52,7 +57,7 @@
/**
* Returns the parsed WML Tags from this config file
- *
+ *
* @return A list of Tags
*/
public Map< String, WMLTag > getWMLTags( )
@@ -67,4 +72,14 @@
+ ( ScenarioId == null ? "": ScenarioId ) + "; CampaignId: "
+ ( CampaignId == null ? "": CampaignId );
}
+
+ /**
+ * Returns the list of the parsed event names
+ *
+ * @return A set of event names
+ */
+ public Set< String > getEvents( )
+ {
+ return events_;
+ }
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits