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); fire(null, eventType);
} }
public void fireShift(int offset, int size, int lines) { public void fireShift(ICElement element, int offset, int size, int lines) {
ICElementDelta delta = new CShiftData(offset, size, lines); ICElementDelta delta = new CShiftData(element, offset, size, lines);
fire(delta, ElementChangedEvent.POST_SHIFT); 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; package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.ICElement; 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 * In this case, no delta for specific element passed
* Instead we'll notify Outline about offsets change. * Instead we'll notify Outline about offsets change.
*
* @author Oleg Krasilnikov
*/ */
public class CShiftData implements ICElementDelta { public class CShiftData implements ICElementDelta {
public int fOffset; private final ICElement element;
public int fSize; private final int offset;
public int fLines; private final int size;
private final int lines;
public CShiftData(int offset, int size, int lines) { public CShiftData(ICElement element, int offset, int size, int lines) {
fOffset = offset; this.element = element;
fSize = size; this.offset = offset;
fLines = lines; this.size = size;
this.lines = lines;
}
public int getOffset() {
return offset;
}
public int getSize() {
return size;
}
public int getLines() {
return lines;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -48,7 +71,7 @@ public class CShiftData implements ICElementDelta {
* @see org.eclipse.cdt.core.model.ICElementDelta#getElement() * @see org.eclipse.cdt.core.model.ICElementDelta#getElement()
*/ */
public ICElement getElement() { public ICElement getElement() {
return null; return element;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -94,6 +117,6 @@ public class CShiftData implements ICElementDelta {
} }
public String toString() { 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.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.progress.DeferredTreeContentManager; import org.eclipse.ui.progress.DeferredTreeContentManager;
@ -144,17 +143,17 @@ public class CContentOutlinerProvider extends BaseCElementContentProvider {
int endOffset = src.getStartPos() + src.getLength(); int endOffset = src.getStartPos() + src.getLength();
// code BELOW this element changed - do nothing ! // 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 // code ABOVE this element changed - modify offset
sm.setIdPos(src.getIdStartPos() + sdata.fSize,src.getIdLength()); sm.setIdPos(src.getIdStartPos() + sdata.getSize(), src.getIdLength());
sm.setPos(src.getStartPos() + sdata.fSize, src.getLength()); sm.setPos(src.getStartPos() + sdata.getSize(), src.getLength());
sm.setLines(src.getStartLine() + sdata.fLines, src.getEndLine() + sdata.fLines); sm.setLines(src.getStartLine() + sdata.getLines(), src.getEndLine() + sdata.getLines());
} else { } else {
// code INSIDE of this element changed - modify length // code INSIDE of this element changed - modify length
sm.setPos(src.getStartPos(), src.getLength() + sdata.fSize); sm.setPos(src.getStartPos(), src.getLength() + sdata.getSize());
sm.setLines(src.getStartLine(), src.getEndLine() + sdata.fLines); sm.setLines(src.getStartLine(), src.getEndLine() + sdata.getLines());
} }
} }
} catch (CModelException e) {} } catch (CModelException e) {}

View file

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