Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
@lang: correct use of CancellationException
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Mar 20, 2015
1 parent 6872214 commit b88c73b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import melnorme.lang.ide.core.utils.CoreOperationAdapter;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.CollectionUtil;
import melnorme.utilbox.misc.Location;
Expand All @@ -38,7 +39,7 @@ public GetAndInstallGoPackageOperation(String goPackage, String exeName) {
protected Location workingDir;

@Override
public void doRun(IProgressMonitor monitor) throws CommonException, CoreException {
public void doRun(IProgressMonitor monitor) throws CommonException, CoreException, OperationCancellation {
GoEnvironment goEnv = GoProjectEnvironment.getGoEnvironment(null);
workingDir = getFirstGoPathEntry(goEnv);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import melnorme.lang.ide.core.operations.LangProjectBuilder;
import melnorme.lang.ide.core.operations.LangProjectBuilderExt;
import melnorme.lang.ide.core.operations.SDKLocationValidator;
import melnorme.lang.ide.core.utils.EclipseUtils;
import melnorme.lang.tooling.data.LocationValidator;
import melnorme.lang.tooling.data.StatusException;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;
Expand Down Expand Up @@ -90,7 +92,7 @@ protected void handleLastOfKind() {

@Override
protected IProject[] doBuild(final IProject project, int kind, Map<String, String> args, IProgressMonitor monitor)
throws CoreException {
throws CoreException, OperationCancellation {

GoToolManager.getDefault().notifyBuildStarting(project, false);

Expand Down Expand Up @@ -154,6 +156,15 @@ protected void addSourcePackagesToCmdLine(final IProject project, ArrayList2<Str

@Override
protected void clean(IProgressMonitor monitor) throws CoreException {
try {
EclipseUtils.checkMonitorCancelation(monitor);
doClean(monitor);
} catch (OperationCancellation e) {
// return
}
}

protected void doClean(IProgressMonitor monitor) throws CoreException, OperationCancellation {
deleteProjectBuildMarkers();

IProject project = getProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.operations.AbstractToolsManager;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;

Expand All @@ -35,7 +36,7 @@ public static GoToolManager getDefault() {
/* ----------------- ----------------- */

public ExternalProcessResult runBuildTool(GoEnvironment goEnv, IProgressMonitor pm, Location workingDir,
List<String> commandLine) throws CoreException {
List<String> commandLine) throws CoreException, OperationCancellation {

ProcessBuilder pb = goEnv.createProcessBuilder(commandLine, workingDir.path);
return runTool(null, pm, pb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import melnorme.lang.ide.ui.tools.console.DaemonToolMessageConsole;
import melnorme.lang.tooling.ast.SourceRange;
import melnorme.lang.tooling.ops.FindDefinitionResult;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;

Expand Down Expand Up @@ -47,7 +48,7 @@ protected void prepareOperation() throws CoreException {

@Override
protected FindDefinitionResult performLongRunningComputation_doAndGetResult(IProgressMonitor monitor)
throws CoreException {
throws CoreException, OperationCancellation {
String goOraclePath = GoToolPreferences.GO_ORACLE_Path.get();

GoEnvironment goEnv = GoProjectEnvironment.getGoEnvironment(project);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
/*******************************************************************************
* Copyright (c) 2015, 2015 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package com.googlecode.goclipse.ui.actions;

import melnorme.lang.ide.core.utils.EclipseUtils;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;

Expand All @@ -9,7 +21,7 @@
import com.googlecode.goclipse.tooling.env.GoEnvironment;
import com.googlecode.goclipse.tooling.gocode.GocodeCompletionOperation;

public class GocodeClient extends GocodeCompletionOperation<CommonException> {
public class GocodeClient extends GocodeCompletionOperation {

protected final IProgressMonitor pm;

Expand All @@ -19,7 +31,10 @@ public GocodeClient(String gocodePath, GoEnvironment goEnvironment, IProgressMon
}

@Override
protected ExternalProcessResult runGocodeProcess(ProcessBuilder pb, String input) throws CommonException {
protected ExternalProcessResult runGocodeProcess(ProcessBuilder pb, String input)
throws CommonException, OperationCancellation {
EclipseUtils.checkMonitorCancelation(pm);

return GoToolManager.getDefault().new RunEngineClientOperation(pb, pm).doRunProcess(input, false);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.googlecode.goclipse.ui.editor;

import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;

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

import melnorme.lang.ide.core.LangCore;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.StringUtil;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;
Expand Down Expand Up @@ -51,8 +54,7 @@ public GocodeCompletionProposalComputer(IEditorPart editor, String filePath, int
}

@Override
public ICompletionProposal[] computeCompletionProposals()
throws CoreException {
public ICompletionProposal[] computeCompletionProposals() throws CoreException {

ArrayList<ICompletionProposal> results = new ArrayList<ICompletionProposal>();

Expand All @@ -67,23 +69,15 @@ public ICompletionProposal[] computeCompletionProposals()
String stdout = processResult.getStdOutBytes().toString(StringUtil.UTF8);
List<String> completions = new ArrayList2<>(GocodeClient.LINE_SPLITTER.split(stdout));

// CodeContext codeContext = codeContexts.get(filePath);
// if (codeContext == null) {
// try {
// codeContext = CodeContext.getCodeContext(project, filePath, document.get());
// } catch (IOException e) {
// throw LangCore.createCoreException("Error during code Context:", e);
// }
// }


for (String completionEntry : completions) {
handleResult(offset, /*codeContext,*/ results, prefix, completionEntry);
}

return results.toArray(new ICompletionProposal[] {});
} catch (CommonException e) {
throw LangCore.createCoreException(e.getMessage(), e.getCause());
} catch (OperationCancellation e) {
throw LangCore.createCoreException("Timeout invoking content assist.", null);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static melnorme.lang.ide.ui.editor.EditorUtils.getEditorDocument;
import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.ui.actions.AbstractEditorOperation;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;

import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -54,7 +55,7 @@ protected void prepareOperation() throws CoreException {
protected abstract void prepareProcessBuilder(GoEnvironment goEnv) throws CoreException;

@Override
protected void performLongRunningComputation_do(IProgressMonitor pm) throws CoreException {
protected void performLongRunningComputation_do(IProgressMonitor pm) throws CoreException, OperationCancellation {

IProject project = null;
ExternalProcessResult processResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import java.util.regex.Pattern;

import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;

import com.googlecode.goclipse.tooling.env.GoEnvironment;


public abstract class GocodeCompletionOperation<EXC extends Exception> {
public abstract class GocodeCompletionOperation {

public static final boolean USE_TCP = true;

Expand All @@ -31,7 +32,7 @@ public GocodeCompletionOperation(GoEnvironment goEnvironment, String gocodePath)
this.gocodePath = gocodePath;
}

protected void setLibPathForEnvironment() throws CommonException, EXC {
protected void setLibPathForEnvironment() throws CommonException, OperationCancellation {

ArrayList2<String> arguments = new ArrayList2<>(gocodePath);

Expand All @@ -47,7 +48,8 @@ protected void setLibPathForEnvironment() throws CommonException, EXC {
runGocodeProcess(pb, null);
}

public ExternalProcessResult execute(String filePath, String bufferText, int offset) throws CommonException, EXC {
public ExternalProcessResult execute(String filePath, String bufferText, int offset)
throws CommonException, OperationCancellation {

setLibPathForEnvironment();

Expand All @@ -72,7 +74,8 @@ public ExternalProcessResult execute(String filePath, String bufferText, int off
return processResult;
}

protected abstract ExternalProcessResult runGocodeProcess(ProcessBuilder pb, String input) throws CommonException;
protected abstract ExternalProcessResult runGocodeProcess(ProcessBuilder pb, String input)
throws CommonException, OperationCancellation;

// TODO: move the code that process gocode result to here

Expand Down

0 comments on commit b88c73b

Please sign in to comment.