Skip to content

Commit 0db621a

Browse files
author
angelozerr
committed
Change API of interpreter.
1 parent 075088a commit 0db621a

File tree

11 files changed

+49
-54
lines changed

11 files changed

+49
-54
lines changed

eclipse/terminal/ts.eclipse.ide.terminal.interpreter.npm/src/ts/eclipse/ide/terminal/interpreter/npm/internal/commands/NpmCommandInterpreterFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class NpmCommandInterpreterFactory implements ICommandInterpreterFactory
1010
@Override
1111
public ICommandInterpreter create(List<String> parameters, String workingDir) {
1212
if (parameters.contains("install")) {
13-
return new NpmInstallCommandInterpreter(parameters, workingDir);
13+
return new NpmInstallCommandInterpreter(workingDir);
1414
}
1515
return null;
1616
}

eclipse/terminal/ts.eclipse.ide.terminal.interpreter.npm/src/ts/eclipse/ide/terminal/interpreter/npm/internal/commands/NpmInstallCommandInterpreter.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ts.eclipse.ide.terminal.interpreter.npm.internal.commands;
22

3-
import java.util.List;
4-
53
import org.eclipse.core.resources.IContainer;
64
import org.eclipse.core.resources.ResourcesPlugin;
75
import org.eclipse.core.runtime.IProgressMonitor;
@@ -20,13 +18,13 @@
2018

2119
public class NpmInstallCommandInterpreter extends AbstractCommandInterpreter {
2220

23-
public NpmInstallCommandInterpreter(List<String> parameters, String workingDir) {
24-
super(parameters, workingDir);
21+
public NpmInstallCommandInterpreter(String workingDir) {
22+
super(workingDir);
2523
}
2624

2725
@Override
28-
public void execute(List<String> parameters, String workingDir) {
29-
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation(new Path(workingDir));
26+
public void execute() {
27+
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation(new Path(getWorkingDir()));
3028
if (c != null && c.length > 0) {
3129
final IContainer container = c[0];
3230
new UIJob("Refresh npm project") {

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/AbstractCommandInterpreter.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,20 @@
1010
*/
1111
package ts.eclipse.ide.terminal.interpreter;
1212

13-
import java.util.List;
14-
1513
/**
1614
* Abstract class for {@link ICommandInterpreter}.
1715
*
1816
*/
1917
public abstract class AbstractCommandInterpreter implements ICommandInterpreter {
2018

21-
private final List<String> parameters;
2219
private final String workingDir;
2320

24-
public AbstractCommandInterpreter(List<String> parameters, String workingDir) {
25-
this.parameters = parameters;
21+
public AbstractCommandInterpreter(String workingDir) {
2622
this.workingDir = workingDir;
2723
}
2824

29-
@Override
30-
public void execute() {
31-
execute(parameters, workingDir);
25+
public String getWorkingDir() {
26+
return workingDir;
3227
}
3328

3429
@Override
@@ -37,12 +32,9 @@ public void onTrace(String line) {
3732
}
3833

3934
/**
40-
* Execute the command interpreter with the given parameters and working
41-
* directory.
35+
* Execute the command interpreter.
4236
*
43-
* @param parameters
44-
* @param workingDir
4537
*/
46-
protected abstract void execute(List<String> parameters, String workingDir);
38+
public abstract void execute();
4739

4840
}

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/CommandInterpreterProcessor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import ts.eclipse.ide.terminal.interpreter.ICommandInterpreter;
2323
import ts.eclipse.ide.terminal.interpreter.ICommandInterpreterFactory;
24-
import ts.eclipse.ide.terminal.interpreter.internal.commands.CdCommandInterpreter;
24+
import ts.eclipse.ide.terminal.interpreter.internal.commands.CdCommandInterpreterFactory;
2525

2626
public class CommandInterpreterProcessor implements ITerminalServiceOutputStreamMonitorListener {
2727

@@ -37,6 +37,9 @@ public void onTrace(String line) {
3737

3838
}
3939
};
40+
41+
private final ICommandInterpreterFactory CD_INTERPRETER_FACTORY = new CdCommandInterpreterFactory();
42+
4043
private final Map<String, Object> properties;
4144
private ICommandInterpreter interpreter;
4245

@@ -109,7 +112,7 @@ public void onContentReadFromStream(byte[] byteBuffer, int bytesRead) {
109112
} else {
110113
// User is typing command.
111114
String lineCmd = lines.getLastLine();
112-
if (lineCmd != null) {
115+
if (lineCmd != null && lineCmd.length() >= lineInput.length()) {
113116
// line cmd contains the working dir and the command
114117
// with parameters
115118
// ex: "C:\User>cd a"
@@ -158,7 +161,7 @@ private void endCommand(String lastLine) {
158161
if (workingDirChanged) {
159162
String workingDir = getWorkingDir(lineInput);
160163
List<String> parameters = getParameters(cmdWithParameters);
161-
new CdCommandInterpreter(parameters, workingDir).execute();
164+
CD_INTERPRETER_FACTORY.create(parameters, workingDir).execute();
162165
}
163166
this.lineInput = lastLine;
164167
}

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/commands/CdCommandInterpreter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ts.eclipse.ide.terminal.interpreter.internal.commands;
22

3-
import java.util.List;
4-
53
import org.eclipse.core.resources.IContainer;
64
import org.eclipse.core.resources.ResourcesPlugin;
75
import org.eclipse.core.runtime.Path;
@@ -17,16 +15,18 @@
1715

1816
public class CdCommandInterpreter extends AbstractCommandInterpreter {
1917

20-
public CdCommandInterpreter(List<String> parameters, String workingDir) {
21-
super(parameters, workingDir);
18+
private final String path;
19+
20+
public CdCommandInterpreter(String path, String workingDir) {
21+
super(workingDir);
22+
this.path = path;
2223
}
2324

2425
@Override
25-
public void execute(List<String> parameters, String workingDir) {
26-
String path = parameters.get(0);
26+
public void execute() {
2727
try {
2828
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot()
29-
.findContainersForLocation(new Path(workingDir + "/" + path));
29+
.findContainersForLocation(new Path(getWorkingDir() + "/" + path));
3030
if (c != null && c.length > 0) {
3131
IWorkbenchPage page = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage();
3232
final IViewPart view = page.findView(IPageLayout.ID_PROJECT_EXPLORER);

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/commands/CdCommandInterpreterFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public ICommandInterpreter create(List<String> parameters, String workingDir) {
2222
if (parameters.size() < 1) {
2323
return null;
2424
}
25-
return new CdCommandInterpreter(parameters, workingDir);
25+
String path = parameters.get(0);
26+
return new CdCommandInterpreter(path, workingDir);
2627
}
2728

2829
}

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/commands/DelCommandInterpreter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ts.eclipse.ide.terminal.interpreter.internal.commands;
22

3-
import java.util.List;
4-
53
import org.eclipse.core.resources.IContainer;
64
import org.eclipse.core.resources.ResourcesPlugin;
75
import org.eclipse.core.runtime.Path;
@@ -12,15 +10,17 @@
1210

1311
public class DelCommandInterpreter extends AbstractCommandInterpreter {
1412

15-
public DelCommandInterpreter(List<String> parameters, String workingDir) {
16-
super(parameters, workingDir);
13+
private final String path;
14+
15+
public DelCommandInterpreter(String path, String workingDir) {
16+
super(workingDir);
17+
this.path = path;
1718
}
1819

1920
@Override
20-
public void execute(List<String> parameters, String workingDir) {
21-
String path = parameters.get(0);
21+
public void execute() {
2222
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot()
23-
.findContainersForLocation(new Path(workingDir + "/" + path));
23+
.findContainersForLocation(new Path(getWorkingDir() + "/" + path));
2424
if (c != null && c.length > 0) {
2525
for (int i = 0; i < c.length; i++) {
2626
UIJob job = new RefreshContainerJob(c[i]);

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/commands/DelCommandInterpreterFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public ICommandInterpreter create(List<String> parameters, String workingDir) {
2626
if (parameters.size() < 1) {
2727
return null;
2828
}
29-
return new DelCommandInterpreter(parameters, workingDir);
29+
String path = parameters.get(0);
30+
return new DelCommandInterpreter(path, workingDir);
3031
}
3132

3233
}

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/commands/RdCommandInterpreter.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ts.eclipse.ide.terminal.interpreter.internal.commands;
22

3-
import java.util.List;
4-
53
import org.eclipse.core.resources.IContainer;
64
import org.eclipse.core.resources.ResourcesPlugin;
75
import org.eclipse.core.runtime.Path;
@@ -12,15 +10,17 @@
1210

1311
public class RdCommandInterpreter extends AbstractCommandInterpreter {
1412

15-
public RdCommandInterpreter(List<String> parameters, String workingDir) {
16-
super(parameters, workingDir);
13+
private final String path;
14+
15+
public RdCommandInterpreter(String path, String workingDir) {
16+
super(workingDir);
17+
this.path = path;
1718
}
1819

1920
@Override
20-
public void execute(List<String> parameters, String workingDir) {
21-
String path = getPath(parameters);
21+
public void execute() {
2222
final IContainer[] c = ResourcesPlugin.getWorkspace().getRoot()
23-
.findContainersForLocation(new Path(workingDir + "/" + path));
23+
.findContainersForLocation(new Path(getWorkingDir()).append(path));
2424
if (c != null && c.length > 0) {
2525
for (int i = 0; i < c.length; i++) {
2626
UIJob job = new RefreshContainerJob(c[i].getParent());
@@ -29,12 +29,6 @@ public void execute(List<String> parameters, String workingDir) {
2929
}
3030
}
3131

32-
private String getPath(List<String> parameters) {
33-
// RD [/S] [/Q] [drive:]path
34-
// path is the last token
35-
return parameters.get(parameters.size() - 1);
36-
}
37-
3832
@Override
3933
public void onTrace(String line) {
4034
// Do nothing

eclipse/terminal/ts.eclipse.ide.terminal.interpreter/src/ts/eclipse/ide/terminal/interpreter/internal/commands/RdCommandInterpreterFactory.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@
2222
public class RdCommandInterpreterFactory implements ICommandInterpreterFactory {
2323

2424
@Override
25-
public ICommandInterpreter create(List<String> parameters, String workingDir) {
25+
public ICommandInterpreter create(List<String> parameters, String workingDir) {
2626
if (parameters.size() < 1) {
2727
return null;
2828
}
29-
return new RdCommandInterpreter(parameters, workingDir);
29+
return new RdCommandInterpreter(getPath(parameters), workingDir);
30+
}
31+
32+
private String getPath(List<String> parameters) {
33+
// RD [/S] [/Q] [drive:]path
34+
// path is the last token
35+
return parameters.get(parameters.size() - 1);
3036
}
3137

3238
}

0 commit comments

Comments
 (0)