private String getMetamodelNsURI(ILeafNode text) {
   try {
     return (String)
         valueConverterService.toValue(
             text.getText(), getLinkingHelper().getRuleNameFrom(text.getGrammarElement()), text);
   } catch (ValueConverterException e) {
     LOG.debug("Exception on leaf '" + text.getText() + "'", e);
     return null;
   }
 }
Ejemplo n.º 2
0
 public @Nullable String getText(@Nullable INode node) {
   if (node == null) {
     return null;
   }
   ILeafNode leafNode = ElementUtil.getLeafNode(node);
   if (leafNode == null) {
     return null;
   }
   EObject grammarElement = leafNode.getGrammarElement();
   if (grammarElement == null) {
     return null;
   }
   String ruleName = getLinkingHelper().getRuleNameFrom(grammarElement);
   return (String) valueConverterService.toValue(leafNode.getText(), ruleName, leafNode);
 }
  public String getCrossRefText(
      EObject owner,
      CrossReference crossref,
      EObject target,
      RefTextEvaluator refTextEvaluator,
      ITextRegion linkTextRegion,
      StatusWrapper status) {
    try {
      final EReference ref = GrammarUtil.getReference(crossref, owner.eClass());
      final IScope scope = scopeProvider.getScope(owner, ref);
      if (scope == null) {
        throw new IllegalStateException("Could not create scope for the given cross reference.");
      }
      String ruleName = linkingHelper.getRuleNameFrom(crossref);

      Iterable<IEObjectDescription> descriptionsForCrossRef = scope.getElements(target);
      String bestRefText = null;
      for (IEObjectDescription desc : descriptionsForCrossRef) {
        try {
          String unconvertedRefText = qualifiedNameConverter.toString(desc.getName());
          String convertedRefText = valueConverter.toString(unconvertedRefText, ruleName);
          if (refTextEvaluator.isValid(convertedRefText)
              && (bestRefText == null
                  || refTextEvaluator.isBetterThan(convertedRefText, bestRefText)))
            bestRefText = convertedRefText;
        } catch (ValueConverterException e) {
          status.add(
              RefactoringStatus.WARNING,
              "Missconfigured language: New reference text has invalid syntax.",
              owner,
              linkTextRegion);
        }
      }
      if (bestRefText == null)
        status.add(
            RefactoringStatus.ERROR,
            "Refactoring introduces a name conflict.",
            owner,
            linkTextRegion);
      return bestRefText;

    } catch (Exception exc) {
      status.add(ERROR, exc.getMessage(), owner, linkTextRegion);
      return null;
    }
  }