Permalink
Browse files

Markers in the route editor

  • Loading branch information...
erwan committed May 25, 2010
1 parent 7c17780 commit 2f8c4987348fe192a5a1f386bc57b31682cdcab9
@@ -3,20 +3,14 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerExtension;
@@ -35,7 +29,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.MarkerUtilities;
import org.playframework.playclipse.PlayPlugin;
@@ -251,51 +244,6 @@ public void propertyChange(PropertyChangeEvent event) {
}
}
// Markers
protected List<Map<String, Object>> pendingMarkers = new ArrayList<Map<String, Object>>();
public void updateMarkers() {
clearMarkers();
for (int i = 0; i < pendingMarkers.size(); i++) {
try {
addError(pendingMarkers.get(i));
} catch (CoreException e) {
// shouldn't happen
}
}
pendingMarkers = new ArrayList<Map<String, Object>>();
}
protected Map<String, Object> getMarkerParameters(int begin, int end, String message, int severity)
throws BadLocationException {
Map<String, Object> map = new HashMap<String, Object>();
MarkerUtilities.setLineNumber(map, getHelper().getLineNumber(begin));
MarkerUtilities.setMessage(map, message);
map.put(IMarker.MESSAGE, message);
map.put(IMarker.LOCATION, getPath().toString());
map.put(IMarker.CHAR_START, begin);
map.put(IMarker.CHAR_END, end);
map.put(IMarker.SEVERITY, new Integer(severity));
return map;
}
private void addError(Map<String, Object> parameters) throws CoreException {
IFile curfile = ((IFileEditorInput)getEditorInput()).getFile();
// MarkerUtilities.createMarker(curfile, parameters, IMarker.PROBLEM);
IMarker marker= curfile.createMarker(IMarker.PROBLEM);
marker.setAttributes(parameters);
}
private void clearMarkers() {
IFile file = ((IFileEditorInput)getEditorInput()).getFile();
try {
file.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
} catch (CoreException e) {
// something went wrong
}
}
// Soft tabs
protected boolean useSoftTabs = false;
@@ -0,0 +1,38 @@
package fr.zenexity.pdt.editors;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
public class IO {
public interface LineReader {
public void readLine(String line, int lineNumber, int offset);
}
public static void readLines(InputStream inputStream, LineReader reader) throws IOException {
StringBuffer lineBuf = new StringBuffer();
int c = inputStream.read();
int lineNumber = 1;
int offset = 0;
while (c != -1) {
if ((char)c == '\n') {
String line = lineBuf.toString();
reader.readLine(line, lineNumber++, offset);
offset += line.length() + 1;
lineBuf = new StringBuffer();
} else {
lineBuf.append((char)c);
}
c = inputStream.read();
}
inputStream.close();
}
public static void readLines(IFile file, LineReader reader) throws IOException, CoreException {
readLines(file.getContents(), reader);
}
}
@@ -18,19 +18,10 @@
package org.playframework.playclipse;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IExecutionListener;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import fr.zenexity.pdt.editors.Editor;
/**
* The activator class controls the plug-in life cycle
*/
@@ -61,7 +52,7 @@ public PlayPlugin() {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
/*
ICommandService commandService = (ICommandService)plugin.getWorkbench().getService(ICommandService.class);
commandService.addExecutionListener(new IExecutionListener() {
public void notHandled(final String commandId, final NotHandledException exception) {}
@@ -75,7 +66,7 @@ public void preExecute( final String commandId, final ExecutionEvent event ) {
}
}
}
});
});*/
}
/*
@@ -27,8 +27,7 @@ public ConfigurationFile(IProject project) {
List<String> lines = getLines();
Pattern p = Pattern.compile("module\\.(\\w+)=(.+)");
Matcher m;
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);
for (String line: lines) {
String moduleName;
String modulePath;
m = p.matcher(line);
@@ -45,8 +44,7 @@ public int getPort() {
List<String> lines = getLines();
Pattern p = Pattern.compile("^\\s*port\\s*=([0-9]+)");
Matcher m;
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);
for (String line: lines) {
int port = 0;
String sport;
m = p.matcher(line);
@@ -0,0 +1,37 @@
package org.playframework.playclipse.builder;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
public abstract class ErrorChecker {
protected IFile file;
public ErrorChecker() {}
public ErrorChecker(IFile file) {
this.file = file;
}
protected IMarker addMarker(String message, int lineNumber, int severity) throws CoreException {
IMarker marker = file.createMarker(IMarker.PROBLEM);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, severity);
if (lineNumber == -1) {
lineNumber = 1;
}
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
return marker;
}
protected IMarker addMarker(String message, int lineNumber, int severity, int begin, int end) throws CoreException {
IMarker marker = addMarker(message, lineNumber, severity);
marker.setAttribute(IMarker.CHAR_START, begin);
marker.setAttribute(IMarker.CHAR_END, end);
return marker;
}
public abstract void check();
}
Oops, something went wrong.

0 comments on commit 2f8c498

Please sign in to comment.