1 package com.github.javaparser.printer.lexicalpreservation; 2 3 import com.github.javaparser.printer.concretesyntaxmodel.CsmElement; 4 import com.github.javaparser.printer.concretesyntaxmodel.CsmIndent; 5 import com.github.javaparser.printer.concretesyntaxmodel.CsmToken; 6 import com.github.javaparser.printer.concretesyntaxmodel.CsmUnindent; 7 8 public class Added implements DifferenceElement { 9 private final CsmElement element; 10 Added(CsmElement element)11 Added(CsmElement element) { 12 this.element = element; 13 } 14 15 @Override toString()16 public String toString() { 17 return "Added{" + element + '}'; 18 } 19 20 @Override equals(Object o)21 public boolean equals(Object o) { 22 if (this == o) return true; 23 if (o == null || getClass() != o.getClass()) return false; 24 25 Added added = (Added) o; 26 27 return element.equals(added.element); 28 } 29 30 @Override hashCode()31 public int hashCode() { 32 return element.hashCode(); 33 } 34 35 @Override getElement()36 public CsmElement getElement() { 37 return element; 38 } 39 40 @Override isAdded()41 public boolean isAdded() { 42 return true; 43 } 44 45 @Override isRemoved()46 public boolean isRemoved() { 47 return false; 48 } 49 isIndent()50 public boolean isIndent() { return element instanceof CsmIndent; } 51 isUnindent()52 public boolean isUnindent() { return element instanceof CsmUnindent; } 53 toTextElement()54 public TextElement toTextElement() { 55 if (element instanceof LexicalDifferenceCalculator.CsmChild) { 56 return new ChildTextElement(((LexicalDifferenceCalculator.CsmChild) element).getChild()); 57 } else if (element instanceof CsmToken) { 58 return new TokenTextElement(((CsmToken) element).getTokenType(), ((CsmToken) element).getContent(null)); 59 } else { 60 throw new UnsupportedOperationException(element.getClass().getSimpleName()); 61 } 62 } 63 } 64