Permalink
Browse files

Respect the missing route pref

  • Loading branch information...
erwan committed May 25, 2010
1 parent d5c14d7 commit 7f99e8c8175452ddd735c763f889280933abe9a1
@@ -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,
@@ -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();
@@ -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) {
@@ -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) {
}
}
}
}
@@ -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;
@@ -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) {
@@ -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();
}
@@ -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());
}
}

0 comments on commit 7f99e8c

Please sign in to comment.