Пример #1
0
 @Override
 public String toString() {
   List<ITextSegment> list = toTokenAndGapList();
   if (list.isEmpty()) return "(empty)";
   Multimap<IHiddenRegion, IEObjectRegion> hiddens = LinkedListMultimap.create();
   List<String> errors = Lists.newArrayList();
   ITextRegionAccess access = list.get(0).getTextRegionAccess();
   TreeIterator<EObject> all = EcoreUtil2.eAll(access.regionForRootEObject().getSemanticElement());
   while (all.hasNext()) {
     EObject element = all.next();
     IEObjectRegion obj = access.regionForEObject(element);
     if (obj == null) continue;
     IHiddenRegion previous = obj.getPreviousHiddenRegion();
     IHiddenRegion next = obj.getNextHiddenRegion();
     if (previous == null)
       errors.add("ERROR: " + EmfFormatter.objPath(element) + " has no leading HiddenRegion.");
     else hiddens.put(previous, obj);
     if (previous != next) {
       if (next == null)
         errors.add("ERROR: " + EmfFormatter.objPath(element) + " has no trailing HiddenRegion.");
       else hiddens.put(next, obj);
     }
   }
   TextRegionListToString result = new TextRegionListToString();
   if (!hideColumnExplanation) {
     result.add("Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement", false);
     result.add("Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion", false);
     result.add("", false);
   }
   for (String error : errors) result.add(error, false);
   int indentation = 0;
   for (ITextSegment region : list) {
     List<IEObjectRegion> previous = Lists.newArrayList();
     List<IEObjectRegion> next = Lists.newArrayList();
     List<String> middle = Lists.newArrayList(toString(region));
     if (region instanceof IHiddenRegion) {
       Collection<IEObjectRegion> found = hiddens.get((IHiddenRegion) region);
       for (IEObjectRegion obj : found) {
         boolean p = obj.getNextHiddenRegion().equals(region);
         boolean n = obj.getPreviousHiddenRegion().equals(region);
         if (p && n) middle.add(EMPTY_TITLE + "Semantic " + toString(obj));
         else if (p) previous.add(obj);
         else if (n) next.add(obj);
       }
       Collections.sort(previous, AstRegionComparator.CHILDREN_FIRST);
       Collections.sort(next, AstRegionComparator.CONTAINER_FIRST);
     }
     for (IEObjectRegion obj : previous) {
       indentation--;
       result.add(indent(indentation) + EOBJECT_END_PADDED + toString(obj));
     }
     String indent = indent(indentation);
     result.add(region, indent + Joiner.on("\n").join(middle).replace("\n", "\n" + indent));
     for (IEObjectRegion obj : next) {
       result.add(indent(indentation) + EOBJECT_BEGIN_PADDED + toString(obj));
       indentation++;
     }
   }
   return result.toString();
 }
Пример #2
0
 public TextRegionAccessToString withRegionAccess(ITextRegionAccess access) {
   this.origin = access.regionForRootEObject();
   this.hightlightOrigin = false;
   return this;
 }