Search in sources :

Example 6 with Type

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

the class JavaTypeHierarchy method findTypesWithSubMethods.

private void findTypesWithSubMethods(IJavaElement element, List<Type> implementations) throws JavaModelException {
    IMethod selectedMethod = (IMethod) element;
    IType parentType = selectedMethod.getDeclaringType();
    if (parentType == null) {
        return;
    }
    ITypeHierarchy typeHierarchy = parentType.newTypeHierarchy(new NullProgressMonitor());
    IType[] subTypes = typeHierarchy.getAllSubtypes(parentType);
    MethodOverrideTester methodOverrideTester = new MethodOverrideTester(parentType, typeHierarchy);
    for (IType type : subTypes) {
        IMethod method = methodOverrideTester.findOverridingMethodInType(type, selectedMethod);
        if (method == null) {
            continue;
        }
        Type openDeclaration = convertToTypeDTO(type);
        setRange(openDeclaration, method);
        implementations.add(openDeclaration);
    }
}
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) MethodOverrideTester(org.eclipse.jdt.internal.corext.util.MethodOverrideTester) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Example 7 with Type

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

the class JavaTypeHierarchy method convertToTypeDTO.

private Type convertToTypeDTO(IType type) throws JavaModelException {
    Type dto = DtoFactory.newDto(Type.class);
    String typeName = type.getElementName();
    if (typeName.isEmpty()) {
        dto.setElementName("Anonymous in " + type.getParent().getElementName());
    } else {
        dto.setElementName(type.getElementName());
    }
    if (type.isBinary()) {
        dto.setRootPath(type.getFullyQualifiedName());
        dto.setLibId(type.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode());
        dto.setBinary(true);
    } else {
        dto.setRootPath(type.getPath().toOSString());
        dto.setBinary(false);
    }
    setRange(dto, type);
    return dto;
}
Also used : IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type)

Example 8 with Type

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

the class JavaElementToDtoConverter method getTypes.

private List<Type> getTypes(Object parent) throws JavaModelException {
    List<Type> result = new ArrayList<>();
    Set<Object> objects = childrens.get(parent);
    if (objects == null) {
        return result;
    }
    for (Object object : objects) {
        if (object instanceof IType) {
            IType type = (IType) object;
            Type dtoType = DtoFactory.newDto(Type.class);
            dtoType.setElementName(type.getElementName());
            dtoType.setLabel(JavaElementLabels.getElementLabel(type, JavaElementLabels.ALL_DEFAULT));
            dtoType.setHandleIdentifier(type.getHandleIdentifier());
            dtoType.setFlags(type.getFlags());
            dtoType.setTypes(getTypes(object));
            dtoType.setFields(getFields(object));
            dtoType.setMethods(getMethods(object));
            dtoType.setInitializers(getInitializes(object));
            if (parent instanceof ITypeRoot) {
                IType primaryType = ((ITypeRoot) parent).findPrimaryType();
                dtoType.setPrimary(type.equals(primaryType));
            } else {
                dtoType.setPrimary(false);
            }
            result.add(dtoType);
        }
    }
    return result;
}
Also used : Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) IType(org.eclipse.jdt.core.IType) ArrayList(java.util.ArrayList) ITypeRoot(org.eclipse.jdt.core.ITypeRoot) IType(org.eclipse.jdt.core.IType)

Example 9 with Type

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

the class JavaNavigation method getCompilationUnitByPath.

/**
     * Get the compilation unit representation of the java file.
     *
     * @param javaProject
     *         path to the project which is contained class file
     * @param fqn
     *         fully qualified name of the class file
     * @param isShowingInheritedMembers
     *         <code>true</code> iff inherited members are shown
     * @return instance of {@link CompilationUnit}
     * @throws JavaModelException
     *         when JavaModel has a failure
     */
public CompilationUnit getCompilationUnitByPath(IJavaProject javaProject, String fqn, boolean isShowingInheritedMembers) throws JavaModelException {
    IType type = javaProject.findType(fqn);
    CompilationUnit compilationUnit = DtoFactory.newDto(CompilationUnit.class);
    ITypeRoot unit;
    if (type.isBinary()) {
        unit = type.getClassFile();
        compilationUnit.setPath(((IClassFile) unit).getType().getFullyQualifiedName());
    } else {
        unit = type.getCompilationUnit();
        compilationUnit.setProjectPath(unit.getJavaProject().getPath().toOSString());
        compilationUnit.setPath(unit.getResource().getFullPath().toOSString());
    }
    compilationUnit.setElementName(unit.getElementName());
    compilationUnit.setHandleIdentifier(unit.getHandleIdentifier());
    compilationUnit.setLabel(org.eclipse.jdt.ui.JavaElementLabels.getElementLabel(unit, org.eclipse.jdt.ui.JavaElementLabels.ALL_DEFAULT));
    List<Type> types = new ArrayList<>(1);
    Type dtoType = convertToDTOType(type);
    dtoType.setPrimary(true);
    types.add(dtoType);
    compilationUnit.setTypes(types);
    if (isShowingInheritedMembers) {
        compilationUnit.setSuperTypes(calculateSuperTypes(type));
    }
    return compilationUnit;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) 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) IClassFile(org.eclipse.jdt.core.IClassFile) ITypeRoot(org.eclipse.jdt.core.ITypeRoot) ArrayList(java.util.ArrayList) IType(org.eclipse.jdt.core.IType)

Example 10 with Type

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

the class JavaNavigation method convertToDTOType.

private Type convertToDTOType(IType iType) throws JavaModelException {
    List<Type> types = new ArrayList<>();
    List<Method> methods = new ArrayList<>();
    List<Field> fields = new ArrayList<>();
    List<Initializer> initializers = new ArrayList<>();
    Type type = DtoFactory.newDto(Type.class);
    setRootPath(iType, type);
    type.setElementName(iType.getElementName());
    type.setLabel(org.eclipse.jdt.ui.JavaElementLabels.getElementLabel(iType, org.eclipse.jdt.ui.JavaElementLabels.ALL_DEFAULT));
    type.setHandleIdentifier(iType.getHandleIdentifier());
    type.setFlags(iType.getFlags());
    type.setFileRegion(convertToDTORegion(iType.getNameRange()));
    if (!iType.hasChildren()) {
        type.setTypes(types);
        return type;
    }
    IJavaElement[] children = iType.getChildren();
    for (IJavaElement child : children) {
        switch(child.getElementType()) {
            case //type
            7:
                types.add(convertToDTOType((IType) child));
                break;
            case //field
            8:
                fields.add(convertToDTOField((IField) child));
                break;
            case //method
            9:
                methods.add(convertToDTOMethod((IMethod) child));
                break;
            case //initializer
            10:
                initializers.add(convertToDTOInitializer((IInitializer) child));
                break;
            default:
                break;
        }
    }
    type.setFields(fields);
    type.setMethods(methods);
    type.setInitializers(initializers);
    type.setTypes(types);
    return type;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IInitializer(org.eclipse.jdt.core.IInitializer) ArrayList(java.util.ArrayList) Method(org.eclipse.che.ide.ext.java.shared.dto.model.Method) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) Field(org.eclipse.che.ide.ext.java.shared.dto.model.Field) IField(org.eclipse.jdt.core.IField) 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) Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) IInitializer(org.eclipse.jdt.core.IInitializer) IMethod(org.eclipse.jdt.core.IMethod)

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