1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Fix for 227463: Syntax coloring error on insertion/deletion

This commit is contained in:
Anton Leherbauer 2008-04-21 13:33:01 +00:00
parent 390aa48830
commit 835e96be68
5 changed files with 105 additions and 59 deletions

View file

@ -72,6 +72,7 @@ import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICPartitions; import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IBufferFactory;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.ui.text.IProblemRequestorExtension; import org.eclipse.cdt.internal.ui.text.IProblemRequestorExtension;
import org.eclipse.cdt.internal.ui.text.spelling.CoreSpellingProblem; import org.eclipse.cdt.internal.ui.text.spelling.CoreSpellingProblem;
@ -787,12 +788,10 @@ public class CDocumentProvider extends TextFileDocumentProvider {
} }
if (element == null) { if (element == null) {
// not in a source folder? // not in a source folder?
final IPath location= file.getLocation();
if (location != null) {
ICProject cproject= CoreModel.getDefault().create(file.getProject()); ICProject cproject= CoreModel.getDefault().create(file.getProject());
if (cproject != null) { if (cproject != null) {
return CoreModel.getDefault().createTranslationUnitFrom(cproject, location); String contentTypeId= CoreModel.getRegistedContentTypeId(file.getProject(), file.getName());
} return new TranslationUnit(cproject, file, contentTypeId);
} }
} }
return null; return null;

View file

@ -195,7 +195,6 @@ import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction;
import org.eclipse.cdt.internal.ui.actions.GotoNextBookmarkAction; import org.eclipse.cdt.internal.ui.actions.GotoNextBookmarkAction;
import org.eclipse.cdt.internal.ui.actions.IndentAction; import org.eclipse.cdt.internal.ui.actions.IndentAction;
import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction; import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction;
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
import org.eclipse.cdt.internal.ui.dnd.TextEditorDropAdapter; import org.eclipse.cdt.internal.ui.dnd.TextEditorDropAdapter;
import org.eclipse.cdt.internal.ui.dnd.TextViewerDragAdapter; import org.eclipse.cdt.internal.ui.dnd.TextViewerDragAdapter;
import org.eclipse.cdt.internal.ui.search.OccurrencesFinder; import org.eclipse.cdt.internal.ui.search.OccurrencesFinder;
@ -1405,13 +1404,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
} }
else if (required == IShowInSource.class) { else if (required == IShowInSource.class) {
ICElement ce= null; ICElement ce= null;
try { ce= getElementAt(getSourceViewer().getSelectedRange().x, false);
ce= SelectionConverter.getElementAtOffset(this);
if (ce instanceof ITranslationUnit) { if (ce instanceof ITranslationUnit) {
ce = null; ce = null;
} }
} catch (CModelException ex) {
}
final ISelection selection= ce != null ? new StructuredSelection(ce) : null; final ISelection selection= ce != null ? new StructuredSelection(ce) : null;
return new IShowInSource() { return new IShowInSource() {
public ShowInContext getShowInContext() { public ShowInContext getShowInContext() {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2007 QNX Software Systems and others. * Copyright (c) 2002, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -12,14 +12,18 @@
package org.eclipse.cdt.internal.ui.editor; package org.eclipse.cdt.internal.ui.editor;
import java.net.URI;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.IOpenable; import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.model.IBufferFactory; import org.eclipse.cdt.internal.core.model.IBufferFactory;
@ -55,6 +59,16 @@ public class CustomBufferFactory implements IBufferFactory {
return new DocumentAdapter(owner, location); return new DocumentAdapter(owner, location);
} }
// URI
URI locationUri= original.getLocationURI();
if (locationUri != null) {
try {
return new DocumentAdapter(owner, locationUri);
} catch (CoreException exc) {
CUIPlugin.log(exc);
}
}
} }
return DocumentAdapter.NULL; return DocumentAdapter.NULL;
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2007 IBM Corporation and others. * Copyright (c) 2002, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -12,25 +12,23 @@
package org.eclipse.cdt.internal.ui.editor; package org.eclipse.cdt.internal.ui.editor;
import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.core.model.BufferChangedEvent;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.IBufferChangedListener;
import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.filebuffers.FileBuffers; import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.ITextFileBuffer; import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager; import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.filebuffers.LocationKind; import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourceAttributes; import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -42,9 +40,15 @@ import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.jface.text.ISynchronizable; import org.eclipse.jface.text.ISynchronizable;
import org.eclipse.core.runtime.Assert;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.model.BufferChangedEvent;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.IBufferChangedListener;
import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.ui.CUIPlugin;
/** /**
* Adapts <code>IDocument</code> to <code>IBuffer</code>. Uses the * Adapts <code>IDocument</code> to <code>IBuffer</code>. Uses the
@ -186,6 +190,8 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
final private IPath fLocation; final private IPath fLocation;
final private LocationKind fLocationKind; final private LocationKind fLocationKind;
private IFileStore fFileStore;
public DocumentAdapter(IOpenable owner, IFile file) { public DocumentAdapter(IOpenable owner, IFile file) {
fOwner= owner; fOwner= owner;
@ -204,18 +210,36 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
initialize(); initialize();
} }
public DocumentAdapter(IOpenable owner, URI locationUri) throws CoreException {
fOwner= owner;
fFileStore= EFS.getStore(locationUri);
fLocation= null;
fLocationKind= null;
initialize();
}
private void initialize() { private void initialize() {
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
try { try {
if (fLocation != null) {
manager.connect(fLocation, fLocationKind, new NullProgressMonitor()); manager.connect(fLocation, fLocationKind, new NullProgressMonitor());
fTextFileBuffer= manager.getTextFileBuffer(fLocation, fLocationKind); fTextFileBuffer= manager.getTextFileBuffer(fLocation, fLocationKind);
} else {
manager.connectFileStore(fFileStore, new NullProgressMonitor());
fTextFileBuffer= manager.getFileStoreTextFileBuffer(fFileStore);
}
fDocument= fTextFileBuffer.getDocument(); fDocument= fTextFileBuffer.getDocument();
} catch (CoreException x) { } catch (CoreException x) {
fStatus= x.getStatus(); fStatus= x.getStatus();
if (fLocation != null) {
fDocument= manager.createEmptyDocument(fLocation, fLocationKind); fDocument= manager.createEmptyDocument(fLocation, fLocationKind);
if (fDocument instanceof ISynchronizable) }
if (fDocument instanceof ISynchronizable) {
((ISynchronizable)fDocument).setLockObject(new Object()); ((ISynchronizable)fDocument).setLockObject(new Object());
} }
}
fDocument.addPrenotifiedDocumentListener(this); fDocument.addPrenotifiedDocumentListener(this);
} }
@ -290,7 +314,11 @@ public class DocumentAdapter implements IBuffer, IDocumentListener {
if (fTextFileBuffer != null) { if (fTextFileBuffer != null) {
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager(); ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
try { try {
if (fLocation != null) {
manager.disconnect(fLocation, fLocationKind, new NullProgressMonitor()); manager.disconnect(fLocation, fLocationKind, new NullProgressMonitor());
} else {
manager.disconnectFileStore(fFileStore, new NullProgressMonitor());
}
} catch (CoreException x) { } catch (CoreException x) {
// ignore // ignore
} }

View file

@ -57,14 +57,23 @@ public class CNavigatorLinkHelper implements ILinkHelper {
*/ */
public IStructuredSelection findSelection(IEditorInput input) { public IStructuredSelection findSelection(IEditorInput input) {
IWorkingCopyManager mgr= CUIPlugin.getDefault().getWorkingCopyManager(); IWorkingCopyManager mgr= CUIPlugin.getDefault().getWorkingCopyManager();
ICElement element= mgr.getWorkingCopy(input); Object element= mgr.getWorkingCopy(input);
if (element == null) { if (element == null) {
IFile file = ResourceUtil.getFile(input); IFile file = ResourceUtil.getFile(input);
if (file != null && CoreModel.hasCNature(file.getProject())) { if (file != null && CoreModel.hasCNature(file.getProject())) {
element= CoreModel.getDefault().create(file); element= CoreModel.getDefault().create(file);
} }
} else { } else {
element= ((IWorkingCopy) element).getOriginalElement(); ITranslationUnit tUnit= ((IWorkingCopy) element).getOriginalElement();
IFile file= (IFile) tUnit.getResource();
if (file != null) {
element= CoreModel.getDefault().create(file);
if (element == null) {
element= file;
}
} else {
element= tUnit;
}
} }
return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY; return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY;
} }