Skip to content

Commit

Permalink
kie-issues#114: JavaCodeCompletion module fails to compile because of…
Browse files Browse the repository at this point in the history
… API change (#2453)
  • Loading branch information
yesamer authored Jul 1, 2024
1 parent 370460d commit 5372b59
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ const TableJavaClassItem = ({
const [isExpanded, setExpanded] = useState(true);

const isFetchable = useCallback((field: JavaField) => {
/* Temporary disable isFetchable, because we need FQCN of the Classes, no longer avaialble */
/* https://github.com/apache/incubator-kie-issues/issues/114 */
return false;
//return field.dmnTypeRef === DMNSimpleType.ANY && !JAVA_TO_DMN_MAP.has(getJavaClassSimpleName(field.type));
return field.dmnTypeRef === DMNSimpleType.ANY && !JAVA_TO_DMN_MAP.has(getJavaClassSimpleName(field.type));
}, []);

const parentRow = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ describe("ImportJavaClasses component tests", () => {
expect(baseElement).toMatchSnapshot();
});

/* Renable in https://github.com/apache/incubator-kie-issues/issues/114 */
test.skip("Should move to second step and fetch a Java Class", async () => {
test("Should move to second step and fetch a Java Class", async () => {
const { baseElement, getByText } = render(
<ImportJavaClasses
gwtLayerService={gwtLayerServiceMock}
Expand All @@ -145,8 +144,7 @@ describe("ImportJavaClasses component tests", () => {
expect(baseElement).toMatchSnapshot();
});

/* Renable in https://github.com/apache/incubator-kie-issues/issues/114 */
test.skip("Should move to second step and fetch, remove a Java Class", async () => {
test("Should move to second step and fetch, remove a Java Class", async () => {
const { baseElement, getByText } = render(
<ImportJavaClasses
gwtLayerService={gwtLayerServiceMock}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ exports[`ImportJavaClasses component tests Should move to second step 1`] = `
>
(Any)
</span>
<button
aria-disabled="false"
class="pf-c-button pf-m-primary pf-m-small fetch-button"
data-ouia-component-id="OUIA-Generated-Button-primary-6"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
>
Fetch "Test" class
</button>
</div>
</td>
</tr>
Expand Down Expand Up @@ -1057,7 +1067,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
<button
aria-disabled="false"
class="pf-c-button pf-m-secondary pf-m-progress"
data-ouia-component-id="OUIA-Generated-Button-secondary-8"
data-ouia-component-id="OUIA-Generated-Button-secondary-13"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
data-testid="modal-wizard-button"
Expand All @@ -1074,21 +1084,21 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
class="pf-l-bullseye"
>
<div
aria-describedby="pf-modal-part-7"
aria-labelledby="pf-modal-part-6"
aria-describedby="pf-modal-part-9"
aria-labelledby="pf-modal-part-8"
aria-modal="true"
class="pf-c-modal-box pf-m-lg"
data-ouia-component-id="OUIA-Generated-Modal-large-6"
data-ouia-component-id="OUIA-Generated-Modal-large-8"
data-ouia-component-type="PF4/ModalContent"
data-ouia-safe="true"
id="pf-modal-part-5"
id="pf-modal-part-7"
role="dialog"
>
<button
aria-disabled="false"
aria-label="Close"
class="pf-c-button pf-m-plain"
data-ouia-component-id="OUIA-Generated-Modal-large-6-ModalBoxCloseButton"
data-ouia-component-id="OUIA-Generated-Modal-large-8-ModalBoxCloseButton"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
Expand All @@ -1112,7 +1122,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
>
<h1
class="pf-c-modal-box__title"
id="pf-modal-part-6"
id="pf-modal-part-8"
>
<span
Expand All @@ -1123,7 +1133,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
</h1>
<div
class="pf-c-modal-box__description"
id="pf-modal-part-7"
id="pf-modal-part-9"
>
It converts your Java assets to DMN types. This is a one-time import action: if the Java class gets updated, you will need to reimport it.
</div>
Expand Down Expand Up @@ -1181,7 +1191,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
>
<nav
class="pf-c-wizard__nav"
data-ouia-component-id="OUIA-Generated-WizardNav-6"
data-ouia-component-id="OUIA-Generated-WizardNav-8"
data-ouia-component-type="PF4/WizardNav"
data-ouia-safe="true"
>
Expand All @@ -1194,7 +1204,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
<button
aria-current="false"
class="pf-c-wizard__nav-link"
data-ouia-component-id="OUIA-Generated-WizardNavItem-16"
data-ouia-component-id="OUIA-Generated-WizardNavItem-22"
data-ouia-component-type="PF4/WizardNavItem"
data-ouia-safe="true"
>
Expand All @@ -1207,7 +1217,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
<button
aria-current="false"
class="pf-c-wizard__nav-link"
data-ouia-component-id="OUIA-Generated-WizardNavItem-17"
data-ouia-component-id="OUIA-Generated-WizardNavItem-23"
data-ouia-component-type="PF4/WizardNavItem"
data-ouia-safe="true"
>
Expand All @@ -1220,7 +1230,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
<button
aria-current="step"
class="pf-c-wizard__nav-link pf-m-current"
data-ouia-component-id="OUIA-Generated-WizardNavItem-18"
data-ouia-component-id="OUIA-Generated-WizardNavItem-24"
data-ouia-component-type="PF4/WizardNavItem"
data-ouia-safe="true"
>
Expand All @@ -1241,7 +1251,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
<table
aria-label="field-table"
class="pf-c-table pf-m-grid-md"
data-ouia-component-id="OUIA-Generated-Table-3"
data-ouia-component-id="OUIA-Generated-Table-8"
data-ouia-component-type="PF4/Table"
data-ouia-safe="true"
role="grid"
Expand All @@ -1252,7 +1262,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
>
<tr
class=""
data-ouia-component-id="OUIA-Generated-TableRow-15"
data-ouia-component-id="OUIA-Generated-TableRow-52"
data-ouia-component-type="PF4/TableRow"
data-ouia-safe="true"
>
Expand All @@ -1265,7 +1275,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
aria-label="Details"
aria-labelledby="simple-node0 expand-toggle0"
class="pf-c-button pf-m-plain pf-m-expanded"
data-ouia-component-id="OUIA-Generated-Button-plain-15"
data-ouia-component-id="OUIA-Generated-Button-plain-29"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
id="expand-toggle0"
Expand Down Expand Up @@ -1307,7 +1317,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
</tr>
<tr
class="pf-c-table__expandable-row pf-m-expanded"
data-ouia-component-id="OUIA-Generated-TableRow-16"
data-ouia-component-id="OUIA-Generated-TableRow-53"
data-ouia-component-type="PF4/TableRow"
data-ouia-safe="true"
>
Expand All @@ -1333,7 +1343,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
</tr>
<tr
class="pf-c-table__expandable-row pf-m-expanded"
data-ouia-component-id="OUIA-Generated-TableRow-17"
data-ouia-component-id="OUIA-Generated-TableRow-54"
data-ouia-component-type="PF4/TableRow"
data-ouia-safe="true"
>
Expand Down Expand Up @@ -1364,7 +1374,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
>
<tr
class=""
data-ouia-component-id="OUIA-Generated-TableRow-18"
data-ouia-component-id="OUIA-Generated-TableRow-55"
data-ouia-component-type="PF4/TableRow"
data-ouia-safe="true"
>
Expand All @@ -1377,7 +1387,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
aria-label="Details"
aria-labelledby="simple-node1 expand-toggle1"
class="pf-c-button pf-m-plain pf-m-expanded"
data-ouia-component-id="OUIA-Generated-Button-plain-16"
data-ouia-component-id="OUIA-Generated-Button-plain-30"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
id="expand-toggle1"
Expand Down Expand Up @@ -1419,7 +1429,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
</tr>
<tr
class="pf-c-table__expandable-row pf-m-expanded"
data-ouia-component-id="OUIA-Generated-TableRow-19"
data-ouia-component-id="OUIA-Generated-TableRow-56"
data-ouia-component-type="PF4/TableRow"
data-ouia-safe="true"
>
Expand All @@ -1445,7 +1455,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
</tr>
<tr
class="pf-c-table__expandable-row pf-m-expanded"
data-ouia-component-id="OUIA-Generated-TableRow-20"
data-ouia-component-id="OUIA-Generated-TableRow-57"
data-ouia-component-type="PF4/TableRow"
data-ouia-safe="true"
>
Expand All @@ -1471,7 +1481,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
</tr>
<tr
class="pf-c-table__expandable-row pf-m-expanded"
data-ouia-component-id="OUIA-Generated-TableRow-21"
data-ouia-component-id="OUIA-Generated-TableRow-58"
data-ouia-component-type="PF4/TableRow"
data-ouia-safe="true"
>
Expand Down Expand Up @@ -1507,7 +1517,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
<button
aria-disabled="false"
class="pf-c-button pf-m-primary"
data-ouia-component-id="OUIA-Generated-Button-primary-6"
data-ouia-component-id="OUIA-Generated-Button-primary-12"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="submit"
Expand All @@ -1517,7 +1527,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
<button
aria-disabled="false"
class="pf-c-button pf-m-secondary"
data-ouia-component-id="OUIA-Generated-Button-secondary-9"
data-ouia-component-id="OUIA-Generated-Button-secondary-14"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
Expand All @@ -1530,7 +1540,7 @@ exports[`ImportJavaClasses component tests Should move to third step 1`] = `
<button
aria-disabled="false"
class="pf-c-button pf-m-link"
data-ouia-component-id="OUIA-Generated-Button-link-6"
data-ouia-component-id="OUIA-Generated-Button-link-8"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@
import org.kogito.core.internal.handlers.Handler;
import org.kogito.core.internal.handlers.HandlerConstants;
import org.kogito.core.internal.handlers.IsLanguageServerAvailableHandler;
import org.kogito.core.internal.handlers.TypeHierarchyHandler;

public class DelegateHandler implements IDelegateCommandHandler {

private static final JavaEngine JAVA_ENGINE = new JavaEngine();
private static final ActivationChecker ACTIVATION_CHECKER = new ActivationChecker();
private static final AutocompleteHandler AUTOCOMPLETE_HANDLER = new AutocompleteHandler(ACTIVATION_CHECKER);
private static final TypeHierarchyHandler TYPE_HIERARCHY_HANDLER = new TypeHierarchyHandler(ACTIVATION_CHECKER);
private final IsLanguageServerAvailableHandler isAvailableHandler;

private static final List<Handler<?>> handlers = List.of(
new GetClassesHandler(HandlerConstants.GET_CLASSES, JAVA_ENGINE, AUTOCOMPLETE_HANDLER),
new GetAccessorsHandler(HandlerConstants.GET_ACCESSORS, JAVA_ENGINE, AUTOCOMPLETE_HANDLER));
new GetAccessorsHandler(HandlerConstants.GET_ACCESSORS, JAVA_ENGINE, AUTOCOMPLETE_HANDLER, TYPE_HIERARCHY_HANDLER));

public DelegateHandler() {
ACTIVATION_CHECKER.check();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,22 @@

package org.kogito.core.internal.api;

/**
* Must be synchronized with JavaCodeCompletionAccessor.ts
*/
public class GetPublicResult {

/**
* The Java Class that cointans the below accessor in FQCN format (eg. `org.Author`)
*/
private String fqcn;
/**
* Accessor's name (eg. `getName()` if a method, `name` if a field
*/
private String accessor;

/**
* Accessor's type in FQCN format (eg. `java.lang.String`)
*/
private String type;

public String getFqcn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import freemarker.template.Configuration;
import freemarker.template.Template;
Expand Down Expand Up @@ -77,9 +75,30 @@ public BuildInformation buildPublicContent(Path filePath, String fqcn, String co
return new BuildInformation(filePath, getContent(filePath), content, 5, getEndOfLinePosition(content, 5));
}

public BuildInformation buildVarTypePublicContent(Path filePath, String fqcn, String completeText) {

TemplateParameters item = new TemplateParameters();
item.setClassName(getClassName(filePath));
item.setQuery(completeText);
item.setFqcn(fqcn);

String content = this.evaluate(Templates.TEMPLATE_ACCESSORS, item);
int varLine = 5;
int varMiddleChar = 2;

return new BuildInformation(filePath, getContent(filePath), content, varLine, getFirstCharInLinePosition(content, varLine) + varMiddleChar);
}

protected int getFirstCharInLinePosition(String content, int lineNumber) {
String[] split = content.split("\n");
String line = split[lineNumber];
int index = line.indexOf(line.trim());

return index + 1;
}

protected int getEndOfLinePosition(String content, int lineNumber) {
String[] split = content.split("\n");
JavaLanguageServerPlugin.logInfo(split[lineNumber]);
return split[lineNumber].length();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.lsp4j.CompletionParams;
import org.eclipse.lsp4j.CompletionTriggerKind;
import org.eclipse.lsp4j.DidChangeTextDocumentParams;
import org.eclipse.lsp4j.DidCloseTextDocumentParams;
import org.eclipse.lsp4j.DidOpenTextDocumentParams;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.TextDocumentContentChangeEvent;
Expand Down Expand Up @@ -117,6 +118,10 @@ public List<CompletionItem> handle(String identifier, BuildInformation buildInfo
} catch (Exception e) {
JavaLanguageServerPlugin.logException("Problem with " + identifier, e);
return Collections.emptyList();
} finally {
DidCloseTextDocumentParams didCloseTextDocumentParams = new DidCloseTextDocumentParams();
didCloseTextDocumentParams.setTextDocument(textDocumentIdentifier);
languageServer.didClose(didCloseTextDocumentParams);
}
}

Expand Down
Loading

0 comments on commit 5372b59

Please sign in to comment.