我已经基于codan
创建了一个Checker插件,并尝试设置启动模式。
我的检查程序扩展了org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker
并覆盖了initPreferences
,因为我没有找到专门用于此用法的扩展点。文件plugin.xml
应该提供一种声明性的方式,更好的恕我直言。
@Override
public void initPreferences( IProblemWorkingCopy problem ) {
super.initPreferences( problem );
final RootProblemPreference pp = (RootProblemPreference)problem.getPreference();
final LaunchModeProblemPreference lmpp = pp.getLaunchModePreference();
lmpp.addLaunchMode( CheckerLaunchMode.RUN_ON_FULL_BUILD, Boolean.FALSE );
lmpp.addLaunchMode( CheckerLaunchMode.RUN_ON_INC_BUILD , Boolean.FALSE );
lmpp.addLaunchMode( CheckerLaunchMode.RUN_ON_DEMAND , Boolean.TRUE );
lmpp.addLaunchMode( CheckerLaunchMode.RUN_ON_FILE_OPEN , Boolean.FALSE );
lmpp.addLaunchMode( CheckerLaunchMode.RUN_AS_YOU_TYPE , Boolean.TRUE );
lmpp.addLaunchMode( CheckerLaunchMode.RUN_ON_FILE_SAVE , Boolean.FALSE );
final SuppressionCommentProblemPreference scp = pp.getSuppressionCommentPreference();
scp.setValue( "//[[derogations(" + problem.getName() + ")]]" );
problem.setPreference((IProblemPreference)pp.clone());
System.out.println( problem.getName() + ": " + problem.getPreference());
}
在运行时,控制台显示初始化成功:
...
RAF-LNG-020: [org.eclipse.cdt.codan.core.param.FileScopeProblemPreference@20676b19, [(boolean)RUN_ON_FULL_BUILD=false, (boolean)RUN_ON_INC_BUILD=false, (boolean)RUN_ON_FILE_OPEN=false, (boolean)RUN_ON_FILE_SAVE=false, (boolean)RUN_AS_YOU_TYPE=true, (boolean)RUN_ON_DEMAND=true], (string)suppression_comment=//[[derogations(RAF-LNG-020)]]]
RAF-LNG-030: [org.eclipse.cdt.codan.core.param.FileScopeProblemPreference@1f0ca550, [(boolean)RUN_ON_FULL_BUILD=false, (boolean)RUN_ON_INC_BUILD=false, (boolean)RUN_ON_FILE_OPEN=false, (boolean)RUN_ON_FILE_SAVE=false, (boolean)RUN_AS_YOU_TYPE=true, (boolean)RUN_ON_DEMAND=true], (string)suppression_comment=//[[derogations(RAF-LNG-030)]]]
...
1)第一个问题:
[X] Run as you type
[ ] Run on file open
[ ] Run as file save
[X] Run on incremental build
[X] Run on full build
[X] Run on demand
2)第二个问题:
我该如何真正调整偏好设置?