Search in sources :

Example 1 with Type

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

the class TypeNode method getChildrenImpl.

@Override
protected Promise<List<Node>> getChildrenImpl() {
    return createFromAsyncRequest(callback -> {
        List<Node> children = new ArrayList<>();
        if (compilationUnit != null && type.isPrimary()) {
            for (ImportDeclaration importDeclaration : compilationUnit.getImports()) {
                createNodeForAllMatches(importDeclaration.getHandleIdentifier(), children);
            }
            for (Type subType : compilationUnit.getTypes()) {
                if (subType == type) {
                    continue;
                }
                children.add(nodeFactory.create(subType, compilationUnit, classFile, matches));
            }
        }
        createNodeForAllMatches(type.getHandleIdentifier(), children);
        for (Initializer initializer : type.getInitializers()) {
            createNodeForAllMatches(initializer.getHandleIdentifier(), children);
        }
        for (Field field : type.getFields()) {
            createNodeForAllMatches(field.getHandleIdentifier(), children);
        }
        final List<Node> typeNodes = type.getTypes().stream().map(subType -> nodeFactory.create(subType, compilationUnit, classFile, matches)).collect(Collectors.toList());
        children.addAll(typeNodes);
        final List<Node> methodNodes = type.getMethods().stream().map(method -> nodeFactory.create(method, matches, compilationUnit, classFile)).collect(Collectors.toList());
        children.addAll(methodNodes);
        Collections.sort(children, new NodeComparator());
        callback.onSuccess(children);
    });
}
Also used : AsyncPromiseHelper.createFromAsyncRequest(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest) Inject(com.google.inject.Inject) Flags(org.eclipse.che.ide.ext.java.client.util.Flags) JavaResources(org.eclipse.che.ide.ext.java.client.JavaResources) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Nullable(org.eclipse.che.commons.annotation.Nullable) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) ImportDeclaration(org.eclipse.che.ide.ext.java.shared.dto.model.ImportDeclaration) Promise(org.eclipse.che.api.promises.client.Promise) NodePresentation(org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation) List(java.util.List) Match(org.eclipse.che.ide.ext.java.shared.dto.search.Match) Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) Node(org.eclipse.che.ide.api.data.tree.Node) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) Map(java.util.Map) Field(org.eclipse.che.ide.ext.java.shared.dto.model.Field) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) ClassFile(org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile) Collections(java.util.Collections) Field(org.eclipse.che.ide.ext.java.shared.dto.model.Field) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) Node(org.eclipse.che.ide.api.data.tree.Node) ArrayList(java.util.ArrayList) ImportDeclaration(org.eclipse.che.ide.ext.java.shared.dto.model.ImportDeclaration)

Example 2 with Type

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

the class OpenImplementationPresenter method openOneImplementation.

private void openOneImplementation(ImplementationsDescriptorDTO implementationsDescriptor, NoImplementationWidget implementationWidget, TextEditor editorPartPresenter) {
    int offset = editorPartPresenter.getCursorOffset();
    PositionConverter.PixelCoordinates coordinates = editorPartPresenter.getPositionConverter().offsetToPixel(offset);
    for (Type type : implementationsDescriptor.getImplementations()) {
        implementationWidget.addItem(type);
    }
    implementationWidget.show(coordinates.getX(), coordinates.getY());
    implementationWidget.asElement().getStyle().setWidth(600 + "px");
}
Also used : Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) PositionConverter(org.eclipse.che.ide.api.editor.position.PositionConverter)

Example 3 with Type

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

the class JavaNavigation method calculateSuperTypes.

private List<Type> calculateSuperTypes(IType type) throws JavaModelException {
    List<Type> superTypes = new ArrayList<>();
    ITypeHierarchy superTypeHierarchy = SuperTypeHierarchyCache.getTypeHierarchy(type);
    if (superTypeHierarchy != null) {
        IType[] superITypes = superTypeHierarchy.getAllSupertypes(type);
        for (IType iType : superITypes) {
            superTypes.add(convertToDTOType(iType));
        }
    }
    return superTypes;
}
Also used : JarEntryType(org.eclipse.che.ide.ext.java.shared.JarEntry.JarEntryType) IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) ArrayList(java.util.ArrayList) IType(org.eclipse.jdt.core.IType)

Example 4 with Type

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

the class JavaTypeHierarchy method findSubTypes.

private void findSubTypes(IJavaElement element, List<Type> implementations) throws JavaModelException {
    IType type = (IType) element;
    ITypeHierarchy typeHierarchy = type.newTypeHierarchy(new NullProgressMonitor());
    IType[] implTypes = typeHierarchy.getAllSubtypes(type);
    for (IType implType : implTypes) {
        Type dto = convertToTypeDTO(implType);
        implementations.add(dto);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) IType(org.eclipse.jdt.core.IType)

Example 5 with Type

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

the class JavaTypeHierarchy method getImplementations.

/**
     * Get all implementations of selected Java Element.
     *
     * @param project
     *         opened project
     * @param fqn
     *         fully qualified name of the class file
     * @param offset
     *         cursor position
     * @return descriptor of the implementations
     * @throws JavaModelException
     *         when JavaModel has a failure
     */
public ImplementationsDescriptorDTO getImplementations(IJavaProject project, String fqn, int offset) throws JavaModelException {
    ImplementationsDescriptorDTO implementationDescriptor = DtoFactory.newDto(ImplementationsDescriptorDTO.class);
    IJavaElement element = getJavaElement(project, fqn, offset);
    if (element == null) {
        return implementationDescriptor.withImplementations(emptyList());
    }
    List<Type> implementations = new ArrayList<>();
    implementationDescriptor.setImplementations(implementations);
    switch(element.getElementType()) {
        case //type
        7:
            findSubTypes(element, implementations);
            implementationDescriptor.setMemberName(element.getElementName());
            break;
        case //method
        9:
            findTypesWithSubMethods(element, implementations);
            implementationDescriptor.setMemberName(element.getElementName());
            break;
        default:
            break;
    }
    return implementationDescriptor;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) ImplementationsDescriptorDTO(org.eclipse.che.ide.ext.java.shared.dto.ImplementationsDescriptorDTO) ArrayList(java.util.ArrayList)

Aggregations

Type (org.eclipse.che.ide.ext.java.shared.dto.model.Type)13 ArrayList (java.util.ArrayList)8 IType (org.eclipse.jdt.core.IType)8 Node (org.eclipse.che.ide.api.data.tree.Node)3 JarEntryType (org.eclipse.che.ide.ext.java.shared.JarEntry.JarEntryType)3 CompilationUnit (org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit)3 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)3 Inject (com.google.inject.Inject)2 Assisted (com.google.inject.assistedinject.Assisted)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 NotNull (javax.validation.constraints.NotNull)2 Promise (org.eclipse.che.api.promises.client.Promise)2 AsyncPromiseHelper.createFromAsyncRequest (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest)2 PositionConverter (org.eclipse.che.ide.api.editor.position.PositionConverter)2 JavaResources (org.eclipse.che.ide.ext.java.client.JavaResources)2 Field (org.eclipse.che.ide.ext.java.shared.dto.model.Field)2 Initializer (org.eclipse.che.ide.ext.java.shared.dto.model.Initializer)2 Match (org.eclipse.che.ide.ext.java.shared.dto.search.Match)2