eclipse plugin: Implement proposal for custom event names

This commit is contained in:
Timotei Dolean 2011-08-06 21:13:24 +00:00
parent 4183265854
commit 924fb6503c
4 changed files with 90 additions and 76 deletions

View file

@ -165,14 +165,12 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
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 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
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 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
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 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
/**
* 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 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
boolean ruleProposal, ContentAssistContext context )
{
StringBuilder proposal = new StringBuilder( );
if( ruleProposal )
{
if( ruleProposal ) {
proposal.append( "[" ); //$NON-NLS-1$
}
proposal.append( tag.getName( ) );

View file

@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
*
* 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 @@ import org.wesnoth.wml.WMLVariable;
* 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 @@ public class ProjectCache implements Serializable
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 @@ public class ProjectCache implements Serializable
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 @@ public class ProjectCache implements Serializable
/**
* Gets the properties map for this project.
*
*
* @return A map with properties of the project
*/
public Map< String, String > getProperties( )
@ -92,7 +90,7 @@ public class ProjectCache implements Serializable
* 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 @@ public class ProjectCache implements Serializable
/**
* 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 @@ public class ProjectCache implements Serializable
/**
* Returns the variables found in this project
*
*
* @return A multimap containing all the variables
*/
public Map< String, WMLVariable > getVariables( )
@ -172,7 +170,7 @@ public class ProjectCache implements Serializable
* Saves:
* - properties
* - existing scenarios
*
*
* @return
*/
public boolean saveCache( )
@ -195,10 +193,10 @@ public class ProjectCache implements Serializable
/**
* 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,7 +215,7 @@ public class ProjectCache implements Serializable
/**
* Returns the defines associated with this project
*
*
* @return
*/
public Map< String, Define > getDefines( )
@ -225,16 +223,6 @@ public class ProjectCache implements Serializable
return defines_;
}
/**
* Returns the list of events available in the project
*
* @return A set with events as strings
*/
public Set< String > getEvents( )
{
return events_;
}
/**
* The name of the install used in the project
*/
@ -246,9 +234,9 @@ public class ProjectCache implements Serializable
/**
* 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 @@ public class ProjectCache implements Serializable
/**
* Returns the current dependency tree builder for this project
*
*
* @return A dependency tree
*/
public DependencyListBuilder getDependencyList( )
@ -272,10 +260,10 @@ public class ProjectCache implements Serializable
*/
public void clear( )
{
properties_ = new HashMap< String, String >( );
properties_.clear( );
configFiles_.clear( );
defines_.clear( );
variables_.clear( );
dependTree_ = new DependencyListBuilder( project_ );
definesTimestamp_ = - 1;
@ -283,9 +271,25 @@ public class ProjectCache implements Serializable
saveCache( );
}
/**
* 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( )

View file

@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2011 by Timotei Dolean <timotei21@gmail.com>
*
*
* 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 com.google.common.base.Preconditions;
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 @@ import org.wesnoth.wml.WMLVariable.Scope;
*/
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 @@ public class SimpleWMLParser
/**
* 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 @@ public class SimpleWMLParser
root_ = ResourceUtils.getWMLRoot( file );
projectCache_ = projCache;
tags_ = new ArrayList< WMLTag >( );
dependencyIndex_ = ResourceUtils.getDependencyIndex( file );
}
@ -101,6 +96,8 @@ public class SimpleWMLParser
// clear tags
config_.getWMLTags( ).clear( );
config_.getEvents( ).clear( );
String currentFileLocation = root_.eResource( ).getURI( )
.toFileString( );
if( currentFileLocation == null ) {
@ -146,6 +143,20 @@ public class SimpleWMLParser
|| 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 @@ public class SimpleWMLParser
config_.getWMLTags( ).putAll( luaParser.getTags( ) );
}
}
// TODO: parse custom events
}
protected String getVariableNameByContext( EObject context )
@ -190,7 +200,6 @@ public class SimpleWMLParser
return variableName;
}
protected void handleSetVariable( EObject context )
{
if( projectCache_ == null ) {
@ -213,8 +222,7 @@ public class SimpleWMLParser
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
}
}
@ -256,19 +264,9 @@ public class SimpleWMLParser
}
}
/**
* 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( )

View file

@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2010 - 2011 by Timotei Dolean <timotei21@gmail.com>
*
*
* 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 @@ package org.wesnoth.wml;
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 class WMLConfig implements Serializable
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 class WMLConfig implements Serializable
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 @@ public class WMLConfig implements Serializable
/**
* Returns the parsed WML Tags from this config file
*
*
* @return A list of Tags
*/
public Map< String, WMLTag > getWMLTags( )
@ -67,4 +72,14 @@ public class WMLConfig implements Serializable
+ ( 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_;
}
}