@SuppressWarnings("unchecked") public <T> T get( Class<T> expectedType, Map<Class<? extends Annotation>, IParameterProvider> context) { XtextResource xtextResource = context.get(ThisResource.class).get(XtextResource.class, context); return (T) NodeModelUtils.findLeafNodeAtOffset( xtextResource.getParseResult().getRootNode(), getOffset()); }
protected EObject find(XtextResource res, int offset, Class<?> expectedType) { INode leaf = NodeModelUtils.findLeafNodeAtOffset(res.getParseResult().getRootNode(), offset); Set<EObject> visited = Sets.newHashSet(); NodeIterator ni = null; while (ni == null || ni.hasNext()) { INode next = ni == null ? leaf : ni.next(); if (ni == null) ni = new NodeIterator(leaf); EObject result = find(expectedType, next, visited); if (result != null) return result; } return null; }
@Override public IHyperlink[] createHyperlinksByOffset( XtextResource resource, int offset, boolean createMultipleHyperlinks) { IHyperlink[] links = super.createHyperlinksByOffset(resource, offset, createMultipleHyperlinks); EObject eo = eObjectAtOffsetHelper.resolveElementAt(resource, offset); if (eo instanceof ControllerHandledValueProperty) { INode n = NodeModelUtils.getNode(eo); if (n != null) { INode currentNode = NodeModelUtils.findLeafNodeAtOffset(n, offset); List<INode> l = NodeModelUtils.findNodesForFeature( eo, FXGraphPackage.Literals.CONTROLLER_HANDLED_VALUE_PROPERTY__METHODNAME); if (l.contains(currentNode)) { Region region = new Region(currentNode.getOffset(), currentNode.getLength()); Model m = (Model) eo.eResource().getContents().get(0); if (m != null) { ComponentDefinition def = m.getComponentDef(); if (def != null) { if (def.getController() != null && def.getController().getType() != null) { IType t = getJDTType(def.getController().getType()); if (t != null) { IFXCtrlClass fxClass = FXPlugin.getClassmodel().findCtrlClass(t.getJavaProject(), t); if (fxClass != null) { IFXCtrlEventMethod fxp = fxClass.getAllEventMethods().get(currentNode.getText()); if (fxp != null) { HyperlinkImpl h = new HyperlinkImpl(region, fxp.getJavaElement()); if (links == null || links.length == 0) { return new IHyperlink[] {h}; } else { IHyperlink[] rv = new IHyperlink[links.length + 1]; System.arraycopy(links, 0, rv, 0, rv.length); rv[rv.length - 1] = h; return rv; } } } } } } } } } } return links; }
protected EStructuralFeatureAndEObject find(XtextResource resource, int offset) { INode leaf = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset); NodeIterator ni = null; while (ni == null || ni.hasNext()) { INode next = ni == null ? leaf : ni.next(); if (ni == null) ni = new NodeIterator(leaf); EObject object = NodeModelUtils.findActualSemanticObjectFor(next); INode current = next; do { Assignment ass = GrammarUtil.containingAssignment(current.getGrammarElement()); if (ass != null) { EStructuralFeature feat = object.eClass().getEStructuralFeature(ass.getFeature()); if (feat != null && matches(object, feat)) return create(object, feat); } current = current.getParent(); } while (current != null && object == NodeModelUtils.findActualSemanticObjectFor(current)); } throw new RuntimeException("No EStructuralFeature found at offset " + offset); }
protected void highlightAnnotation( XAnnotation annotation, IHighlightedPositionAcceptor acceptor, String highlightingConfiguration) { JvmType annotationType = annotation.getAnnotationType(); if (annotationType != null && !annotationType.eIsProxy() && annotationType instanceof JvmAnnotationType) { ICompositeNode xannotationNode = NodeModelUtils.findActualNodeFor(annotation); if (xannotationNode != null) { ILeafNode firstLeafNode = NodeModelUtils.findLeafNodeAtOffset(xannotationNode, xannotationNode.getOffset()); if (firstLeafNode != null) highlightNode(acceptor, firstLeafNode, highlightingConfiguration); } highlightReferenceJvmType( acceptor, annotation, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, annotationType, highlightingConfiguration); } }