import net.sourceforge.phpdt.core.ToolFactory;
import net.sourceforge.phpdt.core.formatter.DefaultCodeFormatterConstants;
-import net.sourceforge.phpdt.internal.corext.Assert;
+//incastrix
+//import net.sourceforge.phpdt.internal.corext.Assert;
+//import org.eclipse.core.runtime.Assert;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import org.eclipse.core.runtime.Preferences;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.Position;
+//import org.eclipse.jface.text.BadLocationException;
+//import org.eclipse.jface.text.BadPositionCategoryException;
+//import org.eclipse.jface.text.DefaultPositionUpdater;
+//import org.eclipse.jface.text.Document;
+//import org.eclipse.jface.text.Position;
//import org.eclipse.text.edits.DeleteEdit;
//import org.eclipse.text.edits.InsertEdit;
//import org.eclipse.text.edits.MultiTextEdit;
//import org.eclipse.text.edits.ReplaceEdit;
-import org.eclipse.text.edits.TextEdit;
+//import org.eclipse.text.edits.TextEdit;
public class CodeFormatterUtil {
* If the positions are not inside the string, a
* IllegalArgumentException is thrown.
*/
- public static String evaluateFormatterEdit(String string, TextEdit edit,
- Position[] positions) {
- try {
- Document doc = createDocument(string, positions);
- edit.apply(doc, 0);
- if (positions != null) {
- for (int i = 0; i < positions.length; i++) {
- Assert.isTrue(!positions[i].isDeleted,
- "Position got deleted"); //$NON-NLS-1$
- }
- }
- return doc.get();
- } catch (BadLocationException e) {
- PHPeclipsePlugin.log(e); // bug in the formatter
- Assert
- .isTrue(
- false,
- "Fromatter created edits with wrong positions: " + e.getMessage()); //$NON-NLS-1$
- }
- return null;
- }
+// public static String evaluateFormatterEdit(String string, TextEdit edit,
+// Position[] positions) {
+// try {
+// Document doc = createDocument(string, positions);
+// edit.apply(doc, 0);
+// if (positions != null) {
+// for (int i = 0; i < positions.length; i++) {
+// Assert.isTrue(!positions[i].isDeleted,
+// "Position got deleted"); //$NON-NLS-1$
+// }
+// }
+// return doc.get();
+// } catch (BadLocationException e) {
+// PHPeclipsePlugin.log(e); // bug in the formatter
+// Assert
+// .isTrue(
+// false,
+// "Fromatter created edits with wrong positions: " + e.getMessage()); //$NON-NLS-1$
+// }
+// return null;
+// }
/**
* Creates edits that describe how to format the given string. Returns
// return newEdit;
// }
- private static Document createDocument(String string, Position[] positions)
- throws IllegalArgumentException {
- Document doc = new Document(string);
- try {
- if (positions != null) {
- final String POS_CATEGORY = "myCategory"; //$NON-NLS-1$
-
- doc.addPositionCategory(POS_CATEGORY);
- doc
- .addPositionUpdater(new DefaultPositionUpdater(
- POS_CATEGORY) {
- protected boolean notDeleted() {
- if (fOffset < fPosition.offset
- && (fPosition.offset + fPosition.length < fOffset
- + fLength)) {
- fPosition.offset = fOffset + fLength; // deleted
- // positions:
- // set
- // to
- // end
- // of
- // remove
- return false;
- }
- return true;
- }
- });
- for (int i = 0; i < positions.length; i++) {
- try {
- doc.addPosition(POS_CATEGORY, positions[i]);
- } catch (BadLocationException e) {
- throw new IllegalArgumentException(
- "Position outside of string. offset: " + positions[i].offset + ", length: " + positions[i].length + ", string size: " + string.length()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
- }
- }
- }
- } catch (BadPositionCategoryException cannotHappen) {
- // can not happen: category is correctly set up
- }
- return doc;
- }
+// private static Document createDocument(String string, Position[] positions)
+// throws IllegalArgumentException {
+// Document doc = new Document(string);
+// try {
+// if (positions != null) {
+// final String POS_CATEGORY = "myCategory"; //$NON-NLS-1$
+//
+// doc.addPositionCategory(POS_CATEGORY);
+// doc
+// .addPositionUpdater(new DefaultPositionUpdater(
+// POS_CATEGORY) {
+// protected boolean notDeleted() {
+// if (fOffset < fPosition.offset
+// && (fPosition.offset + fPosition.length < fOffset
+// + fLength)) {
+// fPosition.offset = fOffset + fLength; // deleted
+// // positions:
+// // set
+// // to
+// // end
+// // of
+// // remove
+// return false;
+// }
+// return true;
+// }
+// });
+// for (int i = 0; i < positions.length; i++) {
+// try {
+// doc.addPosition(POS_CATEGORY, positions[i]);
+// } catch (BadLocationException e) {
+// throw new IllegalArgumentException(
+// "Position outside of string. offset: " + positions[i].offset + ", length: " + positions[i].length + ", string size: " + string.length()); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+// }
+// }
+// }
+// } catch (BadPositionCategoryException cannotHappen) {
+// // can not happen: category is correctly set up
+// }
+// return doc;
+// }
}