eclipse plugin: Refactor the IFile to WMLRoot...

...conversion to its own method
This commit is contained in:
Timotei Dolean 2011-07-05 08:54:09 +00:00
parent d3750307b3
commit 77b3e42c12
5 changed files with 41 additions and 13 deletions

View file

@ -26,10 +26,13 @@ Require-Bundle: org.eclipse.xtext,
Import-Package: org.apache.log4j
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.wesnoth,
org.wesnoth.services,
org.wesnoth.formatting,
org.wesnoth.parseTreeConstruction,
org.wesnoth.parser.antlr,
org.wesnoth.parser.antlr.internal,
org.wesnoth.scoping,
org.wesnoth.services,
org.wesnoth.tests,
org.wesnoth.validation,
org.wesnoth.wml,
org.wesnoth.wml.impl,

View file

@ -57,3 +57,6 @@ Export-Package: org.wesnoth,
org.wesnoth.wml.core,
org.wesnoth.wml.schema,
org.wesnoth.wml.schema.impl
Import-Package: org.wesnoth.wml,
org.wesnoth.wml.impl,
org.wesnoth.wml.util

View file

@ -24,6 +24,8 @@ import org.eclipse.core.runtime.CoreException;
import org.wesnoth.Logger;
import org.wesnoth.builder.WesnothProjectBuilder.WMLFilesComparator;
import org.wesnoth.projects.ProjectDependencyNode;
import org.wesnoth.utils.ResourceUtils;
import org.wesnoth.wml.WMLRoot;
public class DependencyTreeBuilder
{
@ -53,9 +55,9 @@ public class DependencyTreeBuilder
IResource main_cfg = container.findMember( "_main.cfg" );
if ( main_cfg != null ) {
// add main.cfg to tree
WMLRoot root = ResourceUtils.getWMLRoot( ( IFile ) main_cfg );
//TODO process the other children depending on the contents
// of the file
// iterate to find macro calls that include other dirs
}else {
List<IResource> members = null;
try {

View file

@ -12,11 +12,7 @@ import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.wesnoth.utils.ResourceUtils;
import org.wesnoth.utils.WorkspaceUtils;
/**
@ -29,11 +25,7 @@ public class TestHandler extends AbstractHandler
public Object execute(ExecutionEvent event) throws ExecutionException
{
IFile file = WorkspaceUtils.getSelectedFile( );
URI uri = URI.createPlatformResourceURI( file.getFullPath( ).toString( ), true );
ResourceSet resSet = new ResourceSetImpl( );
Resource res = resSet.getResource( uri, true );
EObject obj = res.getContents( ).get( 0 );
System.out.println( obj);
System.out.println( ResourceUtils.getWMLRoot( file ));
// IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path("E:\\work\\java\\runtime-EclipseApplication\\A_Simple_Campaign\\scenarios\\atemplate.cfg"));
// try

View file

@ -34,6 +34,11 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.swt.SWT;
import org.wesnoth.Constants;
@ -43,6 +48,7 @@ import org.wesnoth.preprocessor.PreprocessorUtils;
import org.wesnoth.projects.ProjectUtils;
import org.wesnoth.templates.ReplaceableParameter;
import org.wesnoth.templates.TemplateProvider;
import org.wesnoth.wml.WMLRoot;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@ -476,4 +482,26 @@ public class ResourceUtils
return null;
}
}
/**
* Gets the WML Grammar root of the specified file
* @param file The file to get the WML model from
* @return A WMLRoot instance or null if there is none
*/
public static WMLRoot getWMLRoot( IFile file )
{
URI uri = URI.createPlatformResourceURI( file.getFullPath( ).toString( ), true );
ResourceSet resourceSet = new ResourceSetImpl( );
Resource resource = resourceSet.getResource( uri, true );
if ( resource == null ||
resource.getContents( ).isEmpty( ) )
return null;
EObject result = resource.getContents( ).get( 0 );
if ( result instanceof WMLRoot == false )
return null;
return ( WMLRoot ) result;
}
}