Author: timotei
Date: Tue Jul 26 17:32:29 2011
New Revision: 50429
URL: http://svn.gna.org/viewcvs/wesnoth?rev=50429&view=rev
Log:
eclipse plugin: Refactor a bit the SimpleWMLParser
to make it more concrete on what it can do
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.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
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java?rev=50429&r1=50428&r2=50429&view=diff
==============================================================================
---
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
(original)
+++
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
Tue Jul 26 17:32:29 2011
@@ -310,8 +310,8 @@
monitor.subTask( String.format(
Messages.WesnothProjectBuilder_22, filePath ) );
WMLConfig config = projectCache_.getWMLConfig(
filePath );
- SimpleWMLParser parser = new SimpleWMLParser(
file, config );
- parser.parse( false );
+ SimpleWMLParser parser = new SimpleWMLParser(
file, config, projectCache_ );
+ parser.parse( );
monitor.worked(10);
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=50429&r1=50428&r2=50429&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:32:29 2011
@@ -409,7 +409,7 @@
public static String getCampaignID(IResource resource)
{
SimpleWMLParser parser = new SimpleWMLParser(
getMainConfigLocation( resource ) );
- parser.parse( true );
+ parser.parse( );
return parser.getParsedConfig( ).CampaignId;
}
@@ -421,7 +421,7 @@
public static String getScenarioID(IFile file)
{
SimpleWMLParser parser = new SimpleWMLParser( file );
- parser.parse( true );
+ parser.parse( );
return parser.getParsedConfig( ).ScenarioId;
}
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=50429&r1=50428&r2=50429&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:32:29 2011
@@ -14,10 +14,10 @@
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.wesnoth.Logger;
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;
+import org.wesnoth.wml.WMLLuaCode;
import org.wesnoth.wml.WMLMacroCall;
import org.wesnoth.wml.WMLRoot;
import org.wesnoth.wml.WMLTag;
@@ -37,30 +37,35 @@
/**
* Creates a new parser for the specified file
+ *
+ * @param file The file which to parse
*/
public SimpleWMLParser( IFile file )
{
- this( file, new WMLConfig( file.getProjectRelativePath( ).toString( )
) );
+ this( file, new WMLConfig( file.getProjectRelativePath( ).toString( )
), null );
}
/**
* Creates a new parser and fills the specified config file
- */
- public SimpleWMLParser( IFile file, WMLConfig config )
+ *
+ * @param file The file which to parse
+ * @param config The config to fill
+ * @param projCache The project cache (can be null) on which to reflect
+ * the parsed data
+ */
+ public SimpleWMLParser( IFile file, WMLConfig config, ProjectCache
projCache )
{
config_ = Preconditions.checkNotNull( config );
file_ = file;
- projectCache_ = ProjectUtils.getCacheForProject( file.getProject( ) );
+ projectCache_ = projCache;
dependencyIndex_ = ResourceUtils.getDependencyIndex( file );
}
/**
- * Parses the config. The results will be available in {@link
#getParsedConfig()}
- * @param configOnly If true, the parsing won't modify anything external
- * to the config object (like adding the variables to the project cache)
- */
- public void parse( boolean configOnly )
+ * Parses the config. The resulted config will be available in {@link
#getParsedConfig()}
+ */
+ public void parse( )
{
WMLRoot root = ResourceUtils.getWMLRoot( file_ );
TreeIterator<EObject> itor = root.eAllContents( );
@@ -89,33 +94,28 @@
config_.ScenarioId = WMLUtils.getKeyValue(
key.getValue( ) );
else if ( currentTagName.equals( "campaign" ) )
config_.CampaignId = WMLUtils.getKeyValue(
key.getValue( ) );
- }
-
- // now follows just things that modify project/file's
related info
- if ( configOnly == false ) {
- if ( keyName.equals( "name" ) ) {
- if ( currentTagName.equals( "set_variable" ) ||
- currentTagName.equals( "set_variables" ) ) {
- handleSetVariable( object );
- } else if ( currentTagName.equals(
"clear_variable" ) ||
- currentTagName.equals(
"clear_variables" ) ) {
- handleUnsetVariable( object );
- }
+ } else if ( keyName.equals( "name" ) ) {
+ if ( currentTagName.equals( "set_variable" ) ||
+ currentTagName.equals( "set_variables" ) ) {
+ handleSetVariable( object );
+ } else if ( currentTagName.equals( "clear_variable" )
||
+ currentTagName.equals( "clear_variables" )
) {
+ handleUnsetVariable( object );
}
}
}
}
else if ( object instanceof WMLMacroCall ) {
-
- if ( configOnly == false ) {
- WMLMacroCall macroCall = ( WMLMacroCall ) object;
- String macroCallName = macroCall.getName( );
- if ( macroCallName.equals( "VARIABLE" ) ) {
- handleSetVariable( object );
- } else if ( macroCallName.equals( "CLEAR_VARIABLE" ) ) {
- handleUnsetVariable( object );
- }
+ WMLMacroCall macroCall = ( WMLMacroCall ) object;
+ String macroCallName = macroCall.getName( );
+ if ( macroCallName.equals( "VARIABLE" ) ) {
+ handleSetVariable( object );
+ } else if ( macroCallName.equals( "CLEAR_VARIABLE" ) ) {
+ handleUnsetVariable( object );
}
+ }
+ else if ( object instanceof WMLLuaCode ) {
+
}
}
//TODO: parse custom events
@@ -142,6 +142,9 @@
protected void handleSetVariable( EObject context )
{
+ if ( projectCache_ == null )
+ return;
+
String variableName = getVariableNameByContext( context );
if ( variableName == null ) {
@@ -168,6 +171,9 @@
protected void handleUnsetVariable( EObject context )
{
+ if ( projectCache_ == null )
+ return;
+
String variableName = getVariableNameByContext( context );
if ( variableName == null ) {
Logger.getInstance( ).logWarn(
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits