[stringtemplate-interest] ST4: Bug: Selecting the root template in STVis will not select the complete output

Terence Parr parrt at cs.usfca.edu
Sat Apr 2 11:13:00 PDT 2011


I'm in the process of doing a lot of fixes in STViz at the moment; I think that was how I fixed it :)
Ter
On Mar 31, 2011, at 11:39 PM, Udo Borkowski wrote:

> Here a much simpler fix for the issue:
> 
> Replace the last "else" clause in STVis.updateCurrentST by
> 
> 		else {
> 			// The root ST is selected. As this ST generates the complete output
> 			// select the complete output
> 			highlight(m.output, 0, m.output.getText().length());
> 		}
> 
> Udo
> 
> On 31.03.2011, at 12:27, Udo Borkowski wrote:
> 
>> Selecting the root template in STVis  (i.e. the first one in the left tree) will not select the complete output but just as many characters as the root template text is long:
>> 
>> <PastedGraphic-1.pdf>
>> 
>> This can be fixed by changing the last else int STVis.updateCurrentST:
>> 
>> 
>> 	private void updateCurrentST(STViewFrame m) {
>> 		updateStack(currentST, m);
>> 		updateAttributes(currentST, m);
>>         m.bytecode.setText(currentST.impl.disasm());
>> 		JTreeASTModel astModel = new JTreeASTModel(new CommonTreeAdaptor(), currentST.impl.ast);
>> 		m.ast.setModel(astModel);
>> 
>> 		List<ST> pathST = currentST.getEnclosingInstanceStack(true);
>> 		Object[] path = new Object[pathST.size()];
>> 		int j = 0;
>> 		for (ST s : pathST) path[j++] = new JTreeSTModel.Wrapper((DebugST)s);
>> 
>> 		m.tree.setSelectionPath(new TreePath(path));
>> 
>> 		m.template.setText(currentST.impl.template);
>> 		Interval r = currentST.impl.getTemplateRange();
>> 		if ( currentST.enclosingInstance!=null ) {
>> 			int i = tmodel.getIndexOfChild((DebugST)currentST.enclosingInstance, currentST);
>> 			InterpEvent e = interp.getEvents(currentST.enclosingInstance).get(i);
>> 			if ( e instanceof EvalTemplateEvent) {
>> 				if ( currentST.isAnonSubtemplate() ) {
>> 					highlight(m.template, r.a, r.b);
>> 				}
>> 				highlight(m.output, e.outputStartChar, e.outputStopChar);
>> 			}
>> 		}
>> 		else {
>> 			// The last event is the EvalTemplateEvent for the root ST
>> 			int nEvents = allEvents.size();
>> 			if (nEvents > 0 && allEvents.get(nEvents-1) instanceof EvalTemplateEvent) {
>> 				EvalTemplateEvent e = (EvalTemplateEvent)allEvents.get(nEvents-1);
>> 				highlight(m.output, e.outputStartChar, e.outputStopChar);
>> 			}
>> 		}
>> 	}
>> 
>> 
>> <PastedGraphic-2.pdf>
>> 
>> Udo
>> 
>> P.S.: here some test code:
>> 
>>> package org.stringtemplate.v4.debug;
>>> 
>>> import java.awt.Window;
>>> 
>>> import org.junit.Test;
>>> import org.stringtemplate.v4.ST;
>>> import org.stringtemplate.v4.STGroup;
>>> import org.stringtemplate.v4.STGroupFile;
>>> 
>>> public class InspectTest extends BaseTest {
>>> 
>>> 	/**
>>> 	 * @return true if at least one Window is visible
>>> 	 */
>>> 	public static boolean isAnyWindowVisible() {
>>> 		for (Window w : Window.getWindows()) {
>>> 			if (w.isVisible())
>>> 				return true;
>>> 		}
>>> 		return false;
>>> 	}
>>> 
>>> 	public static void waitUntilAnyWindowIsVisible() {
>>> 		while (!isAnyWindowVisible()) {
>>> 			try {
>>> 				Thread.sleep(100);
>>> 			} catch (InterruptedException e) {
>>> 				// Ignore
>>> 			}
>>> 		}
>>> 	}
>>> 
>>> 	/**
>>> 	 * 
>>> 	 * @param someWindowMustBeVisible
>>> 	 *            [default: true] when true wait for at least one visible window
>>> 	 *            before waiting for all to close
>>> 	 */
>>> 	public static void waitUntilAllWindowsAreClosed(
>>> 			boolean someWindowMustBeVisible) {
>>> 		if (someWindowMustBeVisible) {
>>> 			waitUntilAnyWindowIsVisible();
>>> 		}
>>> 		while (isAnyWindowVisible()) {
>>> 			try {
>>> 				Thread.sleep(100);
>>> 			} catch (InterruptedException e) {
>>> 				// ignore
>>> 			}
>>> 		}
>>> 	}
>>> 
>>> 	public static void waitUntilAllWindowsAreClosed() {
>>> 		waitUntilAllWindowsAreClosed(true);
>>> 	}
>>> 
>>> 	@Test
>>> 	public void testOutputSelectionWhenSelectingRootTemplate() throws Exception {
>>> 		STGroup.debug = true;
>>> 
>>> 		String templates = "t(q) ::= <<\n-<q>-\n>>\n\nmain(p) ::= <<\n<p><t(p)><p>\n>>";
>>> 		writeFile(tmpdir, "t.stg", templates);
>>> 
>>> 		STGroup group = new STGroupFile(tmpdir + "/t.stg");
>>> 
>>> 		ST st = group.getInstanceOf("main");
>>> 		st.add("p", "LongText");
>>> 		((DebugST) st).inspect();
>>> 
>>> 		waitUntilAllWindowsAreClosed();
>>> 	}
>>> }
>> 
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list