Skip to main content



      Home
Home » Eclipse Projects » Dynamic Languages Toolkit (DLTK) » Use DefaultProblem to put error marker in editor(How is it possible to use the DefaultProblem class to have markers in editor)
Use DefaultProblem to put error marker in editor [message #507786] Thu, 14 January 2010 11:24 Go to next message
Eclipse UserFriend
Hi,

I have a DLTK editor and its content is parsed by another int another language. Anyway, when this language receive code with syntax error, parsing fails. I'm parsing the error string to be able to retreive its position in source. I've tried to use the DefaultProblem class to notify the error to the problem reporter but at runtime. There are no markers in editor. Any idea?

Regards
public class LuaSourceParser extends AbstractSourceParser {

	/**
	 * AST cache, allow to keep previous AST in mind when syntax errors occurs
	 */
	private static ModuleDeclaration _cache = null;

	/**
	 * Provide DLTK compliant AST
	 * 
	 * @return {@link ModuleDeclaration}, in case of syntax errors, the previous
	 *         valid AST is given
	 * @see org.eclipse.dltk.ast.parser.ISourceParser#parse(char[], char[],
	 *      org.eclipse.dltk.compiler.problem.IProblemReporter)
	 */
	@Override
	public ModuleDeclaration parse(char[] fileName, char[] source,
			IProblemReporter reporter) {

		// Analyze code
		NodeFactory factory = new NodeFactory(new String(source));

		/*
		 * Keep older version of AST in case of syntax errors, when cache is
		 * defined.
		 */
		if ((_cache == null) || !factory.errorDetected()) {
			_cache = factory.getRoot();
		}

		// Transfers problems if there is any
		if (factory.errorDetected()) {
			IProblem problem = buildProblem(fileName, factory.analyser());
			reporter.reportProblem(problem);
		}
		return _cache;
	}

	public IProblem buildProblem(char[] fileName, LuaParseErrorAnalyzer analyzer) {
		int col = analyzer.syntaxErrorColumn();
		int offset = analyzer.syntaxErrorOffset();
		int line = analyzer.syntaxErrorLine();
		int id = 1;
		int severity = ProblemSeverities.Error;
		String[] args = {};
		String error = analyzer.getErrorString();
		String file = new String(fileName);

		IProblem problem = new DefaultProblem(file, error, id, args, severity,
				offset, offset, line, col);
		return problem;
	}

}

[Updated on: Thu, 14 January 2010 11:25] by Moderator

Re: Use DefaultProblem to put error marker in editor [message #508314 is a reply to message #507786] Mon, 18 January 2010 06:47 Go to previous messageGo to next message
Eclipse UserFriend
Hi Kevin,

The following code works for me:

if (reporter != null) {
			reporter.reportProblem(buildProblem());
		}
...	
	private IProblem buildProblem() {
		int offset = 0;
		int line = 0; // 1st line
		int severity = ProblemSeverities.Error;
		String[] args = null;
		String message = "EXAMPLE ERROR";
		int id = 0;
		return new DefaultProblem(message, id, args, severity, offset, offset, line);
	}


Regards,
Alex
Re: Use DefaultProblem to put error marker in editor [message #508826 is a reply to message #508314] Wed, 20 January 2010 08:45 Go to previous messageGo to next message
Eclipse UserFriend
Hi, thanks for answering.

I've used exactly your code and nothing happened in my editor. As behavior I'm expecting something like a red cross on the editor's left. Am I right? All I do is to pass this DefaultProblem Object to the problem reporter. Is there any other action I should perform.

Regards
Re: Use DefaultProblem to put error marker in editor [message #510200 is a reply to message #508826] Tue, 26 January 2010 11:43 Go to previous messageGo to next message
Eclipse UserFriend
Hi Kevin,

At the moment problems are reported if
- project has your language nature
- file is on the buildpath in a project with correct nature.

I think your issue is related to these pre-conditions.

Regards,
Alex
Re: Use DefaultProblem to put error marker in editor [message #663548 is a reply to message #510200] Tue, 05 April 2011 11:08 Go to previous messageGo to next message
Eclipse UserFriend
I've managed to get the problem flag to display in the left column of the editor, triggered from a IBuildParticipant to do code validation.

How do I get the problem to also display in the "Problems" view?
Re: Use DefaultProblem to put error marker in editor [message #663586 is a reply to message #663548] Tue, 05 April 2011 13:31 Go to previous messageGo to next message
Eclipse UserFriend
Perhaps spoke too soon. The error marker seems to be ignoring the source line number. It always appears at line zero; it does appear to be paying attention to the start and end positions, though.
Re: Use DefaultProblem to put error marker in editor [message #663589 is a reply to message #663586] Tue, 05 April 2011 13:58 Go to previous message
Eclipse UserFriend
ok, the problem was that start/end positions were set to zero (I guess there is no "default" value for these), which made the line number ignored.

Perhaps we could use -1 as default values for start/end so they default to the line start/end if the line number is given? Otherwise calculating the line start/end is going to be useless boilerplate.
Previous Topic:NullPointerException related to AbstractInterpreterInstallType
Next Topic:[PDT/PHP] Find superclass(es) for given class
Goto Forum:
  


Current Time: Tue Jul 01 21:52:56 EDT 2025

Powered by FUDForum. Page generated in 0.03672 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top