1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 09:15:38 +02:00

- fixed couple of NPE's

This commit is contained in:
Alena Laskavaia 2010-03-30 18:34:54 +00:00
parent 077c8e6e45
commit 5954124bbf
3 changed files with 47 additions and 8 deletions

View file

@ -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));
}
}

View file

@ -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

View file

@ -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());
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);