Validators are also using IDocument implementation but they do it in a
wise way. The only IDocument instance per file is created during
validation. Look at
DelegatingSourceValidator.validate(IValidationContext, reporter). It
asks for IDOMDocument instance for validating resource and the
calculate lines for reporter messages by invoking getLineOffset(offcet)
on document.
StructuredModelManager IDomModel instance is obtained from
StructuredModelManager that has complicated caching and sharing mechanism.
For now I would place instance of TextFileDocumentProvider class in
SeamValidation Helper and call it in SeamValidator.addError
try {
coreHelper.getDocumentProvider().connect(target);
message.setLineNo(coreHelper.getDocumentProvider().getDocument(target).getLineOfOffset(offset)+1);
} catch (BadLocationException e) {
// TBD error logging
} catch (CoreException e) {
// TBD error logging
}
that means it will create at least one IDocument instance per file
during validation session, not for every error marker.
Denis.
Max Rydahl Andersen wrote:
Parsing every file when there is an error !? I find that hard to
belive being a proper solution to this.
It will definitly not scale - you can have hundreds even thousands of
warnings and each of them parsing that file yet another time is not a
good way.
Is that how all other validators does it ?
-max
------- Forwarded message -------
From: jbosstools-commits(a)lists.jboss.org
To: jbosstools-commits(a)lists.jboss.org
Cc:
Subject: [jbosstools-commits] JBoss Tools SVN: r5362 -
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation.
Date: Tue, 18 Dec 2007 18:25:47 +0100
Author: dazarov
Date: 2007-12-18 12:25:47 -0500 (Tue, 18 Dec 2007)
New Revision: 5362
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1489
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java
2007-12-18 16:41:55 UTC (rev 5361)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java
2007-12-18 17:25:47 UTC (rev 5362)
@@ -12,15 +12,21 @@
import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.ISeamTextSourceReference;
+import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.SeamPreferences;
+import org.eclipse.jface.text.Document;
/**
* Abstract implementation of ISeamvalidator
@@ -71,10 +77,40 @@
IMessage message = new Message(getBaseName(),
messageSeverity, messageId, messageArguments, target,
ISeamValidator.MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
message.setLength(length);
message.setOffset(offset);
+ int lineNumber = getLineNumber(target, offset);
+ if(lineNumber != 0)message.setLineNo(lineNumber);
if(!ignore) {
reporter.addMessage(validationManager, message);
}
}
+
+ private int getLineNumber(IResource resource, int offset){
+ if(resource.getType() == IResource.FILE){
+ IFile file = (IFile)resource;
+ String content;
+ try {
+ if(!file.isSynchronized(IResource.DEPTH_ZERO)) {
+ // The resource is out of sync with the file system
+ // Just ignore this resource.
+ return 0;
+ }
+ content = FileUtil.readStream(file.getContents());
+ } catch (CoreException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ return 0;
+ }
+ Document document = new Document(content);
+ int lineNumber=0;
+ try{
+ lineNumber = document.getLineOfOffset(offset);
+ return lineNumber+1;
+ }catch(Exception e){
+ SeamCorePlugin.getPluginLog().logError(e);
+ return 0;
+ }
+ }
+ return 0;
+ }
protected void displaySubtask(String messageId) {
displaySubtask(messageId, null);
_______________________________________________
jbosstools-commits mailing list
jbosstools-commits(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jbosstools-commits