예제 #1
0
 private void addTypeCastToExplicitReceiver(
     XAbstractFeatureCall featureCall,
     IModificationContext context,
     JvmType declaringType,
     EReference structuralFeature)
     throws BadLocationException {
   List<INode> nodes = NodeModelUtils.findNodesForFeature(featureCall, structuralFeature);
   if (nodes.isEmpty()) return;
   INode firstNode = IterableExtensions.head(nodes);
   INode lastNode = IterableExtensions.last(nodes);
   int offset = firstNode.getOffset();
   int length = lastNode.getEndOffset() - offset;
   ReplacingAppendable appendable =
       appendableFactory.create(
           context.getXtextDocument(), (XtextResource) featureCall.eResource(), offset, length);
   appendable.append("(");
   ListIterator<INode> nodeIter = nodes.listIterator();
   while (nodeIter.hasNext()) {
     String text = nodeIter.next().getText();
     if (nodeIter.previousIndex() == 0) appendable.append(Strings.removeLeadingWhitespace(text));
     else if (nodeIter.nextIndex() == nodes.size())
       appendable.append(Strings.trimTrailingLineBreak(text));
     else appendable.append(text);
   }
   appendable.append(" as ");
   appendable.append(declaringType);
   appendable.append(")");
   appendable.commitChanges();
 }
 @Override
 protected PsiElement getInternalNavigationElement() {
   List<INode> _findNodesForFeature = NodeModelUtils.findNodesForFeature(this.owner, this.feature);
   final Function1<INode, Iterable<ILeafNode>> _function =
       new Function1<INode, Iterable<ILeafNode>>() {
         @Override
         public Iterable<ILeafNode> apply(final INode it) {
           return it.getLeafNodes();
         }
       };
   List<Iterable<ILeafNode>> _map =
       ListExtensions.<INode, Iterable<ILeafNode>>map(_findNodesForFeature, _function);
   Iterable<ILeafNode> _flatten = Iterables.<ILeafNode>concat(_map);
   final Function1<ILeafNode, Boolean> _function_1 =
       new Function1<ILeafNode, Boolean>() {
         @Override
         public Boolean apply(final ILeafNode it) {
           boolean _isHidden = it.isHidden();
           return Boolean.valueOf((!_isHidden));
         }
       };
   Iterable<ILeafNode> _filter = IterableExtensions.<ILeafNode>filter(_flatten, _function_1);
   ILeafNode _head = IterableExtensions.<ILeafNode>head(_filter);
   ASTNode _aSTNode = this.xtextFile.getASTNode(_head);
   return _aSTNode.getPsi();
 }
 public TextRegion getImportRegion(XtextResource xtextResource) {
   XPackage xPackage = getXPackage(xtextResource);
   if (xPackage != null) {
     List<INode> xPackageNodes =
         NodeModelUtils.findNodesForFeature(xPackage, XcorePackage.Literals.XNAMED_ELEMENT__NAME);
     int begin;
     int size = xPackageNodes.size();
     if (size == 0) {
       begin = 0;
     } else {
       INode lastNode = xPackageNodes.get(size - 1);
       begin = lastNode.getOffset() + lastNode.getLength();
     }
     int end;
     EList<XAnnotationDirective> annotationDirectives = xPackage.getAnnotationDirectives();
     if (!annotationDirectives.isEmpty()) {
       ICompositeNode node = NodeModelUtils.getNode(annotationDirectives.get(0));
       end = node.getTotalOffset();
     } else {
       EList<XClassifier> classifiers = xPackage.getClassifiers();
       if (!classifiers.isEmpty()) {
         ICompositeNode node = NodeModelUtils.getNode(classifiers.get(0));
         end = node.getTotalOffset();
       } else {
         end = xtextResource.getParseResult().getRootNode().getTotalEndOffset();
       }
     }
     return new TextRegion(begin, end - begin);
   } else {
     return null;
   }
 }
예제 #4
0
 /** @since 2.3 */
 protected void validateReferencedMetamodel(ReferencedMetamodel ref) {
   if (ref.getEPackage() != null && !ref.getEPackage().eIsProxy()) return;
   EReference eref = XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE;
   List<INode> nodes = NodeModelUtils.findNodesForFeature(ref, eref);
   String refName = nodes.isEmpty() ? "(unknown)" : NodeModelUtils.getTokenText(nodes.get(0));
   String grammarName = GrammarUtil.getGrammar(ref).getName();
   String msg = "The EPackage " + refName + " in grammar " + grammarName + " could not be found. ";
   msg += "You might want to register that EPackage in your workflow file.";
   throw new IllegalStateException(msg);
 }
  @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;
  }
예제 #6
0
 @Override
 protected ITextRegion getLocationOfCrossReference(
     EObject owner, EReference reference, int indexInList, boolean isSignificant) {
   if (owner instanceof XMemberFeatureCall
       && reference == XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE
       && ((XMemberFeatureCall) owner).isTypeLiteral()) {
     List<INode> featureNodes = NodeModelUtils.findNodesForFeature(owner, reference);
     ITextRegion result = ITextRegion.EMPTY_REGION;
     if (!featureNodes.isEmpty()) {
       INode featureNode = featureNodes.get(0);
       result = result.merge(toZeroBasedRegion(featureNode.getTextRegionWithLineInformation()));
       List<INode> targetNodes =
           NodeModelUtils.findNodesForFeature(
               owner, XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET);
       if (!targetNodes.isEmpty()) {
         INode targetNode = targetNodes.get(0);
         result = result.merge(toZeroBasedRegion(targetNode.getTextRegionWithLineInformation()));
       }
       return result;
     }
   }
   return super.getLocationOfCrossReference(owner, reference, indexInList, isSignificant);
 }
예제 #7
0
 protected ICrossReferenceDescription getCrossReferenceDescription() {
   ICrossReferenceDescription _xblockexpression = null;
   {
     ASTNode _node = this.myElement.getNode();
     IElementType _elementType = _node.getElementType();
     EObject _grammarElement = ((IGrammarAwareElementType) _elementType).getGrammarElement();
     final CrossReference crossReference = ((CrossReference) _grammarElement);
     BaseXtextFile _xtextFile = this.myElement.getXtextFile();
     ASTNode _node_1 = this.myElement.getNode();
     final INode node = _xtextFile.getINode(_node_1);
     final EObject context = NodeModelUtils.findActualSemanticObjectFor(node);
     final EReference reference = GrammarUtil.getReference(crossReference);
     List<INode> _findNodesForFeature = NodeModelUtils.findNodesForFeature(context, reference);
     Iterable<Pair<Integer, INode>> _indexed =
         IterableExtensions.<INode>indexed(_findNodesForFeature);
     final Function1<Pair<Integer, INode>, Boolean> _function =
         new Function1<Pair<Integer, INode>, Boolean>() {
           @Override
           public Boolean apply(final Pair<Integer, INode> it) {
             boolean _and = false;
             INode _value = it.getValue();
             int _totalOffset = _value.getTotalOffset();
             int _totalOffset_1 = node.getTotalOffset();
             boolean _lessEqualsThan = (_totalOffset <= _totalOffset_1);
             if (!_lessEqualsThan) {
               _and = false;
             } else {
               INode _value_1 = it.getValue();
               int _totalEndOffset = _value_1.getTotalEndOffset();
               int _totalEndOffset_1 = node.getTotalEndOffset();
               boolean _greaterEqualsThan = (_totalEndOffset >= _totalEndOffset_1);
               _and = _greaterEqualsThan;
             }
             return Boolean.valueOf(_and);
           }
         };
     Pair<Integer, INode> _findFirst =
         IterableExtensions.<Pair<Integer, INode>>findFirst(_indexed, _function);
     Integer _key = null;
     if (_findFirst != null) {
       _key = _findFirst.getKey();
     }
     final Integer index = _key;
     _xblockexpression = this.crossReferenceDescriptionProvider.get(context, reference, index);
   }
   return _xblockexpression;
 }
예제 #8
0
 private void addTypeCastToImplicitReceiver(
     XFeatureCall featureCall, IModificationContext context, JvmType declaringType)
     throws BadLocationException {
   String receiver;
   if (featureCall.getImplicitReceiver() instanceof XAbstractFeatureCall)
     receiver =
         ((XAbstractFeatureCall) featureCall.getImplicitReceiver()).getFeature().getSimpleName();
   else return;
   List<INode> nodes =
       NodeModelUtils.findNodesForFeature(
           featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE);
   if (nodes.isEmpty()) return;
   INode firstNode = IterableExtensions.head(nodes);
   int offset = firstNode.getOffset();
   ReplacingAppendable appendable =
       appendableFactory.create(
           context.getXtextDocument(), (XtextResource) featureCall.eResource(), offset, 0);
   appendable.append("(");
   appendable.append(receiver);
   appendable.append(" as ");
   appendable.append(declaringType);
   appendable.append(").");
   appendable.commitChanges();
 }
예제 #9
0
 protected String computeFieldName(XtendField field, JvmGenericType declaringType) {
   if (field.getName() != null) return field.getName();
   JvmTypeReference type = field.getType();
   String name = null;
   if (type != null) {
     while (type instanceof JvmGenericArrayTypeReference) {
       type = ((JvmGenericArrayTypeReference) type).getComponentType();
     }
     if (type instanceof JvmParameterizedTypeReference) {
       List<INode> nodes =
           NodeModelUtils.findNodesForFeature(
               type, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
       if (!nodes.isEmpty()) {
         String typeName = nodes.get(0).getText().trim();
         int lastDot = typeName.lastIndexOf('.');
         if (lastDot != -1) {
           typeName = typeName.substring(lastDot + 1);
         }
         name = "_" + Strings.toFirstLower(typeName);
       }
     }
   }
   return name;
 }