mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 02:36:01 +02:00
2005-01-29 Alain Magloire
Copy the spaces and Newlines. * model/org/eclipse/cdt/internal/core/model/CopylementsOperation.java * model/org/eclipse/cdt/internal/core/model/DeleteElementsOperation.java
This commit is contained in:
parent
a865ae80b6
commit
958d78914a
3 changed files with 56 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
2005-01-29 Alain Magloire
|
||||
Copy the spaces and Newlines.
|
||||
* model/org/eclipse/cdt/internal/core/model/CopylementsOperation.java
|
||||
* model/org/eclipse/cdt/internal/core/model/DeleteElementsOperation.java
|
||||
|
||||
2005-01-28 Alain Magloire
|
||||
Operation on translationUnit
|
||||
* model/org/eclipse/cdt/core/model/ITranslationUnit.java
|
||||
|
|
|
@ -5,10 +5,12 @@ package org.eclipse.cdt.internal.core.model;
|
|||
* All Rights Reserved.
|
||||
*/
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IBuffer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICModelStatus;
|
||||
import org.eclipse.cdt.core.model.ICModelStatusConstants;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
|
@ -97,10 +99,35 @@ public class CopyElementsOperation extends MultiOperation {
|
|||
*/
|
||||
private String getSourceFor(ICElement element) {
|
||||
if (element instanceof ISourceReference) {
|
||||
ISourceReference source = (ISourceReference)element;
|
||||
// TODO: remove this hack when we have ASTRewrite and doit properly
|
||||
try {
|
||||
ISourceReference source = (ISourceReference)element;
|
||||
ISourceRange range = source.getSourceRange();
|
||||
String contents = source.getSource();
|
||||
// TODO: remove this hack when we have ASTRewrite and doit properly
|
||||
StringBuffer sb = new StringBuffer(contents);
|
||||
// Copy the extra spaces and newLines like it is part of
|
||||
// the element. Note: the DeleteElementAction is doing the same.
|
||||
IBuffer buffer = getSourceTranslationUnit(element).getBuffer();
|
||||
boolean newLineFound = false;
|
||||
for (int offset = range.getStartPos() + range.getLength();;++offset) {
|
||||
try {
|
||||
char c = buffer.getChar(offset);
|
||||
// TODO:Bug in the Parser, it does not give the semicolon
|
||||
if (c == ';') {
|
||||
sb.append(c) ;
|
||||
} else if (c == '\r' || c == '\n') {
|
||||
newLineFound = true;
|
||||
sb.append(c) ;
|
||||
} else if (!newLineFound && c == ' ') { // Do not include the spaces after the newline
|
||||
sb.append(c) ;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
contents = sb.toString();
|
||||
if (! contents.endsWith(Util.LINE_SEPARATOR)) {
|
||||
contents += Util.LINE_SEPARATOR;
|
||||
}
|
||||
|
|
|
@ -114,13 +114,34 @@ public class DeleteElementsOperation extends MultiOperation {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated marked deprecated to suppress JDOM-related deprecation warnings
|
||||
* @deprecated marked deprecated, future to use ASTRewrite
|
||||
*/
|
||||
private void replaceElementInBuffer(IBuffer buffer, ICElement elementToRemove, String cuName) throws CModelException {
|
||||
if (elementToRemove instanceof ISourceReference) {
|
||||
ISourceRange range = ((ISourceReference)elementToRemove).getSourceRange();
|
||||
int startPosition = range.getStartPos();
|
||||
int length = range.getLength();
|
||||
// Copy the extra spaces and newLines like it is part of
|
||||
// the element. Note: the CopyElementAction is doing the same.
|
||||
boolean newLineFound = false;
|
||||
for (int offset = range.getStartPos() + range.getLength();;++offset) {
|
||||
try {
|
||||
char c = buffer.getChar(offset);
|
||||
// TODO:Bug in the Parser, it does not give the semicolon
|
||||
if (c == ';') {
|
||||
length++;
|
||||
} else if (c == '\r' || c == '\n') {
|
||||
newLineFound = true;
|
||||
length++;
|
||||
} else if (!newLineFound && c == ' ') { // Do not include the spaces after the newline
|
||||
length++ ;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
buffer.replace(startPosition, length, CharOperation.NO_CHAR);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue