Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2010-03-18 10:33:13 -0400
committerAlena Laskavaia2010-03-18 10:33:13 -0400
commitbad558e232093b7b985eed2f96a171f685a4b9f3 (patch)
tree06c83e68fdbf8f6b315e928bfe04d66b2315d8e0 /codan/org.eclipse.cdt.codan.examples
parent5cc82d793ac09b5ace108d842a52ad4b92a4e918 (diff)
downloadorg.eclipse.cdt-bad558e232093b7b985eed2f96a171f685a4b9f3.tar.gz
org.eclipse.cdt-bad558e232093b7b985eed2f96a171f685a4b9f3.tar.xz
org.eclipse.cdt-bad558e232093b7b985eed2f96a171f685a4b9f3.zip
- extracted example from real checkers
Diffstat (limited to 'codan/org.eclipse.cdt.codan.examples')
-rw-r--r--codan/org.eclipse.cdt.codan.examples/.classpath7
-rw-r--r--codan/org.eclipse.cdt.codan.examples/.project34
-rw-r--r--codan/org.eclipse.cdt.codan.examples/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--codan/org.eclipse.cdt.codan.examples/META-INF/MANIFEST.MF14
-rw-r--r--codan/org.eclipse.cdt.codan.examples/build.properties5
-rw-r--r--codan/org.eclipse.cdt.codan.examples/plugin.xml22
-rw-r--r--codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/Activator.java50
-rw-r--r--codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/NamingConventionFunctionChecker.java107
8 files changed, 247 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.examples/.classpath b/codan/org.eclipse.cdt.codan.examples/.classpath
new file mode 100644
index 0000000000..64c5e31b7a
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/codan/org.eclipse.cdt.codan.examples/.project b/codan/org.eclipse.cdt.codan.examples/.project
new file mode 100644
index 0000000000..7eacfe4486
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.cdt.codan.examples</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
diff --git a/codan/org.eclipse.cdt.codan.examples/.settings/org.eclipse.jdt.core.prefs b/codan/org.eclipse.cdt.codan.examples/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..3d823e3cf6
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Thu Mar 18 10:08:06 EDT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/codan/org.eclipse.cdt.codan.examples/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.examples/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..096f9a5604
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Code Analysis Checker Examples
+Bundle-SymbolicName: org.eclipse.cdt.codan.examples;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.cdt.codan.examples.Activator
+Bundle-Vendor: CDT
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.cdt.codan.core.cxx;bundle-version="1.0.0",
+ org.eclipse.cdt.codan.core;bundle-version="1.0.0",
+ org.eclipse.cdt.core;bundle-version="5.2.0",
+ org.eclipse.core.resources;bundle-version="3.6.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
diff --git a/codan/org.eclipse.cdt.codan.examples/build.properties b/codan/org.eclipse.cdt.codan.examples/build.properties
new file mode 100644
index 0000000000..e9863e281e
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/codan/org.eclipse.cdt.codan.examples/plugin.xml b/codan/org.eclipse.cdt.codan.examples/plugin.xml
new file mode 100644
index 0000000000..8d01e27f26
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/plugin.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.cdt.codan.core.checkers"
+ id="org.eclipse.cdt.codan.core.internal.checkers">
+
+ <checker
+ class="org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionChecker"
+ id="org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionChecker"
+ name="NamingConventionFunctionChecker">
+ <problem
+ category="org.eclipse.cdt.codan.core.categories.CodeStyle"
+ defaultEnabled="false"
+ defaultSeverity="Info"
+ id="org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionProblem"
+ messagePattern="Bad function name &quot;{0}&quot; (pattern /{1}/)"
+ name="Name convention for function">
+ </problem>
+ </checker>
+ </extension>
+</plugin>
diff --git a/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/Activator.java b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/Activator.java
new file mode 100644
index 0000000000..51f58149f8
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/Activator.java
@@ -0,0 +1,50 @@
+package org.eclipse.cdt.codan.examples;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.cdt.codan.examples"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ 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;
+ }
+
+}
diff --git a/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/NamingConventionFunctionChecker.java b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/NamingConventionFunctionChecker.java
new file mode 100644
index 0000000000..54799917d9
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/NamingConventionFunctionChecker.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Alena Laskavaia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.examples.checkers;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.cdt.codan.core.cxx.model.AbstractCIndexChecker;
+import org.eclipse.cdt.codan.core.model.ICheckerWithParameters;
+import org.eclipse.cdt.codan.core.model.IProblem;
+import org.eclipse.cdt.codan.core.model.IProblemParameterInfo;
+import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICElementVisitor;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * @author Alena
+ *
+ */
+public class NamingConventionFunctionChecker extends AbstractCIndexChecker
+ implements ICheckerWithParameters {
+ private static final String DEFAULT_PATTERN = "^[a-z]"; // name starts with english lowercase letter //$NON-NLS-1$
+ public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$
+ private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionProblem"; //$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.cdt.codan.core.model.ICIndexChecker#processUnit(org.eclipse
+ * .cdt.core.model.ITranslationUnit)
+ */
+ public void processUnit(ITranslationUnit unit) {
+ final IProblem pt = getProblemById(ER_ID, getFile());
+ try {
+ unit.accept(new ICElementVisitor() {
+ public boolean visit(ICElement element) throws CoreException {
+ if (element.getElementType() == ICElement.C_FUNCTION) {
+ String parameter = (String) pt.getParameter(PARAM_KEY);
+ Pattern pattern = Pattern.compile(parameter);
+ String name = element.getElementName();
+ if (!pattern.matcher(name).find()) {
+
+ reportProblem(ER_ID, getFile(), 1, // TODO: line number
+ name, parameter);
+ }
+ return false;
+ }
+ return true;
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.cdt.codan.core.model.ICheckerWithParameters#initParameters
+ * (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
+ */
+ public void initParameters(IProblemWorkingCopy problem) {
+ IProblemParameterInfo info = new IProblemParameterInfo() {
+ public String getUiInfo() {
+ return null;
+ }
+
+ public String getType() {
+ return IProblemParameterInfo.TYPE_STRING;
+ }
+
+ public String getLabel() {
+ return "Name Pattern";
+ }
+
+ public String getKey() {
+ return PARAM_KEY;
+ }
+
+ public IProblemParameterInfo getElement(String key) {
+ return null;
+ }
+ };
+ problem.setParameterInfo(info);
+
+ problem.setParameter(PARAM_KEY, DEFAULT_PATTERN);
+
+ }
+
+
+
+ @Override
+ public boolean runInEditor() {
+ return false;
+ }
+}

Back to the top