[jbosstools-dev] Fwd: [jbosstools-commits] JBoss Tools SVN: r5362 - trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation.

Max Rydahl Andersen max.andersen at redhat.com
Tue Dec 18 13:37:21 EST 2007


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 at lists.jboss.org
To: jbosstools-commits at 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 at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jbosstools-commits



-- 
--
Max Rydahl Andersen
callto://max.rydahl.andersen

Hibernate
max at hibernate.org
http://hibernate.org

JBoss a division of Red Hat
max.andersen at jboss.com




More information about the jbosstools-dev mailing list