Author: timotei
Date: Thu Aug  4 21:16:46 2011
New Revision: 50607

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50607&view=rev
Log:
eclipse plugin: Create a wrapper method over the
'resolveElementAt' to prevent the NPE bug in xtext

Modified:
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/navigation/WMLHyperlinkHelper.java
    
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java?rev=50607&r1=50606&r2=50607&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/labeling/wmldoc/WMLDocHandler.java
 Thu Aug  4 21:16:46 2011
@@ -7,6 +7,15 @@
  * http://www.eclipse.org/legal/epl-v10.html
  
*******************************************************************************/
 package org.wesnoth.ui.labeling.wmldoc;
+
+import org.wesnoth.Logger;
+import org.wesnoth.installs.WesnothInstallsUtils;
+import org.wesnoth.preprocessor.Define;
+import org.wesnoth.projects.ProjectUtils;
+import org.wesnoth.ui.editor.WMLEditor;
+import org.wesnoth.utils.WMLUtils;
+import org.wesnoth.wml.WMLMacroCall;
+import org.wesnoth.wml.WMLTag;
 
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
@@ -19,14 +28,6 @@
 import org.eclipse.xtext.ui.editor.XtextEditor;
 import org.eclipse.xtext.ui.editor.utils.EditorUtils;
 import org.eclipse.xtext.util.concurrent.IUnitOfWork;
-import org.wesnoth.Logger;
-import org.wesnoth.installs.WesnothInstallsUtils;
-import org.wesnoth.preprocessor.Define;
-import org.wesnoth.projects.ProjectUtils;
-import org.wesnoth.ui.editor.WMLEditor;
-import org.wesnoth.utils.WMLUtils;
-import org.wesnoth.wml.WMLMacroCall;
-import org.wesnoth.wml.WMLTag;
 
 /**
  * A handler that handles pressing F2 on a resource in the editor
@@ -52,7 +53,7 @@
                     Point positionAbsolute = 
editor.getInternalSourceViewer().getTextWidget().toDisplay(positionRelative);
                     positionAbsolute.y += 20;
 
-                    EObject grammarElement = WMLUtils.EObjectUtils( 
).resolveElementAt( resource, selection.getOffset( ) );
+                    EObject grammarElement = WMLUtils.resolveElementAt( 
resource, selection.getOffset( ) );
                     if ( grammarElement == null )
                         return;
 

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/navigation/WMLHyperlinkHelper.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/navigation/WMLHyperlinkHelper.java?rev=50607&r1=50606&r2=50607&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/navigation/WMLHyperlinkHelper.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/navigation/WMLHyperlinkHelper.java
 Thu Aug  4 21:16:46 2011
@@ -36,7 +36,7 @@
     {
         super.createHyperlinksByOffset(resource, offset, acceptor);
 
-        EObject object = WMLUtils.EObjectUtils( ).resolveElementAt( resource, 
offset );
+        EObject object = WMLUtils.resolveElementAt( resource, offset );
 
         if ( object == null )
             return;

Modified: 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java?rev=50607&r1=50606&r2=50607&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth.ui/src/org/wesnoth/ui/syntax/WMLCharacterPairMatcher.java
 Thu Aug  4 21:16:46 2011
@@ -10,6 +10,10 @@
 
 import java.util.Iterator;
 
+import org.wesnoth.ui.editor.WMLEditor;
+import org.wesnoth.utils.WMLUtils;
+import org.wesnoth.wml.WMLTag;
+
 import org.eclipse.emf.common.notify.Adapter;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.jface.text.IDocument;
@@ -19,9 +23,6 @@
 import org.eclipse.xtext.ui.editor.model.XtextDocument;
 import org.eclipse.xtext.ui.editor.utils.EditorUtils;
 import org.eclipse.xtext.util.concurrent.IUnitOfWork;
-import org.wesnoth.ui.editor.WMLEditor;
-import org.wesnoth.utils.WMLUtils;
-import org.wesnoth.wml.WMLTag;
 
 public class WMLCharacterPairMatcher extends DefaultCharacterPairMatcher
 {
@@ -70,12 +71,7 @@
 
     public synchronized void computeMatchingRegion(XtextResource state, int 
offset)
     {
-        EObject object = null;
-        try {
-            WMLUtils.EObjectUtils( ).resolveElementAt( state, offset );
-        } catch ( NullPointerException e ) {
-            // fix a bug in xtext when the document has syntax errors
-        }
+        EObject object = WMLUtils.resolveElementAt( state, offset );
 
         // do nothing if we clicked the same tag
         if ( currentTag_ == object )

Modified: trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java?rev=50607&r1=50606&r2=50607&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/WMLUtils.java Thu Aug 
 4 21:16:46 2011
@@ -8,14 +8,16 @@
  
*******************************************************************************/
 package org.wesnoth.utils;
 
+import org.wesnoth.wml.WMLExpression;
+import org.wesnoth.wml.WMLKey;
+import org.wesnoth.wml.WMLKeyValue;
+import org.wesnoth.wml.WMLTag;
+
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
 import org.eclipse.xtext.resource.EObjectAtOffsetHelper;
-import org.wesnoth.wml.WMLExpression;
-import org.wesnoth.wml.WMLKey;
-import org.wesnoth.wml.WMLKeyValue;
-import org.wesnoth.wml.WMLTag;
+import org.eclipse.xtext.resource.XtextResource;
 
 public class WMLUtils
 {
@@ -27,6 +29,17 @@
         }
 
         return eObjectAtOffsetHelper_;
+    }
+
+    public static EObject resolveElementAt( XtextResource resource, int offset 
) {
+        try{
+            return EObjectUtils( ).resolveElementAt( resource, offset );
+        }
+        catch( NullPointerException e ) {
+            // in xtext 2.0, there is a bug, that if the file
+            // contains errors, this method may throw a null pointer exception
+            return null;
+        }
     }
 
     /**


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to