Skip to content

Commit

Permalink
Filter and fill some value for Java (server) snippet
Browse files Browse the repository at this point in the history
Fixes redhat-developer#265

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Mar 31, 2020
1 parent eed5a4b commit c1f9b46
Show file tree
Hide file tree
Showing 30 changed files with 1,083 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<delegateCommandHandler class="com.redhat.microprofile.jdt.internal.core.ls.MicroProfileDelegateCommandHandlerForJava">
<command id="microprofile/java/codeAction"/>
<command id="microprofile/java/codeLens"/>
<command id="microprofile/java/completion"/>
<command id="microprofile/java/diagnostics"/>
<command id="microprofile/java/hover"/>
</delegateCommandHandler>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.microprofile.commons;

/**
* The java element scope.
*
* @author Angelo ZERR
*
*/
public enum JavaScope {

UNKNOWN(0), ANY(1), TYPE(2), METHOD(3), FIELD(4), PARAMETER(5), ANNOTATION_TYPE(6);

private final int value;

JavaScope(int value) {
this.value = value;
}

public int getValue() {
return value;
}

public static JavaScope forValue(int value) {
JavaScope[] allValues = JavaScope.values();
if (value < 1 || value > allValues.length)
throw new IllegalArgumentException("Illegal enum value: " + value);
return allValues[value - 1];
}

public static JavaScope getScope(String scope) {
if (scope != null) {
scope = scope.toUpperCase();
try {
return JavaScope.valueOf(scope);
} catch (Exception e) {
// Do nothing
}
}
return UNKNOWN;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.microprofile.commons;

import org.eclipse.lsp4j.Position;

/**
* MicroProfile Java completion parameters.
*
* @author Angelo ZERR
*
*/
public class MicroProfileJavaCompletionParams {

private String uri;
private Position position;
private boolean collectProjectDependencies;

public MicroProfileJavaCompletionParams() {

}

public MicroProfileJavaCompletionParams(String uri, Position position) {
this();
setUri(uri);
setPosition(position);
}

/**
* Returns the java file uri.
*
* @return the java file uri.
*/
public String getUri() {
return uri;
}

/**
* Set the java file uri.
*
* @param uri the java file uri.
*/
public void setUri(String uri) {
this.uri = uri;
}

/**
* Returns the completion position
*
* @return the completion position
*/
public Position getPosition() {
return position;
}

/**
* Sets the completion position
*
* @param position the completion position
*/
public void setPosition(Position position) {
this.position = position;
}

public boolean isCollectProjectDependencies() {
return collectProjectDependencies;
}

public void setCollectProjectDependencies(boolean collectProjectDependencies) {
this.collectProjectDependencies = collectProjectDependencies;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2020 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.microprofile.commons;

import java.util.List;

/**
* MicroProfile Java completion result.
*
* @author Angelo ZERR
*
*/
public class MicroProfileJavaCompletionResult {

private JavaScope scope;

private String projectURI;

private List<String> projectDependencies;

/**
* Returns the java scope according to the completion offset.
*
* @return the java scope according to the completion offset.
*/
public JavaScope getScope() {
return scope;
}

public void setScope(JavaScope scope) {
this.scope = scope;
}

public String getProjectURI() {
return projectURI;
}

public void setProjectURI(String projectURI) {
this.projectURI = projectURI;
}

/**
* Returns the project dependencies.
*
* @return the project dependencies.
*/
public List<String> getProjectDependencies() {
return projectDependencies;
}

public void setProjectDependencies(List<String> projectDependencies) {
this.projectDependencies = projectDependencies;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.CodeLens;
import org.eclipse.lsp4j.Command;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.PublishDiagnosticsParams;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

import com.redhat.microprofile.commons.DocumentFormat;
import com.redhat.microprofile.commons.MicroProfileJavaCodeActionParams;
import com.redhat.microprofile.commons.MicroProfileJavaCodeLensParams;
import com.redhat.microprofile.commons.MicroProfileJavaCompletionParams;
import com.redhat.microprofile.commons.MicroProfileJavaCompletionResult;
import com.redhat.microprofile.commons.MicroProfileJavaDiagnosticsParams;
import com.redhat.microprofile.commons.MicroProfileJavaHoverParams;
import com.redhat.microprofile.jdt.core.java.codelens.JavaCodeLensContext;
Expand All @@ -41,6 +41,7 @@
import com.redhat.microprofile.jdt.internal.core.java.JavaFeaturesRegistry;
import com.redhat.microprofile.jdt.internal.core.java.codeaction.CodeActionHandler;
import com.redhat.microprofile.jdt.internal.core.java.codelens.JavaCodeLensDefinition;
import com.redhat.microprofile.jdt.internal.core.java.completion.CompletionHandler;
import com.redhat.microprofile.jdt.internal.core.java.diagnostics.JavaDiagnosticsDefinition;
import com.redhat.microprofile.jdt.internal.core.java.hover.JavaHoverDefinition;

Expand All @@ -60,8 +61,11 @@ public static PropertiesManagerForJava getInstance() {

private final CodeActionHandler codeActionHandler;

private final CompletionHandler completionHandler;

private PropertiesManagerForJava() {
this.codeActionHandler = new CodeActionHandler();
this.completionHandler = new CompletionHandler();
}

/**
Expand Down Expand Up @@ -124,6 +128,20 @@ private void collectCodeLens(String uri, ITypeRoot typeRoot, IJDTUtils utils, Mi
definitions.forEach(definition -> definition.endCodeLens(context, monitor));
}

/**
* Returns completion result for the given uri and position.
*
* @param params the completion parameters
* @param utils the utilities class
* @param monitor the monitor
* @return completion result for the given uri and position.
* @throws JavaModelException
*/
public MicroProfileJavaCompletionResult completion(MicroProfileJavaCompletionParams params, IJDTUtils utils,
IProgressMonitor monitor) throws JavaModelException {
return completionHandler.completion(params, utils, monitor);
}

/**
* Returns diagnostics for the given uris list.
*
Expand Down
Loading

0 comments on commit c1f9b46

Please sign in to comment.