1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixed NPEs that occured because CShiftData didn't capture the element. It now passes on the WorkingCopy from the CReconcilingStrategy.

This commit is contained in:
Doug Schaefer 2006-01-06 18:12:26 +00:00
parent 3f96a4af6c
commit 0c006716b3
4 changed files with 46 additions and 24 deletions

View file

@ -797,8 +797,8 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
fire(null, eventType);
}
public void fireShift(int offset, int size, int lines) {
ICElementDelta delta = new CShiftData(offset, size, lines);
public void fireShift(ICElement element, int offset, int size, int lines) {
ICElementDelta delta = new CShiftData(element, offset, size, lines);
fire(delta, ElementChangedEvent.POST_SHIFT);
}

View file

@ -1,6 +1,13 @@
/**
/*******************************************************************************
* Copyright (c) 2006 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*/
* Contributors:
* Intel Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.ICElement;
@ -10,17 +17,33 @@ import org.eclipse.core.resources.IResourceDelta;
/**
* In this case, no delta for specific element passed
* Instead we'll notify Outline about offsets change.
*
* @author Oleg Krasilnikov
*/
public class CShiftData implements ICElementDelta {
public int fOffset;
public int fSize;
public int fLines;
private final ICElement element;
private final int offset;
private final int size;
private final int lines;
public CShiftData(int offset, int size, int lines) {
fOffset = offset;
fSize = size;
fLines = lines;
public CShiftData(ICElement element, int offset, int size, int lines) {
this.element = element;
this.offset = offset;
this.size = size;
this.lines = lines;
}
public int getOffset() {
return offset;
}
public int getSize() {
return size;
}
public int getLines() {
return lines;
}
/* (non-Javadoc)
@ -48,7 +71,7 @@ public class CShiftData implements ICElementDelta {
* @see org.eclipse.cdt.core.model.ICElementDelta#getElement()
*/
public ICElement getElement() {
return null;
return element;
}
/* (non-Javadoc)
@ -94,6 +117,6 @@ public class CShiftData implements ICElementDelta {
}
public String toString() {
return ("CShiftData: offset=" + fOffset + ", size=" + fSize + ", lines=" + fLines);
return ("CShiftData: offset=" + offset + ", size=" + size + ", lines=" + lines);
}
}

View file

@ -34,7 +34,6 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.progress.DeferredTreeContentManager;
@ -144,17 +143,17 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
int endOffset = src.getStartPos() + src.getLength();
// code BELOW this element changed - do nothing !
if (sdata.fOffset > endOffset) { continue; }
if (sdata.getOffset() > endOffset) { continue; }
if (sdata.fOffset < src.getStartPos()) {
if (sdata.getOffset() < src.getStartPos()) {
// code ABOVE this element changed - modify offset
sm.setIdPos(src.getIdStartPos() + sdata.fSize,src.getIdLength());
sm.setPos(src.getStartPos() + sdata.fSize, src.getLength());
sm.setLines(src.getStartLine() + sdata.fLines, src.getEndLine() + sdata.fLines);
sm.setIdPos(src.getIdStartPos() + sdata.getSize(), src.getIdLength());
sm.setPos(src.getStartPos() + sdata.getSize(), src.getLength());
sm.setLines(src.getStartLine() + sdata.getLines(), src.getEndLine() + sdata.getLines());
} else {
// code INSIDE of this element changed - modify length
sm.setPos(src.getStartPos(), src.getLength() + sdata.fSize);
sm.setLines(src.getStartLine(), src.getEndLine() + sdata.fLines);
sm.setPos(src.getStartPos(), src.getLength() + sdata.getSize());
sm.setLines(src.getStartLine(), src.getEndLine() + sdata.getLines());
}
}
} catch (CModelException e) {}

View file

@ -85,7 +85,7 @@ public class CReconcilingStrategy implements IReconcilingStrategy {
if (dirtyRegion.getType().charAt(2) == 'i') { // insert operation
s = dirtyRegion.getText();
if (!CWordFinder.hasCBraces(s)) {
CModelManager.getDefault().fireShift(dOff, dLen, CWordFinder.countLFs(s));
CModelManager.getDefault().fireShift(tu, dOff, dLen, CWordFinder.countLFs(s));
needReconcile = false;
}
} else { // remove operation
@ -93,7 +93,7 @@ public class CReconcilingStrategy implements IReconcilingStrategy {
if (txt != null && (txt.length() == doc.getLength() + dLen)) {
s = txt.substring(dOff, dOff + dLen);
if (!CWordFinder.hasCBraces(s)) {
CModelManager.getDefault().fireShift(dOff, -dLen, -CWordFinder.countLFs(s));
CModelManager.getDefault().fireShift(tu, dOff, -dLen, -CWordFinder.countLFs(s));
needReconcile = false;
}
}