forked from redhat-developer/quarkus-ls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See redhat-developer#229 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
a7ac0e1
commit 580b5b9
Showing
12 changed files
with
300 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...e.jdt.core/src/main/java/com/redhat/microprofile/jdt/core/java/IJavaHoverParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************* | ||
* 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.jdt.core.java; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
|
||
/** | ||
* Java hover participants API. | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public interface IJavaHoverParticipant { | ||
|
||
/** | ||
* Returns true if hover must be collected for the given context and false | ||
* otherwise. | ||
* | ||
* <p> | ||
* Collection is done by default. Participants can override this to check if | ||
* some classes are on the classpath before deciding to process the collection. | ||
* </p> | ||
* | ||
* @param the java hover context | ||
* @param monitor the progress monitor | ||
* @return true if hover must be collected for the given context and false | ||
* otherwise. | ||
* @throws JavaModelException | ||
*/ | ||
default boolean isAdaptedForHover(JavaHoverContext context, IProgressMonitor monitor) throws JavaModelException { | ||
return true; | ||
} | ||
|
||
/** | ||
* Collect hover according to the context. | ||
* | ||
* @param context the java hover context | ||
* @param monitor the progress monitor | ||
* @throws JavaModelException | ||
* @throws CoreException | ||
*/ | ||
void collectHover(JavaHoverContext context, IProgressMonitor monitor) throws JavaModelException, CoreException; | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...rofile.jdt.core/src/main/java/com/redhat/microprofile/jdt/core/java/JavaHoverContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************* | ||
* 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.jdt.core.java; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jdt.core.ITypeRoot; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
import org.eclipse.lsp4j.Range; | ||
|
||
import com.redhat.microprofile.commons.DocumentFormat; | ||
import com.redhat.microprofile.jdt.core.utils.IJDTUtils; | ||
|
||
/** | ||
* Java hover context for a given compilation unit. | ||
* | ||
* @author Angelo ZERR | ||
* | ||
*/ | ||
public class JavaHoverContext extends AbtractJavaContext { | ||
|
||
private final List<Diagnostic> hover; | ||
|
||
private final DocumentFormat documentFormat; | ||
|
||
public JavaHoverContext(String uri, ITypeRoot typeRoot, IJDTUtils utils, DocumentFormat documentFormat, | ||
List<Diagnostic> hover) { | ||
super(uri, typeRoot, utils); | ||
this.hover = hover; | ||
this.documentFormat = documentFormat; | ||
} | ||
|
||
public List<Diagnostic> getHover() { | ||
return hover; | ||
} | ||
|
||
public DocumentFormat getDocumentFormat() { | ||
return documentFormat; | ||
} | ||
|
||
public Diagnostic addDiagnostic(String uri, String message, Range range, String source, IJavaErrorCode code) { | ||
Diagnostic diagnostic = createDiagnostic(uri, message, range, source, code); | ||
getHover().add(diagnostic); | ||
return diagnostic; | ||
} | ||
|
||
private Diagnostic createDiagnostic(String uri, String message, Range range, String source, IJavaErrorCode code) { | ||
Diagnostic diagnostic = new Diagnostic(); | ||
diagnostic.setSource(source); | ||
diagnostic.setMessage(message); | ||
diagnostic.setSeverity(DiagnosticSeverity.Warning); | ||
diagnostic.setRange(range); | ||
if (code != null) { | ||
diagnostic.setCode(code.getCode()); | ||
} | ||
return diagnostic; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
.../com/redhat/microprofile/jdt/internal/config/java/MicroProfileConfigHoverParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/******************************************************************************* | ||
* 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.jdt.internal.config.java; | ||
|
||
import static com.redhat.microprofile.jdt.core.MicroProfileConfigConstants.CONFIG_PROPERTY_ANNOTATION; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.jdt.core.IJavaElement; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.core.ITypeRoot; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
|
||
import com.redhat.microprofile.jdt.core.java.IJavaHoverParticipant; | ||
import com.redhat.microprofile.jdt.core.java.JavaHoverContext; | ||
import com.redhat.microprofile.jdt.core.utils.JDTTypeUtils; | ||
|
||
/** | ||
* | ||
* MicroProfile Config Hover | ||
* | ||
* @author Angelo ZERR | ||
* | ||
* @See https://github.com/eclipse/microprofile-config | ||
* | ||
*/ | ||
public class MicroProfileConfigHoverParticipant implements IJavaHoverParticipant { | ||
|
||
@Override | ||
public boolean isAdaptedForHover(JavaHoverContext context, IProgressMonitor monitor) throws JavaModelException { | ||
// Hover is done only if microprofile-config is on the classpath | ||
IJavaProject javaProject = context.getJavaProject(); | ||
return JDTTypeUtils.findType(javaProject, CONFIG_PROPERTY_ANNOTATION) != null; | ||
} | ||
|
||
@Override | ||
public void collectHover(JavaHoverContext context, IProgressMonitor monitor) throws CoreException { | ||
ITypeRoot typeRoot = context.getTypeRoot(); | ||
IJavaElement[] elements = typeRoot.getChildren(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.