blob: 39e0bdec8f26211f6e8a49d6cc83d6c4d5b80fdc [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2019 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Xavier Le Pallec (for CEA LIST) xlepallec@lilo.org - Bug 558456
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.clazz.lf.autosizeableclasses;
import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.eclipse.papyrus.uml.diagram.clazz.lf.autosizeableclasses.messages.Messages;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.diagram.clazz.lf.autosizeableclasses"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
private LogHelper myLogHelper;
/**
* The constructor
*/
public Activator() {
// this constructor is required to implement the extension point.
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
/**
* Logs an error through a message (param)
* @param error
*/
public void logError(String error) {
getLogHelper().warn(error);
}
/**
* Logs an error through a message and an exception (params)
* @param error
* @param throwable
*/
public void logError(String error, Throwable throwable) {
getLogHelper().error(error, throwable);
}
/**
* Logs an information through a message (param)
* @param message
*/
public void logInfo(String message) {
getLogHelper().info(message);
}
/**
* Logs an information through a message and an exception (params)
* @param message
* @param throwable
*/
public void logInfo(String message, Throwable throwable) {
getLogHelper().error(message, throwable);
}
/**
* Gets the LogHelper
* @return
*/
public LogHelper getLogHelper() {
if (myLogHelper==null) {
myLogHelper=new LogHelper(getDefault());
}
return myLogHelper;
}
public void logNullParameter(String parameterName) {
getLogHelper().warn(Messages.Activator_Parameter+parameterName+Messages.Activator_IsNullInMethod+getMethodName(4));
}
public void logNullParameter(String parameterName, int deep) {
getLogHelper().warn(Messages.Activator_Parameter+parameterName+Messages.Activator_IsNullInMethod+getMethodName(deep));
}
public void logCastProblem(String variableName, Class targetCastClass, int deep) {
getLogHelper().warn(variableName+Messages.Activator_CannotBeCastedIn+targetCastClass.getName()+Messages.Activator_InMethod+getMethodName(deep));
}
public void logCastProblem(String variableName, Class targetCastClass) {
getLogHelper().warn(variableName+Messages.Activator_CannotBeCastedIn+targetCastClass.getName()+Messages.Activator_InMethod+getMethodName(3));
}
/**
* Get the method name for a depth in call stack. <br />
* Utility function
* @param depth depth in the call stack (0 means current method, 1 means call method, ...)
* @return method name
*/
public static String getMethodName(int deep)
{
final StackTraceElement[] ste = Thread.currentThread().getStackTrace();
return ste[deep].getMethodName()+" ("+ste[deep].getClassName()+")";
}
}