1 11 package org.eclipse.jdt.internal.core.dom.rewrite; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.jdt.core.formatter.IndentManipulation; 17 import org.eclipse.text.edits.ISourceModifier; 18 import org.eclipse.text.edits.ReplaceEdit; 19 20 21 public class SourceModifier implements ISourceModifier { 22 23 private final String destinationIndent; 24 private final int sourceIndentLevel; 25 private final int tabWidth; 26 private final int indentWidth; 27 28 public SourceModifier(int sourceIndentLevel, String destinationIndent, int tabWidth, int indentWidth) { 29 this.destinationIndent= destinationIndent; 30 this.sourceIndentLevel= sourceIndentLevel; 31 this.tabWidth= tabWidth; 32 this.indentWidth= indentWidth; 33 } 34 35 public ISourceModifier copy() { 36 return this; 38 } 39 40 public ReplaceEdit[] getModifications(String source) { 41 List result= new ArrayList (); 42 int destIndentLevel= IndentManipulation.measureIndentUnits(this.destinationIndent, this.tabWidth, this.indentWidth); 43 if (destIndentLevel == this.sourceIndentLevel) { 44 return (ReplaceEdit[])result.toArray(new ReplaceEdit[result.size()]); 45 } 46 return IndentManipulation.getChangeIndentEdits(source, this.sourceIndentLevel, this.tabWidth, this.indentWidth, this.destinationIndent); 47 } 48 } 49 | Popular Tags |