Skip to content

Commit

Permalink
Respect the missing route pref
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan committed May 25, 2010
1 parent d5c14d7 commit 7f99e8c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/META-INF/MANIFEST.MF
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Playclipse
Bundle-SymbolicName: org.playframework.playclipse; singleton:=true
Bundle-Version: 0.6.0
Bundle-Version: 0.7.0
Bundle-Activator: org.playframework.playclipse.PlayPlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
Expand Down
1 change: 0 additions & 1 deletion source/src/fr/zenexity/pdt/editors/Editor.java
Expand Up @@ -231,7 +231,6 @@ public String toString() {

@Override
public void propertyChange(PropertyChangeEvent event) {
// TODO Auto-generated method stub
for (String type: getTypes()) {
if (event.getProperty().equals(getStylePref(type))) {
ISourceViewer viewer= getSourceViewer();
Expand Down
21 changes: 20 additions & 1 deletion source/src/org/playframework/playclipse/builder/PlayBuilder.java
Expand Up @@ -10,8 +10,17 @@
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.playframework.playclipse.PlayPlugin;
import org.playframework.playclipse.editors.route.RouteEditor;

public class PlayBuilder extends IncrementalProjectBuilder {
public class PlayBuilder extends IncrementalProjectBuilder implements IPropertyChangeListener {

public PlayBuilder() {
super();
PlayPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
}

class ResourceVisitor implements IResourceVisitor {
public boolean visit(IResource resource) {
Expand Down Expand Up @@ -66,4 +75,14 @@ protected void fullBuild(final IProgressMonitor monitor) throws CoreException {
}
}

@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(RouteEditor.MISSING_ROUTE)) {
try {
fullBuild(null);
} catch (CoreException e) {
}
}
}

}
19 changes: 14 additions & 5 deletions source/src/org/playframework/playclipse/builder/RouteChecker.java
Expand Up @@ -5,6 +5,8 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.playframework.playclipse.PlayPlugin;
import org.playframework.playclipse.editors.route.RouteEditor;

import fr.zenexity.pdt.editors.IO;
import fr.zenexity.pdt.editors.IO.LineReader;
Expand All @@ -20,6 +22,13 @@ public RouteChecker(IFile file) {

@Override
public void check() {
String severityStr = PlayPlugin.getDefault().getPreferenceStore().getString(RouteEditor.MISSING_ROUTE);
if (severityStr.equals("ignore")) return;
System.out.println("Severity => " + severityStr);
final int severity = severityStr.equals("warning")
? IMarker.SEVERITY_WARNING
: IMarker.SEVERITY_ERROR;

try {
IO.readLines(file, new LineReader() {
public void readLine(String line, int lineNumber, int offset) {
Expand All @@ -32,7 +41,7 @@ public void readLine(String line, int lineNumber, int offset) {
return;
}
try {
checkLine(line, lineNumber, offset);
checkLine(line, lineNumber, offset, severity);
} catch (CoreException e) {
e.printStackTrace();
}
Expand All @@ -44,24 +53,24 @@ public void readLine(String line, int lineNumber, int offset) {

private static Pattern METHOD = Pattern.compile("(\\*|GET|POST|PUT|DELETE|UPDATE|HEAD)");

private void checkLine(String line, int lineNumber, int offset) throws CoreException {
private void checkLine(String line, int lineNumber, int offset, int severity) throws CoreException {
String[] rule = line.split("\\s+");
if (rule.length != 3) {
addMarker("Invalid route syntax", lineNumber, IMarker.SEVERITY_ERROR, offset, offset + line.length());
addMarker("Invalid route syntax", lineNumber, severity, offset, offset + line.length());
return;
}
String method = rule[0];
//String path = rule[1];
String action = rule[2];
if (METHOD.matcher(method).matches() == false) {
addMarker("Invalid method", lineNumber, IMarker.SEVERITY_ERROR, offset, offset + method.length());
addMarker("Invalid method", lineNumber, severity, offset, offset + method.length());
}

if (action.indexOf(":") == -1 && // TODO: Check module routes
action.indexOf("{") == -1 && // TODO: Check if it's valid?
getInspector().resolveAction(action) == null) {
int start = offset + line.indexOf(action);
addMarker("Missing route: " + action, lineNumber, IMarker.SEVERITY_ERROR, start, start + action.length());
addMarker("Missing route: " + action, lineNumber, severity, start, start + action.length());
}
}

Expand Down

0 comments on commit 7f99e8c

Please sign in to comment.