Skip to content

Commit

Permalink
use jdt.ls to support Rename refactoring (#9636)
Browse files Browse the repository at this point in the history
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
  • Loading branch information
Valeriy Svydenko authored and tsmaeder committed Sep 13, 2018
1 parent 096897d commit aac7989
Show file tree
Hide file tree
Showing 31 changed files with 1,320 additions and 2,298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ public interface Container extends Resource {
*/
Promise<Optional<Container>> getContainer(String relativePath);

/**
* Returns the {@code Promise} with handle to the resource identified by the given path in this
* container.
*
* <p>The supplied path should represent relative path to resource.
*
* @param relativePath the path of the member resource
* @return the {@code Promise} with the handle of the member resource
* @throws IllegalStateException if during resource search failed has been occurred. Reasons
* include:
* <ul>
* <li>Resource with path '/project_path' doesn't exists
* <li>Resource with path '/project_path' isn't a project
* </ul>
*
* @see #getFile(Path)
*/
Promise<Optional<Resource>> getResource(Path relativePath);

/**
* Returns the {@code Promise} with array of existing member resources (projects, folders and
* files) in this resource, in particular order. Order is organized by alphabetic resource name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public Promise<Optional<Container>> getContainer(String relativePath) {
return resourceManager.getContainer(getLocation().append(relativePath));
}

@Override
public Promise<Optional<Resource>> getResource(Path relativePath) {
return resourceManager.getResource(getLocation().append(relativePath));
}

/** {@inheritDoc} */
@Override
public Promise<Resource[]> getChildren(final boolean forceUpdate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ Promise<Optional<Container>> getContainer(final Path absolutePath) {
});
}

protected Promise<Optional<Resource>> getResource(final Path absolutePath) {
return findResource(absolutePath);
}

protected Promise<Optional<File>> getFile(final Path absolutePath) {
final Optional<Resource> resourceOptional = store.getResource(absolutePath);

Expand Down
8 changes: 8 additions & 0 deletions plugins/plugin-java/che-plugin-java-ext-lang-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j.jsonrpc</artifactId>
</dependency>
<dependency>
<groupId>org.vectomatic</groupId>
<artifactId>lib-gwt-svg</artifactId>
Expand Down Expand Up @@ -317,6 +321,10 @@
<dtoPackages>
<dtoPackage>org.eclipse.che.jdt.ls.extension.api.dto</dtoPackage>
</dtoPackages>
<classes>
<class>org.eclipse.che.jdt.ls.extension.api.dto.CheResourceChange</class>
<class>org.eclipse.che.jdt.ls.extension.api.dto.CheWorkspaceEdit</class>
</classes>
<excludes>
<exclude>org.eclipse.che.jdt.ls.extension.api.dto.LinearRange</exclude>
</excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public class PomDiagnosticsRequestor {
@Inject
public PomDiagnosticsRequestor(
final EventBus eventBus,
DtoBuildHelper buildHelper,
final DtoBuildHelper buildHelper,
final JavaLanguageExtensionServiceClient service) {
eventBus.addHandler(
EditorOpenedEvent.TYPE,
new EditorOpenedEventHandler() {
@Override
public void onEditorOpened(EditorOpenedEvent event) {
String uri = buildHelper.getUri(event.getFile());
if (uri.endsWith(POM_FILE)) {
if (!uri.endsWith(POM_FILE)) {
return;
}
new Timer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* 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:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.ide.ext.java.client.refactoring;

/**
* Describes actions which should be supported by refactoring wizards.
*
* @author Valeriy Svydenko
*/
public interface RefactoringActionDelegate {
/** Closes wizard's window. */
void closeWizard();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.che.ide.ext.java.client.JavaLocalizationConstant;
import org.eclipse.che.ide.ext.java.client.navigation.service.JavaNavigationService;
import org.eclipse.che.ide.ext.java.client.refactoring.RefactorInfo;
import org.eclipse.che.ide.ext.java.client.refactoring.RefactoringActionDelegate;
import org.eclipse.che.ide.ext.java.client.refactoring.RefactoringUpdater;
import org.eclipse.che.ide.ext.java.client.refactoring.preview.PreviewPresenter;
import org.eclipse.che.ide.ext.java.client.refactoring.service.RefactoringServiceClient;
Expand All @@ -62,7 +63,7 @@
* @author Valeriy Svydenko
*/
@Singleton
public class MovePresenter implements MoveView.ActionDelegate {
public class MovePresenter implements MoveView.ActionDelegate, RefactoringActionDelegate {
private final MoveView view;
private final RefactoringUpdater refactoringUpdater;
private final EditorAgent editorAgent;
Expand Down Expand Up @@ -365,4 +366,10 @@ private void showErrorMessage(RefactoringStatus arg) {
view.setEnableAcceptButton(false);
view.setEnablePreviewButton(false);
}

@Override
public void closeWizard() {
view.close();
onCancelButtonClicked();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2012-2018 Red Hat, Inc.
* 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:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.ide.ext.java.client.refactoring.preview;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.lsp4j.ResourceChange;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.jsonrpc.messages.Either;

/**
* Describes a node from the tree of changes in Preview page.
*
* @author Valeriy Svydenko
*/
public class PreviewNode {
private String id;
private String description;
private boolean enable;
private Either<ResourceChange, TextEdit> data;
private List<PreviewNode> children;
private PreviewNode parent;
private String uri;

public PreviewNode() {
this.children = new ArrayList<>();
}

/** Returns id of node. */
public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

/** Returns description which describes current node. */
public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

/** Returns {@code true} if node is chose otherwise returns {@code false}. */
public boolean isEnable() {
return enable;
}

public void setEnable(boolean enable) {
this.enable = enable;
}

/** Returns data of current node it can be {@link ResourceChange} or {@link TextEdit}. */
public Either<ResourceChange, TextEdit> getData() {
return data;
}

public void setData(Either<ResourceChange, TextEdit> data) {
this.data = data;
}

/** Returns list of children. */
public List<PreviewNode> getChildren() {
return children;
}

public void setChildren(List<PreviewNode> children) {
this.children = children;
}

/** Returns parent node if current node is leaf or null if it isn't. */
public PreviewNode getParent() {
return parent;
}

public void setParent(PreviewNode parent) {
this.parent = parent;
}

public boolean hasParent() {
return parent != null;
}

/** Returns uri of the resource which is related to current change. */
public String getUri() {
return uri;
}

public void setUri(String uri) {
this.uri = uri;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
PreviewNode other = (PreviewNode) obj;
if (this.children == null) {
if (other.children != null) return false;
} else if (!this.children.equals(other.children)) return false;
if (this.id == null) {
if (other.id != null) return false;
} else if (!this.id.equals(other.id)) return false;
if (this.uri == null) {
if (other.uri != null) return false;
} else if (!this.uri.equals(other.uri)) return false;
return true;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.children == null) ? 0 : this.children.hashCode());
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
result = prime * result + ((this.uri == null) ? 0 : this.uri.hashCode());
return result;
}
}
Loading

0 comments on commit aac7989

Please sign in to comment.