All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fife.rsta.ac.js.PreProcesssingScripts Maven / Gradle / Ivy

Go to download

A library adding code completion and other advanced features for Java, JavaScript, Perl, and other languages to RSyntaxTextArea.

There is a newer version: 3.3.0
Show newest version
package org.fife.rsta.ac.js;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;

import org.fife.rsta.ac.js.ast.CodeBlock;
import org.mozilla.javascript.CompilerEnvirons;
import org.mozilla.javascript.Parser;
import org.mozilla.javascript.ast.AstRoot;

/**
*
* Scripts to be processed before  parsing main script text
* 
* Useful for includes within JavaScript client
* 
* Caches the completions so they do not have to parsed every single time the main script text is parsed
*/
public class PreProcesssingScripts {
	
	private SourceCompletionProvider provider;
	
	private Set preProcessingCompletions = new HashSet();
	
	
	public PreProcesssingScripts(SourceCompletionProvider provider)
	{
		this.provider = provider;
	}
	
	public void parseScript(String scriptText)
	{
		if(scriptText != null && scriptText.length() > 0)
		{
			CompilerEnvirons env = JavaScriptParser.createCompilerEnvironment(new JavaScriptParser.JSErrorReporter(), provider.getLanguageSupport());
			Parser parser = new Parser(env);
			StringReader r = new StringReader(scriptText);
			try {
				AstRoot root = parser.parse(r, null, 0);
				CodeBlock block = provider.iterateAstRoot(root, preProcessingCompletions, "", Integer.MAX_VALUE, true);
				provider.recursivelyAddLocalVars(preProcessingCompletions, block, 0, null, false, true);
			}
			catch(IOException io) {
				//ignore this
			}
		}
	}
	
	
	public void reset()
	{
		preProcessingCompletions.clear();
		//remove all preProcessing Variables
		provider.getVariableResolver().resetPreProcessingVariables(true);
	}
	
	public Set getCompletions()
	{
		return preProcessingCompletions;
	}
	
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy