Commit 3968e7c4 authored by Andrey Filippov's avatar Andrey Filippov

Added support fo Eclipse string resolution, such as verilog_project_loc

parent 1b718a7b
......@@ -14,7 +14,8 @@ bin.includes = icons/,\
LICENSE,\
INSTALL,\
CONTRIBUTORS_VEDITOR.txt,\
parsers/
parsers/,\
bin/
#
# Set the following to override the environment
......
......@@ -361,6 +361,12 @@
<extension
point="org.eclipse.core.variables.dynamicVariables">
<variable
name="verilog_project_loc"
description="Returns the absolute file system path of the project."
resolver="com.elphel.vdt.ui.variables.VerilogResolver"
supportsArgument="true">
</variable>
<variable
name="verilog_source_loc"
description="%verilog_source_loc.description"
......
......@@ -39,7 +39,6 @@ import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import org.eclipse.swt.widgets.Display;
import com.elphel.vdt.Txt;
import com.elphel.vdt.core.tools.contexts.BuildParamsItem;
import com.elphel.vdt.ui.MessageUI;
import com.elphel.vdt.veditor.VerilogPlugin;
import com.elphel.vdt.veditor.preference.PreferenceStrings;
......
......@@ -33,8 +33,14 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.IDynamicVariable;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.IValueVariable;
import org.eclipse.core.variables.VariablesPlugin;
import com.elphel.vdt.core.tools.ToolsCore;
import com.elphel.vdt.core.tools.config.Config;
import com.elphel.vdt.core.tools.config.ConfigException;
......@@ -327,7 +333,7 @@ public abstract class Context {
for(Iterator<String> lineIter = lines.iterator(); lineIter.hasNext();) {
String line = (String)lineIter.next();
// the result will not be used as some other parameter value, so topProcessor is null in the next line /Andrey
commandSequence.add(buildCommandString(line,null)); // TODO: parses them here? VERIFY
commandSequence.add(resolveStrings(buildCommandString(line,null))); // TODO: parses them here? VERIFY
}
// Here - already resolved to empty
......@@ -467,7 +473,7 @@ public abstract class Context {
// new ContextParamRepeaterRecognizer(this)
},topProcessor);
return processor.process(paramStringTemplate);
return processor.process(paramStringTemplate);
}
// recognizes parameter name (just %name), or simple generators
......@@ -492,7 +498,7 @@ public abstract class Context {
List<String> result= processor.process(stringTemplate);
if (result.size()==0) return "";
return result.get(0);
return result.get(0);
}
protected void initControlInterface() throws ConfigException {
......@@ -735,5 +741,90 @@ public abstract class Context {
private void checkNotInitialized() throws ConfigException {
if(initialized)
throw new ConfigException("Context cannot be re-initialized");
}
}
//Substitute Eclipse and VDT ("verilog_") strings ${} here, after all VDT parameter processing
// recursively resolve variables
private List<String> resolveStrings(List<String> preResolved){
List<String> resolved = new ArrayList<String>();
for (String s:preResolved){
resolved.add(resolveStrings(s));
}
return resolved;
}
private String resolveStrings(String s){
int start = s.indexOf("${");
if (start < 0) return s;
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) System.out.println("Before substitution\""+s+"\"");
int end = s.indexOf("}", start);
if (end < 0) return s;
String dynVar = s.substring(start+2,end).trim();
String dynValue = resolveEclipseVariables(dynVar);
if (dynValue == null) {
System.out.println("getEclipseSubstitutedString("+s+") - undefined variable: "+dynVar);
dynValue = s.substring(start,end+1); // just no substitution
}
String result = s.substring(0,start)+dynValue;
if (end < s.length()) result += resolveStrings(s.substring(end+1));
if (VerilogPlugin.getPreferenceBoolean(PreferenceStrings.DEBUG_OTHER)) System.out.println("After substitution\""+result+"\"");
return result;
}
// from http://www.programcreek.com/java-api-examples/index.php?api=org.eclipse.core.variables.IDynamicVariable
private String resolveEclipseVariables(String key){
if (key == null) return null;
IStringVariableManager variableManager=VariablesPlugin.getDefault().getStringVariableManager();
//debug
/*
IValueVariable [] variables = variableManager.getValueVariables();
IDynamicVariable [] dVariables = variableManager.getDynamicVariables();
System.out.println("resolveEclipseVariables: key=" + key);
for (IValueVariable v : variables){
System.out.println("resolveEclipseVariables: variables=" + v.getValue());
}
for (IDynamicVariable dv : dVariables){
if (!dv.getName().contains("prompt")) {
try {
System.out.print("resolveEclipseVariables: dVariables=" + dv.getName());
System.out.println(" -- "+dv.getValue(null));
} catch (CoreException e) {
// TODO Auto-generated catch block
System.out.println(" -- null?");
}
}
}
*/
int index=key.indexOf(':');
if (index > 1) {
String varName=key.substring(0,index);
IDynamicVariable variable=variableManager.getDynamicVariable(varName);
if (variable == null) return null;
try {
if (key.length() > index + 1) return variable.getValue(key.substring(index + 1));
return variable.getValue(null);
}
catch ( CoreException e) {
return null;
}
}
IValueVariable variable=variableManager.getValueVariable(key);
if (variable == null) {
IDynamicVariable dynamicVariable=variableManager.getDynamicVariable(key);
if (dynamicVariable == null) return null;
try {
return dynamicVariable.getValue(null);
}
catch ( CoreException e) {
return null;
}
}
return variable.getValue();
}
}
......@@ -77,7 +77,11 @@ public class VerilogResolver implements IDynamicVariableResolver {
*/
protected String translateToValue(IResource resource, IDynamicVariable variable) throws CoreException {
String name = variable.getName();
if (name.endsWith("_loc")) { //$NON-NLS-1$
if (name.endsWith("project_loc")) { //$NON-NLS-1$
resource = SelectedResourceManager.getDefault().getChosenVerilogFile();
return resource.getProject().getLocation().toOSString();
} else if (name.endsWith("_loc")) { //$NON-NLS-1$
return resource.getLocation().toOSString();
} else if (name.endsWith("_path")) { //$NON-NLS-1$
return resource.getFullPath().toOSString();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment