KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > dom > rewrite > SourceModifier


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core.dom.rewrite;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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 JavaDoc destinationIndent;
24     private final int sourceIndentLevel;
25     private final int tabWidth;
26     private final int indentWidth;
27         
28     public SourceModifier(int sourceIndentLevel, String JavaDoc 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         // We are state less
37
return this;
38     }
39     
40     public ReplaceEdit[] getModifications(String JavaDoc source) {
41         List JavaDoc result= new ArrayList JavaDoc();
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