Skip to content

Commit

Permalink
Labeled all my own TODOs with TtC for future reference.
Browse files Browse the repository at this point in the history
Implemented some small things for Windows (untested).
  • Loading branch information
ttencate committed Aug 8, 2009
1 parent 5085c4c commit 8ba97b2
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected IProject[] build( final int kind,
////////////////////

private void checkCabalFile() throws CoreException {
// TODO replace by something not Cohatoe-based
// TODO TtC replace by something not Cohatoe-based
/*
if( getCabalFile().exists() ) {
CohatoeServer server = CohatoeServer.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* <p>A typical use would be to call a command line tool and ask for its
* version number, like 'java -version'.</p>
*
* TODO: refactor this to use ProcessRunner (and probably refactor ProcessRunner as well)
* TODO TtC refactor this to use ProcessRunner (and probably refactor ProcessRunner as well)
*
* @author Leif Frenzel
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* For parsing, the Parsec "grammar" from GHCOutputParser.hs is used.
*
* TODO this should be an {@link ICompilerListener}, I think.
* TODO TtC this should be an {@link ICompilerListener}, I think.
*
* @author Thomas ten Cate
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void reloadFile(String fileName) {
}

public void unloadFile(String fileName) {
// TODO Scion has no command for unloading yet!
// TODO TtC Scion has no command for unloading yet!
loadedFiles.remove(fileName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public static String getStringResource(String key) {

/**
* Returns whether tracing is enabled for the specified option.
* TODO this is executed for every trace call, even when tracing is off... optimize?
*/
public static boolean isTracing(String optionId) {
String option = getPluginId() + "/" + optionId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected String getMethod() {

@Override
protected void doProcessResult(Object result) throws JSONException {
// TODO
// TODO TtC
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Location {
private int startLine, startColumn, endLine, endColumn;

public Location(JSONObject json) throws JSONException {
// TODO this is not the complete syntax
// TODO TtC this is not the complete syntax
this.fileName = json.getString("file");
JSONArray region = json.getJSONArray("region");
startLine = region.getInt(0) - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public Label getLabelControl(final Composite parent) {
if (fLabelText != null && !"".equals(fLabelText)) { //$NON-NLS-1$
fLabel.setText(fLabelText);
} else {
// XXX: to avoid a 16 pixel wide empty label - revisit
// TODO to avoid a 16 pixel wide empty label - revisit
fLabel.setText("."); //$NON-NLS-1$
fLabel.setVisible(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Object execute(final ExecutionEvent event) {
ISelection selection = haskellEditor.getSelectionProvider().getSelection();
if (selection instanceof TextSelection) {
TextSelection textSel = (TextSelection)selection;
String name = textSel.getText().trim(); // TODO make work on 0-length selections too
String name = textSel.getText().trim(); // TODO TtC make work on 0-length selections too
Location location = HaskellUIPlugin.getDefault().getScionInstanceManager( file ).firstDefinitionLocation(name);
if (location != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

import java.util.HashMap;
import java.util.Map;

import net.sf.eclipsefp.haskell.core.internal.project.IManipulateCabalFile;
import net.sf.eclipsefp.haskell.core.internal.project.InvalidCabalFileException;
import net.sf.eclipsefp.haskell.core.internal.project.IManipulateCabalFile.Accessor;
import net.sf.eclipsefp.haskell.core.internal.project.IManipulateCabalFile.Mutator;
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
import net.sf.eclipsefp.haskell.ui.internal.editors.cabal.CabalFormEditor;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.text.DocumentEvent;
Expand Down Expand Up @@ -73,7 +71,7 @@ IStatusLineManager getStatusLineManager() {
}

IManipulateCabalFile getManipulator() {
// TODO replace by something not Cohatoe-based
// TODO TtC replace by something not Cohatoe-based
/*
CohatoeServer server = CohatoeServer.getInstance();
return server.createFunction( IManipulateCabalFile.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private void createTextOpAction( final String name, final int targetId,
}

private void initMarkOccurrences() {
// TODO replace by something not Cohatoe-based
// TODO TtC replace by something not Cohatoe-based
/*
* CohatoeServer server = CohatoeServer.getInstance(); IMarkOccurrences mo =
* server.createFunction( IMarkOccurrences.class ); if( mo != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class HaskellTextHover extends DefaultTextHover {
@Override
public String getHoverInfo( final ITextViewer textViewer,
final IRegion hoverRegion ) {
// XXX: this method does not get called when hovering over a string literal
// TODO TtC this method does not get called when hovering over a string literal
// which leads to potential problem annotation hovers not appearing
String hoverInfo = computeProblemInfo( textViewer, hoverRegion );
if (hoverInfo != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

import java.util.ArrayList;
import java.util.List;

import net.sf.eclipsefp.haskell.core.compiler.CompilerManager;
import net.sf.eclipsefp.haskell.core.compiler.ICompilerManager;
import net.sf.eclipsefp.haskell.core.internal.hsimpl.IHsImplementation;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;

Expand All @@ -18,7 +16,7 @@ public class CodeFolding implements ICodeFolding {
public List<ICodeFoldingRegion> performCodeFolding(
final IContainer srcRoot, final IFile file ) {
List<ICodeFoldingRegion> result = new ArrayList<ICodeFoldingRegion>();
// TODO replace by something not Cohatoe-based
// TODO TtC replace by something not Cohatoe-based
/*
String libDir = getGHCLibDir();
if( libDir != null && new File( libDir ).exists() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import net.sf.eclipsefp.haskell.core.project.HaskellProjectManager;
import net.sf.eclipsefp.haskell.core.project.IHaskellProject;
import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -50,7 +48,7 @@ void setDocument( final IDocument document ) {
}

void updateFoldingRegions() {
// TODO replace by something not Cohatoe-based
// TODO TtC replace by something not Cohatoe-based
/*
ProjectionAnnotationModel model = getAnnModel();
if( model != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private String detectScionServer() {
List<File> candidates = new ArrayList<File>(32);

// add all directories from the $PATH variable
// TODO this is Unix-only; Windows splits on semicolons I believe, and might do quoting/escaping?
// TODO TtC this is Unix-only; Windows splits on semicolons I believe, and might do quoting/escaping?
String path = System.getenv("PATH");
for (String dir : path.split(":")) {
candidates.add(new File(dir));
Expand Down Expand Up @@ -127,8 +127,7 @@ private String detectScionServer() {
}

public static String getServerExecutableName() {
// TODO Windows
return "scion_server";
return FileUtil.makeExecutableName("scion_server");
}

/* (non-Javadoc)
Expand All @@ -139,8 +138,8 @@ public void init(final IWorkbench workbench) {
}

public static void initializeDefaults(final IPreferenceStore store) {
// TODO invoke autodetection?
store.setDefault(SCION_SERVER_EXECUTABLE, "");
// scion might be on the path...
store.setDefault(SCION_SERVER_EXECUTABLE, getServerExecutableName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package net.sf.eclipsefp.haskell.ui.internal.refactoring;

import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
Expand Down Expand Up @@ -68,7 +67,7 @@ void createChange( final IProgressMonitor pm,

private Change createRenameChange() {
TextFileChange result = null;
// TODO replace by something not Cohatoe-based
// TODO TtC replace by something not Cohatoe-based
/*
CohatoeServer server = CohatoeServer.getInstance();
Object fun = server.createFunction( IMakePointFree.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package net.sf.eclipsefp.haskell.ui.internal.refactoring;

import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
Expand Down Expand Up @@ -68,7 +67,7 @@ void createChange( final IProgressMonitor pm,

private Change createRenameChange() {
TextFileChange result = null;
// TODO replace by something not Cohatoe-based
// TODO TtC replace by something not Cohatoe-based
/*
CohatoeServer server = CohatoeServer.getInstance();
IRename fun = server.createFunction( IRename.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,82 @@

import java.io.File;
import java.io.IOException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;

/**
* A class with some static helper methods to work with files.
*
*
* @author Thomas ten Cate
*/
public class FileUtil {


/**
* List of extensions of files that can be executed under Windows.
* The first is the default in case we need to construct a valid executable file name.
*/
public static final String[] WINDOWS_EXECUTABLE_EXTENSIONS = new String[] { "exe", "bat" };

private FileUtil() {
// do not instantiate
}


/**
* Makes the given base name into a valid executable file name.
* On Unix, this returns the base name itself.
* On Windows, it appends ".exe".
*/
public static String makeExecutableName(final String baseName) {
if (runningOnWindows()) {
return baseName + "." + WINDOWS_EXECUTABLE_EXTENSIONS[0];
} else {
return baseName;
}
}

/**
* Returns true if the given file is executable.
* On Unix, this checks the file permission bits.
* On Windows, it checks whether the file extension is that of an executable file.
*/
public static boolean isExecutable(File file) {
// if (we are on Unix) {
// Until Java 7, there is no way to check the executable bit of a file.
// Apart from writing a JNI function (hassle), this is the best we can do...
try {
Process process = Runtime.getRuntime().exec(new String[] {"test", "-x", file.getAbsolutePath()});
int exitValue = process.waitFor();
if (exitValue != 0) {
return false;
}
} catch (IOException ex) {
// pretend it succeeded
} catch (InterruptedException ex) {
// pretend it succeeded
public static boolean isExecutable(final File file) {
if (runningOnWindows()) {
return isExecutableWindows( file );
} else {
// Assume a UNIX flavour.
return isExecutableUnix( file );
}
return true;
// } else if (we are on Windows) {
// TODO implement this for Windows
// }
}

private static boolean isExecutableUnix( final File file ) {
// Until Java 7, there is no way to check the executable bit of a file.
// Apart from writing a JNI function (hassle), this is the best we can do...
try {
Process process = Runtime.getRuntime().exec(new String[] {"test", "-x", file.getAbsolutePath()});
int exitValue = process.waitFor();
if (exitValue != 0) {
return false;
}
} catch (IOException ex) {
// pretend it succeeded
} catch (InterruptedException ex) {
// pretend it succeeded
}
return true;
}

private static boolean isExecutableWindows( final File file ) {
String fileExt = new Path(file.getPath()).getFileExtension();
for (String ext : WINDOWS_EXECUTABLE_EXTENSIONS) {
if (fileExt.equals( ext )) {
return true;
}
}
return false;
}

private static boolean runningOnWindows() {
return Platform.getOS().equals( Platform.OS_WIN32 );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor;
import net.sf.eclipsefp.haskell.ui.internal.views.common.TreeElementCP;
import net.sf.eclipsefp.haskell.ui.internal.views.common.TreeElementLP;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ISelection;
Expand Down Expand Up @@ -81,7 +80,7 @@ public void selectionChanged( final SelectionChangedEvent event ) {

/** <p>sets the input of the outline page.</p> */
public void setInput( final Object input ) {
// TODO replace by something not Cohatoe-based
// TODO TtC replace by something not Cohatoe-based
/*
if( input != null && input instanceof IFileEditorInput ) {
IFileEditorInput fei = ( IFileEditorInput )input;
Expand Down

0 comments on commit 8ba97b2

Please sign in to comment.