Search in sources :

Example 1 with MethodParameters

use of org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters in project che by eclipse.

the class ParametersHints method findHints.

private void findHints(IJavaElement method, IJavaElement parent, List<MethodParameters> result) throws JavaModelException {
    String methodName = method.getElementName();
    for (IMethod iMethod : ((IType) parent).getMethods()) {
        int methodFlag = iMethod.getFlags();
        if (Flags.isPrivate(methodFlag) || !methodName.equals(iMethod.getElementName())) {
            continue;
        }
        MethodParameters methodParameters = DtoFactory.newDto(MethodParameters.class);
        String parameters = getMethodParametersAsString(iMethod);
        methodParameters.setMethodName(methodName);
        methodParameters.setParameters(parameters);
        if (!result.contains(methodParameters)) {
            result.add(methodParameters);
        }
    }
}
Also used : IMethod(org.eclipse.jdt.core.IMethod) MethodParameters(org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters) IType(org.eclipse.jdt.core.IType)

Example 2 with MethodParameters

use of org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters in project che by eclipse.

the class ParametersHintsPresenter method show.

/**
     * The method gets method parameters via {@link JavaNavigationService} and then call special method on view to display them.
     *
     * @param activeEditor
     *         active editor which contains method or constructor for which parameters will be displayed
     */
public void show(final TextEditor activeEditor) {
    final int offset = activeEditor.getCursorOffset();
    if (!isCursorInRightPlace(activeEditor, offset)) {
        return;
    }
    VirtualFile file = activeEditor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        final int lineStartOffset = getLineStartOffset(activeEditor, offset);
        navigationService.getMethodParametersHints(project.get().getLocation(), JavaUtil.resolveFQN(file), offset, lineStartOffset).then(new Operation<List<MethodParameters>>() {

            @Override
            public void apply(List<MethodParameters> parameters) throws OperationException {
                if (parameters.isEmpty()) {
                    return;
                }
                PositionConverter.PixelCoordinates coordinates = activeEditor.getPositionConverter().offsetToPixel(offset);
                view.show(parameters, coordinates.getX(), coordinates.getY());
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                Log.error(getClass(), error.getMessage());
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) List(java.util.List) MethodParameters(org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters) PositionConverter(org.eclipse.che.ide.api.editor.position.PositionConverter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with MethodParameters

use of org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters in project che by eclipse.

the class ParametersHintsViewImpl method show.

@Override
public void show(List<MethodParameters> parametersList, int x, int y) {
    parametersPanel.clear();
    for (MethodParameters parameters : parametersList) {
        FlowPanel widget = panelsProvider.get();
        String parametersLine = parameters.getParameters();
        if (parametersLine.isEmpty()) {
            parametersLine = "<no parameters>";
        }
        String result = parametersLine.replace("<", "&lt").replace(">", "&gt");
        Element element = widget.getElement();
        element.setInnerHTML(result);
        element.getStyle().setColor("yellow");
        parametersPanel.add(widget);
    }
    setPopupPosition(x, y);
    show();
}
Also used : Element(com.google.gwt.dom.client.Element) FlowPanel(com.google.gwt.user.client.ui.FlowPanel) MethodParameters(org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters)

Example 4 with MethodParameters

use of org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters in project che by eclipse.

the class ParametersHints method findHints.

public List<MethodParameters> findHints(IJavaProject project, String fqn, int offset, int lineStartOffset) throws JavaModelException {
    IType type = project.findType(fqn);
    if (type.isBinary()) {
        return Collections.emptyList();
    }
    IJavaElement element = getSelectedElement(type, offset, lineStartOffset);
    if (element == null) {
        return Collections.emptyList();
    }
    IJavaElement parent = element.getParent();
    if (!(parent instanceof IType) || !(element.getElementType() == METHOD)) {
        return Collections.emptyList();
    }
    List<MethodParameters> result = new ArrayList<>();
    findHintsRecursive(element, parent, result);
    return result;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ArrayList(java.util.ArrayList) MethodParameters(org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters) IType(org.eclipse.jdt.core.IType)

Aggregations

MethodParameters (org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters)4 IType (org.eclipse.jdt.core.IType)2 Element (com.google.gwt.dom.client.Element)1 FlowPanel (com.google.gwt.user.client.ui.FlowPanel)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 PositionConverter (org.eclipse.che.ide.api.editor.position.PositionConverter)1 Project (org.eclipse.che.ide.api.resources.Project)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IMethod (org.eclipse.jdt.core.IMethod)1