eclipse plugin: Migrate the rest of code to the new node model
This commit is contained in:
parent
359d2e3b4f
commit
89e0d88b1c
6 changed files with 89 additions and 71 deletions
|
@ -8,11 +8,11 @@
|
|||
*******************************************************************************/
|
||||
package org.wesnoth.ui.autoedit;
|
||||
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.DocumentCommand;
|
||||
import org.eclipse.jface.text.IAutoEditStrategy;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.xtext.nodemodel.BidiIterator;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
|
@ -46,41 +46,57 @@ public class ClosingEndTagAutoEditStrategy implements IAutoEditStrategy
|
|||
if(parseResult == null)
|
||||
return;
|
||||
ICompositeNode rootNode = parseResult.getRootNode();
|
||||
ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, command.offset);
|
||||
ILeafNode currentNode = NodeModelUtils.findLeafNodeAtOffset(rootNode, command.offset);
|
||||
|
||||
String tagName = ""; //$NON-NLS-1$
|
||||
EList<INode> children = node.getParent().getParent().getChildren();
|
||||
for(int i = 0 ;i < children.size(); ++i)
|
||||
{
|
||||
if ((children.get(i) instanceof ILeafNode) == false)
|
||||
continue;
|
||||
// we need one more child
|
||||
if (i+1 >= children.size())
|
||||
continue;
|
||||
if (((ILeafNode)children.get(i)).getText().equals("[")) //$NON-NLS-1$
|
||||
{
|
||||
if (children.get(i+1) instanceof ILeafNode)
|
||||
{
|
||||
// in case we have [+
|
||||
if (((ILeafNode)children.get(i+1)).getText().equals("+")) //$NON-NLS-1$
|
||||
{
|
||||
if (i+2 >= children.size() ||
|
||||
(children.get(i+2) instanceof ILeafNode) == false)
|
||||
continue;
|
||||
tagName = ((ILeafNode)children.get(i+2)).getText();
|
||||
}
|
||||
else
|
||||
{
|
||||
tagName = ((ILeafNode)children.get(i+1)).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tagName.isEmpty() == false)
|
||||
{
|
||||
command.shiftsCaret = true;
|
||||
command.text = ("/" + tagName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
BidiIterator<INode> itor = currentNode.getParent( ).getChildren( ).iterator( );
|
||||
|
||||
//TODO test the new closing tag strategy
|
||||
|
||||
INode prevNode = null;
|
||||
while ( itor.hasNext( ) ) {
|
||||
INode node = itor.next( );
|
||||
|
||||
if ( node instanceof ILeafNode == false)
|
||||
continue;
|
||||
|
||||
if ( itor.hasNext( ) )
|
||||
|
||||
prevNode = node;
|
||||
}
|
||||
|
||||
// EList<INode> children = currentNode.getParent().getParent().getChildren();
|
||||
// for(int i = 0 ;i < children.size(); ++i)
|
||||
// {
|
||||
// if ((children.get(i) instanceof ILeafNode) == false)
|
||||
// continue;
|
||||
// // we need one more child
|
||||
// if (i+1 >= children.size())
|
||||
// continue;
|
||||
// if (((ILeafNode)children.get(i)).getText().equals("[")) //$NON-NLS-1$
|
||||
// {
|
||||
// if (children.get(i+1) instanceof ILeafNode)
|
||||
// {
|
||||
// // in case we have [+
|
||||
// if (((ILeafNode)children.get(i+1)).getText().equals("+")) //$NON-NLS-1$
|
||||
// {
|
||||
// if (i+2 >= children.size() ||
|
||||
// (children.get(i+2) instanceof ILeafNode) == false)
|
||||
// continue;
|
||||
// tagName = ((ILeafNode)children.get(i+2)).getText();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// tagName = ((ILeafNode)children.get(i+1)).getText();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (tagName.isEmpty() == false)
|
||||
// {
|
||||
// command.shiftsCaret = true;
|
||||
// command.text = ("/" + tagName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ package org.wesnoth.ui.labeling.wmldoc;
|
|||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
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;
|
||||
|
@ -62,13 +62,13 @@ public class WMLDocHandler extends AbstractHandler
|
|||
IParseResult parseResult = resource.getParseResult();
|
||||
//TODO: check this
|
||||
INode abstractNode = NodeModelUtils.getNode( eObjectAtOffsetHelper.resolveElementAt( resource, selection.getOffset( ) ) );
|
||||
if (abstractNode == null || abstractNode.eContainer() == null)
|
||||
if (abstractNode == null )
|
||||
return;
|
||||
|
||||
ICompositeNode container = (ICompositeNode)abstractNode.eContainer();
|
||||
if (container.getElement() instanceof WMLMacroCall)
|
||||
EObject grammarElement = abstractNode.getGrammarElement( );
|
||||
if ( grammarElement instanceof WMLMacroCall )
|
||||
{
|
||||
WMLMacroCall macro = (WMLMacroCall)container.getElement();
|
||||
WMLMacroCall macro = (WMLMacroCall) grammarElement;
|
||||
Define define = ProjectUtils.getCacheForProject(
|
||||
WMLUtil.getActiveEditorFile().getProject())
|
||||
.getDefines().get(macro.getName());
|
||||
|
@ -85,13 +85,13 @@ public class WMLDocHandler extends AbstractHandler
|
|||
presenter_.open();
|
||||
}
|
||||
}
|
||||
else if (container.getElement() instanceof WMLTag)
|
||||
else if ( grammarElement instanceof WMLTag)
|
||||
{
|
||||
if (presenter_ == null)
|
||||
{
|
||||
presenter_ = new WMLDocInformationPresenter(
|
||||
editor.getSite().getShell(),
|
||||
new WMLDocTag( installName, ((WMLTag)container.getElement()).getName()),
|
||||
new WMLDocTag( installName, ( ( WMLTag ) grammarElement ).getName() ),
|
||||
positionAbsolute);
|
||||
presenter_.create();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package org.wesnoth.ui.navigation;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
|
@ -70,15 +71,16 @@ public class WMLHyperlinkHelper extends HyperlinkHelper
|
|||
private void createMacroHyperlink( IFile file, Paths paths, ILeafNode node,
|
||||
IHyperlinkAcceptor acceptor, XtextResource resource)
|
||||
{
|
||||
if (node.eContainer() == null ||
|
||||
(node.eContainer() instanceof ICompositeNode) == false)
|
||||
if ( node instanceof ICompositeNode == false)
|
||||
return;
|
||||
|
||||
ICompositeNode container = (ICompositeNode)node.eContainer();
|
||||
if ((container.getElement() instanceof WMLMacroCall) == false)
|
||||
//TODO: test
|
||||
ICompositeNode container = (ICompositeNode)node;
|
||||
EObject grammarElement = container.getGrammarElement( );
|
||||
if ( grammarElement instanceof WMLMacroCall == false)
|
||||
return;
|
||||
|
||||
WMLMacroCall macro = (WMLMacroCall)container.getElement();
|
||||
WMLMacroCall macro = (WMLMacroCall) grammarElement;
|
||||
|
||||
// get the define for the macro
|
||||
Define define = ProjectUtils.getCacheForProject(file.getProject()).getDefines().get(macro.getName());
|
||||
|
|
|
@ -176,7 +176,7 @@ public class WMLCharacterPairMatcher extends DefaultCharacterPairMatcher
|
|||
|
||||
private boolean isWMLTag(INode node)
|
||||
{
|
||||
return (node.eContainer() != null &&
|
||||
node.eContainer() instanceof ICompositeNode && ((ICompositeNode) node.eContainer()).getElement() instanceof WMLTag);
|
||||
return ( node != null &&
|
||||
node.getGrammarElement( ) instanceof WMLTag );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
package org.wesnoth.ui.syntax;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EStructuralFeature;
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
|
@ -51,41 +53,41 @@ public class WMLSemanticHighlightingCalculator implements ISemanticHighlightingC
|
|||
String beginId = null, endId = null;
|
||||
if (current instanceof WMLTag)
|
||||
{
|
||||
begin = getFirstFeatureNode(current, WmlPackage.eINSTANCE.getWMLExpression_Name( ).getName( ));
|
||||
begin = getFirstFeatureNode( current, WmlPackage.Literals.WML_EXPRESSION__NAME );
|
||||
beginId = WMLHighlightingConfiguration.RULE_WML_TAG;
|
||||
|
||||
end = getFirstFeatureNode(current, WmlPackage.Literals.WML_TAG__END_NAME.getName());
|
||||
end = getFirstFeatureNode( current, WmlPackage.Literals.WML_TAG__END_NAME );
|
||||
endId = WMLHighlightingConfiguration.RULE_WML_TAG;
|
||||
}
|
||||
else if (current instanceof WMLKey)
|
||||
{
|
||||
begin = getFirstFeatureNode(current, WmlPackage.eINSTANCE.getWMLExpression_Name( ).getName());
|
||||
begin = getFirstFeatureNode( current, WmlPackage.Literals.WML_EXPRESSION__NAME );
|
||||
beginId = WMLHighlightingConfiguration.RULE_WML_KEY;
|
||||
}
|
||||
else if (current instanceof WMLMacroCall)
|
||||
{
|
||||
begin = getFirstFeatureNode(current, WmlPackage.eINSTANCE.getWMLExpression_Name( ).getName());
|
||||
begin = getFirstFeatureNode( current, WmlPackage.Literals.WML_EXPRESSION__NAME );
|
||||
beginId = WMLHighlightingConfiguration.RULE_WML_MACRO_CALL;
|
||||
}
|
||||
else if (current instanceof WMLTextdomain)
|
||||
{
|
||||
begin = getFirstFeatureNode(current, WmlPackage.eINSTANCE.getWMLExpression_Name( ).getName());
|
||||
begin = getFirstFeatureNode( current, WmlPackage.Literals.WML_EXPRESSION__NAME );
|
||||
beginId = WMLHighlightingConfiguration.RULE_WML_TEXTDOMAIN;
|
||||
}
|
||||
else if (current instanceof WMLPreprocIF)
|
||||
{
|
||||
begin = getFirstFeatureNode(current, WmlPackage.eINSTANCE.getWMLExpression_Name( ).getName());
|
||||
begin = getFirstFeatureNode( current, WmlPackage.Literals.WML_EXPRESSION__NAME );
|
||||
beginId = WMLHighlightingConfiguration.RULE_WML_IF;
|
||||
|
||||
end = getFirstFeatureNode(current, WmlPackage.Literals.WML_PREPROC_IF__END_NAME.getName());
|
||||
end = getFirstFeatureNode( current, WmlPackage.Literals.WML_EXPRESSION__NAME );
|
||||
endId = WMLHighlightingConfiguration.RULE_WML_IF;
|
||||
}
|
||||
else if (current instanceof WMLMacroDefine)
|
||||
{
|
||||
begin = getFirstFeatureNode(current, WmlPackage.eINSTANCE.getWMLExpression_Name( ).getName());
|
||||
begin = getFirstFeatureNode( current, WmlPackage.Literals.WML_EXPRESSION__NAME );
|
||||
beginId = WMLHighlightingConfiguration.RULE_WML_MACRO_DEFINE;
|
||||
|
||||
end = getFirstFeatureNode(current, WmlPackage.Literals.WML_MACRO_DEFINE__END_NAME.getName());
|
||||
end = getFirstFeatureNode( current, WmlPackage.Literals.WML_MACRO_DEFINE__END_NAME );
|
||||
endId = WMLHighlightingConfiguration.RULE_WML_MACRO_DEFINE;
|
||||
}
|
||||
|
||||
|
@ -139,24 +141,22 @@ public class WMLSemanticHighlightingCalculator implements ISemanticHighlightingC
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public INode getFirstFeatureNode(EObject semantic, String feature)
|
||||
public INode getFirstFeatureNode(EObject semantic, EStructuralFeature feature)
|
||||
{
|
||||
ICompositeNode node = NodeModelUtils.findActualNodeFor( semantic );
|
||||
if (node != null)
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
for (INode child : node.getChildren())
|
||||
{
|
||||
for (INode child : node.getChildren())
|
||||
{
|
||||
if (child instanceof ILeafNode)
|
||||
{
|
||||
if (feature.equals(((ILeafNode) child).getFeature()))
|
||||
{
|
||||
return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( child instanceof ILeafNode == false)
|
||||
continue;
|
||||
|
||||
List<INode> features = NodeModelUtils.findNodesForFeature(
|
||||
child.getGrammarElement( ), feature );
|
||||
if ( !features.isEmpty( ) )
|
||||
return features.get( 0 );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -56,7 +56,7 @@ public class WMLJavaValidator extends AbstractWMLJavaValidator
|
|||
|
||||
boolean found = false;
|
||||
String searchName = parentNode.getText();
|
||||
if (node.getParent().eContainer() == null) // root node
|
||||
if (node.getParent() == null) // root node
|
||||
{
|
||||
searchName = "root"; //$NON-NLS-1$
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue