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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations