diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 23f290120fa..31c8733da45 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,14 @@ +2004-06-01 Alain Magloire + + Fall back on the Nature of the project + to decide of the syntax of the CEditor. + + * src/org/eclipse/cdt/internal/ui/editor/CEditor.java + + NPE in the CSourceHover. + + * src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java + 2004-05-31 Alain Magloire Putting a good chunk of code(Taken from JDT) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index c0ade7b0ebc..aa0fa668286 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -13,6 +13,7 @@ import java.util.StringTokenizer; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.filetype.ICFileType; import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ISourceRange; import org.eclipse.cdt.core.model.ISourceReference; @@ -31,6 +32,7 @@ import org.eclipse.cdt.ui.actions.RefactoringActionGroup; import org.eclipse.cdt.ui.actions.ShowInCViewAction; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.action.IAction; @@ -902,7 +904,15 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS // Figure out if this is a C or C++ source file IWorkingCopyManager mgr = CUIPlugin.getDefault().getWorkingCopyManager(); ITranslationUnit unit = mgr.getWorkingCopy(getEditorInput()); - String fileType = (unit != null && unit.isCXXLanguage()) ? LANGUAGE_CPP : LANGUAGE_C; + String fileType = LANGUAGE_CPP; + if (unit != null) { + // default is C++ unless the project as C Nature Only + // we can then be smarter. + IProject p = unit.getCProject().getProject(); + if (!CoreModel.hasCCNature(p)) { + fileType = unit.isCXXLanguage() ? LANGUAGE_CPP : LANGUAGE_C; + } + } fAnnotationAccess = createAnnotationAccess(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java index 372264cbeda..6da050d7888 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java @@ -51,6 +51,9 @@ public class CSourceHover extends AbstractCEditorTextHover { IEditorInput input= editor.getEditorInput(); IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager(); IWorkingCopy copy = manager.getWorkingCopy(input); + if (copy == null) { + return null; + } String expression; try {