From 5954124bbf9044c702c576e75fca01bc7e0f5d23 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Tue, 30 Mar 2010 18:34:54 +0000 Subject: [PATCH] - fixed couple of NPE's --- .../eclipse/cdt/codan/core/cxx/Activator.java | 30 +++++++++++++++++++ .../cxx/model/AbstractIndexAstChecker.java | 7 ++++- .../preferences/FieldEditorOverlayPage.java | 18 ++++++----- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/Activator.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/Activator.java index ab9f071891e..7bdfbef8233 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/Activator.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/Activator.java @@ -1,6 +1,8 @@ package org.eclipse.cdt.codan.core.cxx; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; import org.osgi.framework.BundleContext; /** @@ -46,5 +48,33 @@ public class Activator extends Plugin { public static Activator getDefault() { return plugin; } + /** + * Logs the specified status with this plug-in's log. + * + * @param status + * status to log + */ + public static void log(IStatus status) { + getDefault().getLog().log(status); + } + /** + * Logs an internal error with the specified throwable + * + * @param e + * the exception to be logged + */ + public static void log(Throwable e) { + log(new Status(IStatus.ERROR, PLUGIN_ID, 1, "Internal Error", e)); //$NON-NLS-1$ + } + + /** + * Logs an internal error with the specified message. + * + * @param message + * the error message to log + */ + public static void log(String message) { + log(new Status(IStatus.ERROR, PLUGIN_ID, 1, message, null)); + } } diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java index dc146fc2393..0eeac066ba7 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java @@ -11,9 +11,10 @@ package org.eclipse.cdt.codan.core.cxx.model; import org.eclipse.cdt.codan.core.CodanCorePlugin; +import org.eclipse.cdt.codan.core.cxx.Activator; import org.eclipse.cdt.codan.core.model.AbstractChecker; -import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker; import org.eclipse.cdt.codan.core.model.IProblemLocation; +import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTNode; @@ -88,6 +89,10 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements if (astFile == null) { astFile = file; } + if (astFile == null) { + Activator.log("Cannot resolve location: "+location); //$NON-NLS-1$ + return; + } IProblemLocation loc; int line = astLocation.getStartingLineNumber(); if (line == astLocation diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java index e617a7541f0..6b77c8a388c 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/FieldEditorOverlayPage.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.codan.internal.ui.preferences; import java.util.ArrayList; import java.util.Iterator; import java.util.List; - import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.PreferenceConstants; import org.eclipse.core.resources.IProject; @@ -121,6 +120,8 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement() */ public IAdaptable getElement() { + if (!(element instanceof IProject)) + return (IAdaptable) element.getAdapter(IProject.class); return element; } @@ -157,12 +158,15 @@ public abstract class FieldEditorOverlayPage extends FieldEditorPreferencePage // Cache the page id pageId = getPageId(); // Create an overlay preference store and fill it with properties - ProjectScope ps = new ProjectScope((IProject) getElement()); - ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, - CodanCorePlugin.PLUGIN_ID); - scoped.setSearchContexts(new IScopeContext[] { ps, - new InstanceScope() }); - overlayStore = scoped; + IAdaptable e = getElement(); + if (e != null) { + ProjectScope ps = new ProjectScope((IProject) e); + ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, + CodanCorePlugin.PLUGIN_ID); + scoped.setSearchContexts(new IScopeContext[] { ps, + new InstanceScope() }); + overlayStore = scoped; + } // Set overlay store as current preference store } super.createControl(parent);