eclipse plugin: Use the new methods and classes...
...instead of the old node model's ones
This commit is contained in:
parent
2b36faa0ff
commit
948399d4a7
9 changed files with 39 additions and 30 deletions
|
@ -13,14 +13,15 @@ import org.eclipse.emf.ecore.EObject;
|
|||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
|
||||
|
||||
public class WMLUtil
|
||||
{
|
||||
public static String debug(EObject root)
|
||||
{
|
||||
ICompositeNode node = NodeUtil.getNode(root);
|
||||
Iterable<INode> contents = NodeUtil.getAllContents(node);
|
||||
ICompositeNode node = NodeModelUtils.getNode(root);
|
||||
Iterable<INode> contents = node.getAsTreeIterable( );
|
||||
StringBuffer text = new StringBuffer();
|
||||
for (INode abstractNode : contents)
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.jface.text.IDocument;
|
|||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.parser.IParseResult;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.ui.editor.XtextEditor;
|
||||
|
@ -45,7 +46,7 @@ public class ClosingEndTagAutoEditStrategy implements IAutoEditStrategy
|
|||
if(parseResult == null)
|
||||
return;
|
||||
ICompositeNode rootNode = parseResult.getRootNode();
|
||||
ILeafNode node = (ILeafNode) NodeUtil.findLeafNodeAtOffset(rootNode, command.offset);
|
||||
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, command.offset);
|
||||
|
||||
String tagName = ""; //$NON-NLS-1$
|
||||
EList<INode> children = node.getParent().getParent().getChildren();
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.eclipse.swt.graphics.Image;
|
|||
import org.eclipse.xtext.Assignment;
|
||||
import org.eclipse.xtext.RuleCall;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
|
||||
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
|
||||
import org.wesnoth.installs.WesnothInstallsUtils;
|
||||
|
@ -278,15 +278,14 @@ public class WMLProposalProvider extends AbstractWMLProposalProvider
|
|||
|
||||
if (parentTag != null)
|
||||
{
|
||||
ICompositeNode node = NodeUtil.getNode(model);
|
||||
ICompositeNode node = NodeModelUtils.getNode(model);
|
||||
|
||||
String parentIndent = ""; //$NON-NLS-1$
|
||||
if (context.getCurrentNode().getOffset() > 0)
|
||||
parentIndent = ((ILeafNode)NodeUtil.findLeafNodeAtOffset(node.getParent(),
|
||||
parentIndent = NodeModelUtils.findLeafNodeAtOffset(node.getParent(),
|
||||
context.getCurrentNode().getOffset() -
|
||||
// if we have a non-rule proposal, subtract 1
|
||||
(ruleProposal ? 0 : 1)
|
||||
)).getText();
|
||||
(ruleProposal ? 0 : 1) ).getText();
|
||||
|
||||
// remove ugly new lines that break indentation
|
||||
parentIndent = parentIndent.replace("\r", "").replace("\n", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
|
|
|
@ -15,7 +15,9 @@ import org.eclipse.jface.text.ITextSelection;
|
|||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.parser.IParseResult;
|
||||
import org.eclipse.xtext.resource.EObjectAtOffsetHelper;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.ui.editor.XtextEditor;
|
||||
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
|
||||
|
@ -28,11 +30,16 @@ import org.wesnoth.ui.WMLUtil;
|
|||
import org.wesnoth.wml.WMLMacroCall;
|
||||
import org.wesnoth.wml.WMLTag;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* A handler that handles pressing F2 on a resource in the editor
|
||||
*/
|
||||
public class WMLDocHandler extends AbstractHandler
|
||||
{
|
||||
@Inject
|
||||
private EObjectAtOffsetHelper eObjectAtOffsetHelper;
|
||||
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException
|
||||
{
|
||||
try
|
||||
|
@ -53,7 +60,7 @@ public class WMLDocHandler extends AbstractHandler
|
|||
positionAbsolute.y +=20;
|
||||
|
||||
IParseResult parseResult = resource.getParseResult();
|
||||
INode abstractNode = ParseTreeUtil.getCurrentOrPrecedingNodeByOffset(parseResult.getRootNode(), selection.getOffset());
|
||||
INode abstractNode = NodeModelUtils.getNode( eObjectAtOffsetHelper.resolveElementAt( resource, selection.getOffset( ) ) );
|
||||
if (abstractNode == null || abstractNode.eContainer() == null)
|
||||
return;
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
|
|||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.ui.editor.hyperlinking.HyperlinkHelper;
|
||||
import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor;
|
||||
|
@ -35,11 +36,12 @@ public class WMLHyperlinkHelper extends HyperlinkHelper
|
|||
IHyperlinkAcceptor acceptor)
|
||||
{
|
||||
super.createHyperlinksByOffset(resource, offset, acceptor);
|
||||
ICompositeNode rootNode = NodeUtil.getRootNode(resource.getContents().get(0));
|
||||
//TODO: test this
|
||||
ICompositeNode rootNode = resource.getParseResult( ).getRootNode( );
|
||||
if (rootNode == null)
|
||||
return;
|
||||
|
||||
ILeafNode node = (ILeafNode)NodeUtil.findLeafNodeAtOffset(rootNode, offset);
|
||||
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
|
||||
if (node == null)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +54,7 @@ public class WMLHyperlinkHelper extends HyperlinkHelper
|
|||
Paths paths = Preferences.getPaths( WesnothInstallsUtils.getInstallNameForResource( file ) );
|
||||
|
||||
createMacroHyperlink( file, paths, node, acceptor, resource );
|
||||
ILeafNode prevNode = (ILeafNode)NodeUtil.findLeafNodeAtOffset(rootNode,
|
||||
ILeafNode prevNode = NodeModelUtils.findLeafNodeAtOffset(rootNode,
|
||||
node.getOffset() - 1);
|
||||
if(prevNode == null)
|
||||
return;
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
|
|||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor;
|
||||
import org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator;
|
||||
|
@ -141,20 +142,16 @@ public class WMLSemanticHighlightingCalculator implements ISemanticHighlightingC
|
|||
@Override
|
||||
public INode getFirstFeatureNode(EObject semantic, String feature)
|
||||
{
|
||||
NodeAdapter adapter = NodeUtil.getNodeAdapter(semantic);
|
||||
if (adapter != null)
|
||||
ICompositeNode node = NodeModelUtils.findActualNodeFor( semantic );
|
||||
if (node != null)
|
||||
{
|
||||
ICompositeNode node = adapter.getParserNode();
|
||||
if (node != null)
|
||||
for (INode child : node.getChildren())
|
||||
{
|
||||
for (INode child : node.getChildren())
|
||||
if (child instanceof ILeafNode)
|
||||
{
|
||||
if (child instanceof ILeafNode)
|
||||
if (feature.equals(((ILeafNode) child).getFeature()))
|
||||
{
|
||||
if (feature.equals(((ILeafNode) child).getFeature()))
|
||||
{
|
||||
return child;
|
||||
}
|
||||
return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.xtext.Keyword;
|
|||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingReconciler;
|
||||
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
|
||||
|
@ -49,10 +50,10 @@ public class WMLBracketMatching extends DefaultBracketMatcher
|
|||
{
|
||||
if (state == null || state.getContents() == null || state.getContents().isEmpty())
|
||||
return null;
|
||||
ICompositeNode rootNode = NodeUtil.getRootNode(state.getContents().get(0));
|
||||
ICompositeNode rootNode = state.getParseResult( ).getRootNode( );
|
||||
if (rootNode == null)
|
||||
return null;
|
||||
INode node = NodeUtil.findLeafNodeAtOffset(rootNode, offset);
|
||||
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
|
|
|
@ -12,9 +12,10 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.impl.CompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.wesnoth.wml.WMLExpression;
|
||||
import org.wesnoth.wml.WMLKey;
|
||||
import org.wesnoth.wml.WMLKeyValue;
|
||||
|
@ -84,7 +85,7 @@ public class WMLGrammarUtils
|
|||
*/
|
||||
public static String toStringWMLKeyValue( WMLKeyValue keyValue )
|
||||
{
|
||||
ICompositeNode node = NodeUtil.getNode( keyValue );
|
||||
ICompositeNode node = NodeModelUtils.getNode( keyValue );
|
||||
if ( node == null )
|
||||
return "";
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.eclipse.core.runtime.Path;
|
|||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.validation.Check;
|
||||
import org.eclipse.xtext.validation.CheckType;
|
||||
import org.wesnoth.Messages;
|
||||
|
@ -47,12 +48,11 @@ public class WMLJavaValidator extends AbstractWMLJavaValidator
|
|||
// @Check(CheckType.NORMAL)
|
||||
public void checkNormalTagName(WMLTag tag)
|
||||
{
|
||||
ICompositeNode node = NodeUtil.getNodeAdapter(tag).getParserNode();
|
||||
ICompositeNode node = NodeModelUtils.getNode( tag );
|
||||
if (node != null)
|
||||
{
|
||||
ILeafNode parentNode = (ILeafNode)
|
||||
NodeUtil.findLeafNodeAtOffset(node.getParent(),
|
||||
node.getParent().getOffset() + 2);
|
||||
ILeafNode parentNode = NodeModelUtils.findLeafNodeAtOffset(node.getParent(),
|
||||
node.getParent().getOffset() + 2);
|
||||
|
||||
boolean found = false;
|
||||
String searchName = parentNode.getText();
|
||||
|
|
Loading…
Add table
Reference in a new issue