Skip to content

Commit

Permalink
initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Oct 19, 2015
1 parent d812a52 commit b2ef7e5
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 1 deletion.
125 changes: 125 additions & 0 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import com.cflint.listeners.ProgressMonitorListener;
import com.cflint.listeners.ScanProgressListener;
import com.cflint.plugins.CFLintScanner;
import com.cflint.plugins.CFLintStructureListener;
import com.cflint.plugins.Context;
import com.cflint.plugins.Context.ContextMessage;
import com.cflint.plugins.exceptions.CFLintExceptionListener;
Expand Down Expand Up @@ -376,14 +377,67 @@ else if (elem.getName().equalsIgnoreCase("cffunction")) {
if (elem.getName().equalsIgnoreCase("cffunction")) {
inFunction = true;
handler.push("function");
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).startFunction(context);
for(final ContextMessage message : context.getMessages()){
reportRule(elem, "", context, plugin, message);
}
context.getMessages().clear();
}
}catch(Exception e){
reportRule(elem, "", context, plugin, e.getMessage());
}
}
processStack(elem.getChildElements(), space + " ", context);
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).endFunction(context);
for(final ContextMessage message : context.getMessages()){
reportRule(elem, "", context, plugin, message);
}
context.getMessages().clear();
}
}catch(Exception e){
reportRule(elem, "", context, plugin, e.getMessage());
}
}
inFunction = false;
handler.pop();
} else if (elem.getName().equalsIgnoreCase("cfcomponent")) {
inComponent = true;
handler.push("component");
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).startComponent(context);
for(final ContextMessage message : context.getMessages()){
reportRule(elem, "", context, plugin, message);
}
context.getMessages().clear();
}
}catch(Exception e){
reportRule(elem, "", context, plugin, e.getMessage());
}
}
context.setInComponent(true);
processStack(elem.getChildElements(), space + " ", context);
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).endComponent(context);
for(final ContextMessage message : context.getMessages()){
reportRule(elem, "", context, plugin, message);
}
context.getMessages().clear();
}
}catch(Exception e){
reportRule(elem, "", context, plugin, e.getMessage());
}
}

inComponent = false;
handler.pop();
} else if (elem.getName().equalsIgnoreCase("cfquery")) {
Expand Down Expand Up @@ -452,7 +506,36 @@ private void process(final CFScriptStatement expression, final String filename,
process(((CFExpressionStatement) expression).getExpression(), filename, elem, functionName);
} else if (expression instanceof CFCompDeclStatement) {
inComponent = true;
//do startComponent notifications
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).startComponent(context);
for(final ContextMessage message : context.getMessages()){
reportRule(elem, expression, context, plugin, message);
}
context.getMessages().clear();
}
}catch(Exception e){
reportRule(elem, expression, context, plugin, e.getMessage());
}
}
//process the component declaration
process(((CFCompDeclStatement) expression).getBody(), filename, elem, functionName);
//do endComponent notifications
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).endComponent(context);
for(final ContextMessage message : context.getMessages()){
reportRule(elem, expression, context, plugin, message);
}
context.getMessages().clear();
}
}catch(Exception e){
reportRule(elem, expression, context, plugin, e.getMessage());
}
}
inComponent = false;
} else if (expression instanceof CFForStatement) {
process(((CFForStatement) expression).getInit(), filename, elem, functionName);
Expand Down Expand Up @@ -496,7 +579,34 @@ private void process(final CFScriptStatement expression, final String filename,
for (final CFFunctionParameter param : function.getFormals()) {
handler.addArgument(param.getName());
}
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).startFunction(context);
for(final ContextMessage message : context.getMessages()){
reportRule(elem, expression, context, plugin, message);
}
context.getMessages().clear();
}
}catch(Exception e){
reportRule(elem, expression, context, plugin, e.getMessage());
}
}

process(function.getBody(), filename, elem, function.getName());
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).endFunction(context);
for(final ContextMessage message : context.getMessages()){
reportRule(elem, expression, context, plugin, message);
}
context.getMessages().clear();
}
}catch(Exception e){
reportRule(elem, expression, context, plugin, e.getMessage());
}
}
inFunction = false;
handler.pop();
} else {
Expand Down Expand Up @@ -760,12 +870,27 @@ public void addScanProgressListener(final ScanProgressListener scanProgressListe

protected void fireStartedProcessing(final String srcidentifier) {
currentFile = srcidentifier;
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).startFile(srcidentifier);
}
}catch(Exception e){}
}

for (final ScanProgressListener p : scanProgressListeners) {
p.startedProcessing(srcidentifier);
}
}

protected void fireFinishedProcessing(final String srcidentifier) {
for (final CFLintScanner plugin : extensions) {
try{
if(plugin instanceof CFLintStructureListener){
((CFLintStructureListener) plugin).endFile(currentFile);
}
}catch(Exception e){}
}
for (final ScanProgressListener p : scanProgressListeners) {
p.finishedProcessing(srcidentifier);
}
Expand Down
39 changes: 38 additions & 1 deletion src/main/java/com/cflint/plugins/CFLintScannerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

/**
* Lint Rule Plugins can extend this adapter instead of implementing all the methods of CFLintScanner
* (and CFLintStructureListener)
*
* @author eberlyrh
*
*/
public class CFLintScannerAdapter implements CFLintScanner {
public class CFLintScannerAdapter implements CFLintScanner,CFLintStructureListener {

Map<String, String> params = new HashMap<String,String>();
public CFLintScannerAdapter() {
Expand Down Expand Up @@ -49,4 +50,40 @@ public int currentLine(final CFExpression expression, final Context context) {
public Map<String, String> getParams() {
return params;
}

/**
* Default implementation does nothing
*/
@Override
public void startFile(String fileName) {}

/**
* Default implementation does nothing
*/
@Override
public void endFile(String fileName) {}

/**
* Default implementation does nothing
*/
@Override
public void startComponent(Context context) {}

/**
* Default implementation does nothing
*/
@Override
public void endComponent(Context context) {}

/**
* Default implementation does nothing
*/
@Override
public void startFunction(Context context) {}

/**
* Default implementation does nothing
*/
@Override
public void endFunction(Context context) {}
}
45 changes: 45 additions & 0 deletions src/main/java/com/cflint/plugins/CFLintStructureListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.cflint.plugins;

/**
* This interface supports plugins recieving structure notifications (file start/end, component start/end, function start/end)
*
* Normally it is used for initialization or summarization types of behaviours
* @author eberlyrh
*
*/
public interface CFLintStructureListener {

/**
* Called when processing of a new file has started
* @param context
*/
public void startFile(String fileName);
/**
* Called when processing of current file has ended
* @param context
*/
public void endFile(String fileName);

/**
* Called when processing a new component has started
* @param context
*/
public void startComponent(Context context);
/**
* Called when processing of current component has ended
* @param context
*/
public void endComponent(Context context);

/**
* Called when processing of a new function has started
* @param context
*/
public void startFunction(Context context);
/**
* Called when processing of current function has ended
* @param context
*/
public void endFunction(Context context);

}

0 comments on commit b2ef7e5

Please sign in to comment.