eclipse plugin: make the parsing of wmlparser much...

...faster by using the already preprocessed file
This commit is contained in:
Timotei Dolean 2010-07-27 19:08:06 +00:00
parent a297afdfbe
commit 5ccd0104b1
5 changed files with 41 additions and 27 deletions

View File

@ -25,6 +25,6 @@ public class RunWMLLintOnPreprocFile extends ObjectActionDelegate
PreprocessorUtils.preprocessFile(file, null);
WMLTools.runWMLToolAsWorkspaceJob(Tools.WMLLINT,
PreprocessorUtils.getPreprocessedFilePath(file, false));
PreprocessorUtils.getPreprocessedFilePath(file, false, false).toString());
}
}

View File

@ -75,8 +75,8 @@ public class GameUtils
{
String campaignId = ProjectUtils.getCampaignID(selectedResource);
String scenarioId = null;
if (scenario == true)
scenarioId = ProjectUtils.getScenarioID(selectedResource);
if (scenario == true && selectedResource instanceof IFile)
scenarioId = ProjectUtils.getScenarioID((IFile)selectedResource);
if (campaignId == null)
{

View File

@ -37,10 +37,7 @@ public class PreprocessorUtils
*/
public static boolean preprocessFile(IFile file, List<String> defines)
{
String targetDirectory = WorkspaceUtils.getTemporaryFolder();
targetDirectory += file.getProject().getName() + "/";
targetDirectory += file.getParent().getProjectRelativePath().toOSString();
return preprocessFile(file, targetDirectory, defines, true);
return preprocessFile(file, getTemporaryLocation(file), defines, true);
}
/**
@ -120,17 +117,10 @@ public class PreprocessorUtils
return;
}
preprocessFile(file, null);
IFileStore preprocFile =
EFS.getLocalFileSystem().getStore(new Path(WorkspaceUtils.getTemporaryFolder()));
preprocFile = preprocFile.getChild(file.getName() +
(openPlain == true? ".plain" : ""));
try
{
IDE.openEditorOnFileStore(WorkspaceUtils.getWorkbenchWindow().getActivePage(),
preprocFile);
getPreprocessedFilePath(file, openPlain, true));
}
catch (Exception e)
{
@ -142,13 +132,31 @@ public class PreprocessorUtils
* Returns the path of the preprocessed file of the specified file
* @param file The file whom preprocessed file to get
* @param plain True to return the plain version file's file
* @param create if this is true, if the target preprocessed file
* doesn't exist it will be created.
* @return
*/
public static String getPreprocessedFilePath(IFile file, boolean plain)
public static IFileStore getPreprocessedFilePath(IFile file, boolean plain,
boolean create)
{
IFileStore preprocFile =
EFS.getLocalFileSystem().getStore(new Path(WorkspaceUtils.getTemporaryFolder()));
EFS.getLocalFileSystem().getStore(new Path(getTemporaryLocation(file)));
preprocFile = preprocFile.getChild(file.getName() + (plain == true? ".plain" : "") );
return preprocFile.toString();
if (create && !preprocFile.fetchInfo().exists())
preprocessFile(file, null);
return preprocFile;
}
/**
* Gets the temporary location where that file should be preprcessed
* @param file
* @return
*/
public static String getTemporaryLocation(IFile file)
{
String targetDirectory = WorkspaceUtils.getTemporaryFolder();
targetDirectory += file.getProject().getName() + "/";
targetDirectory += file.getParent().getProjectRelativePath().toOSString() + "/";
return targetDirectory;
}
}

View File

@ -159,7 +159,7 @@ public class ProjectUtils
}
/**
* Returns "_main.cfg" location
* Returns "_main.cfg" file
* from the specified resource or null if it isn't any
* It will start searching upwards starting from curren
* resource's directory, until it finds a '_main.cfg' but it will
@ -168,12 +168,12 @@ public class ProjectUtils
* @param resource The resource where to search for '_main.cfg'
* @return
*/
public static String getMainConfigLocation(IResource resource)
public static IFile getMainConfigLocation(IResource resource)
{
if (resource == null)
return null;
IResource targetResource = null;
IFile targetResource = null;
if (resource instanceof IProject)
{
IProject project = (IProject)resource;
@ -191,7 +191,7 @@ public class ProjectUtils
if (targetResource == null && resource instanceof IFile)
{
if (resource.getName().equals("_main.cfg"))
targetResource = resource;
targetResource = (IFile) resource;
else
{
IProject project = resource.getProject();
@ -218,8 +218,8 @@ public class ProjectUtils
}
}
if (targetResource == null)
return "";
return targetResource.getLocation().toOSString();
return null;
return targetResource;
}
/**
@ -231,7 +231,9 @@ public class ProjectUtils
*/
public static String getCampaignID(IResource resource)
{
WMLSaxHandler handler = getWMLHandlerFromResource(getMainConfigLocation(resource));
WMLSaxHandler handler = getWMLHandlerFromResource(
PreprocessorUtils.getPreprocessedFilePath(
getMainConfigLocation(resource), false, true).toString());
if (handler == null)
return null;
return handler.CampaignId;
@ -242,9 +244,10 @@ public class ProjectUtils
* @param fileName
* @return
*/
public static String getScenarioID(IResource resource)
public static String getScenarioID(IFile file)
{
WMLSaxHandler handler = getWMLHandlerFromResource(resource.getLocation().toOSString());
WMLSaxHandler handler = getWMLHandlerFromResource(
PreprocessorUtils.getPreprocessedFilePath(file, false, true).toString());
if (handler == null)
return null;
return handler.ScenarioId;

View File

@ -90,6 +90,9 @@ public class WMLTools
// xml output
arguments.add("-x");
// no preprocess
arguments.add("-n");
// wesnoth executable's path
arguments.add("-w");
arguments.add(Preferences.getString(Constants.P_WESNOTH_EXEC_PATH));