Java Code Examples for org.eclipse.jdt.core.ITypeHierarchy#getSuperclass()

The following examples show how to use org.eclipse.jdt.core.ITypeHierarchy#getSuperclass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PullUpRefactoringProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Set<IType> getSkippedSuperTypes(final IProgressMonitor monitor) throws JavaModelException {
	monitor.beginTask(RefactoringCoreMessages.PullUpRefactoring_checking, 1);
	try {
		if (fCachedSkippedSuperTypes != null && getDestinationTypeHierarchy(new SubProgressMonitor(monitor, 1)).getType().equals(getDestinationType()))
			return fCachedSkippedSuperTypes;
		final ITypeHierarchy hierarchy= getDestinationTypeHierarchy(new SubProgressMonitor(monitor, 1));
		fCachedSkippedSuperTypes= new HashSet<IType>(2);
		IType current= hierarchy.getSuperclass(getDeclaringType());
		while (current != null && !current.equals(getDestinationType())) {
			fCachedSkippedSuperTypes.add(current);
			current= hierarchy.getSuperclass(current);
		}
		return fCachedSkippedSuperTypes;
	} finally {
		monitor.done();
	}
}
 
Example 2
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean isSuperType(ITypeHierarchy hierarchy, IType possibleSuperType, IType type) {
	// filed bug 112635 to add this method to ITypeHierarchy
	IType superClass= hierarchy.getSuperclass(type);
	if (superClass != null && (possibleSuperType.equals(superClass) || isSuperType(hierarchy, possibleSuperType, superClass))) {
		return true;
	}
	if (Flags.isInterface(hierarchy.getCachedFlags(possibleSuperType))) {
		IType[] superInterfaces= hierarchy.getSuperInterfaces(type);
		for (int i= 0; i < superInterfaces.length; i++) {
			IType curr= superInterfaces[i];
			if (possibleSuperType.equals(curr) || isSuperType(hierarchy, possibleSuperType, curr)) {
				return true;
			}
		}
	}
	return false;
}
 
Example 3
Source File: JavadocContentAccess2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Visits the super types of the given <code>currentType</code>.
 *
 * @param currentType
 *            the starting type
 * @param typeHierarchy
 *            a super type hierarchy that contains <code>currentType</code>
 * @return the result from a call to {@link #visit(IType)}, or <code>null</code>
 *         if none of the calls returned a result
 * @throws JavaModelException
 *             unexpected problem
 */
public Object visitInheritDoc(IType currentType, ITypeHierarchy typeHierarchy) throws JavaModelException {
	ArrayList<IType> visited = new ArrayList<>();
	visited.add(currentType);
	Object result = visitInheritDocInterfaces(visited, currentType, typeHierarchy);
	if (result != InheritDocVisitor.CONTINUE) {
		return result;
	}

	IType superClass;
	if (currentType.isInterface()) {
		superClass = currentType.getJavaProject().findType("java.lang.Object"); //$NON-NLS-1$
	} else {
		superClass = typeHierarchy.getSuperclass(currentType);
	}

	while (superClass != null && !visited.contains(superClass)) {
		result = visit(superClass);
		if (result == InheritDocVisitor.STOP_BRANCH) {
			return null;
		} else if (result == InheritDocVisitor.CONTINUE) {
			visited.add(superClass);
			result = visitInheritDocInterfaces(visited, superClass, typeHierarchy);
			if (result != InheritDocVisitor.CONTINUE) {
				return result;
			} else {
				superClass = typeHierarchy.getSuperclass(superClass);
			}
		} else {
			return result;
		}
	}

	return null;
}
 
Example 4
Source File: JavaModelSearch.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static IField findFieldInHierarchy(ITypeHierarchy hierarchy,
    IType type, String fieldName) {

  IField field = findField(type, fieldName);

  // Check super class
  if (field == null) {
    IType superClass = hierarchy.getSuperclass(type);
    if (superClass != null) {
      field = findFieldInHierarchy(hierarchy, superClass, fieldName);
    }
  }

  return field;
}
 
Example 5
Source File: JavaModelSearch.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static IMethod findMethodOrCtorInHierarchy(ITypeHierarchy hierarchy,
    IType type, String methodName, String[] paramTypes, boolean isConstructor) {
  IMethod method = findMethodOrCtor(type, methodName, paramTypes,
      isConstructor);
  if (method != null) {
    return method;
  }

  // Check super class
  IType superClass = hierarchy.getSuperclass(type);
  if (superClass != null) {
    method = findMethodOrCtorInHierarchy(hierarchy, superClass, methodName,
        paramTypes, isConstructor);
    if (method != null) {
      return method;
    }
  }

  if (!isConstructor) {
    // Check interfaces
    IType[] superInterfaces = hierarchy.getSuperInterfaces(type);
    for (IType superInterface : superInterfaces) {
      method = findMethodOrCtorInHierarchy(hierarchy, superInterface,
          methodName, paramTypes, false);
      if (method != null) {
        return method;
      }
    }
  }

  return method;
}
 
Example 6
Source File: PullUpMethodPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void checkAllParents(final IType parent) {
	final ITypeHierarchy th= getTreeInput();
	final IType root= getTreeInput().getType();
	IType type= parent;
	while (!root.equals(type)) {
		fTreeViewer.setChecked(type, true);
		type= th.getSuperclass(type);
	}
	fTreeViewer.setChecked(root, true);
}
 
Example 7
Source File: ChangeExceptionsControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IStatus checkException(final IType type) throws JavaModelException {
	ITypeHierarchy hierarchy= type.newSupertypeHierarchy(new NullProgressMonitor());
	IType curr= type;
	while (curr != null) {
		String name= curr.getFullyQualifiedName();
		if ("java.lang.Throwable".equals(name)) //$NON-NLS-1$
			return StatusInfo.OK_STATUS;
		curr= hierarchy.getSuperclass(curr);
	}
	return JavaUIStatus.createError(IStatus.ERROR,
			RefactoringMessages.ChangeExceptionsControl_not_exception, null);
}
 
Example 8
Source File: SubTypeHierarchyViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected IType getParentType(IType type) {
	ITypeHierarchy hierarchy= getHierarchy();
	if (hierarchy != null) {
		return hierarchy.getSuperclass(type);
		// dont handle interfaces
	}
	return null;
}
 
Example 9
Source File: TraditionalHierarchyViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getDepth(ITypeHierarchy hierarchy, IType input) {
	int count= 0;
	IType superType= hierarchy.getSuperclass(input);
	while (superType != null) {
		count++;
		superType= hierarchy.getSuperclass(superType);
	}
	return count;
}
 
Example 10
Source File: TraditionalHierarchyViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected IType getParentType(IType type) {
	ITypeHierarchy hierarchy= getHierarchy();
	if (hierarchy != null) {
		return hierarchy.getSuperclass(type);
		// don't handle interfaces
	}
	return null;
}
 
Example 11
Source File: JavadocContentAccess2.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Visits the super types of the given <code>currentType</code>.
 *
 * @param currentType the starting type
 * @param typeHierarchy a super type hierarchy that contains <code>currentType</code>
 * @return the result from a call to {@link #visit(IType)}, or <code>null</code> if none of
 *         the calls returned a result
 * @throws JavaModelException unexpected problem
 */
public Object visitInheritDoc(IType currentType, ITypeHierarchy typeHierarchy) throws JavaModelException {
	ArrayList<IType> visited= new ArrayList<IType>();
	visited.add(currentType);
	Object result= visitInheritDocInterfaces(visited, currentType, typeHierarchy);
	if (result != InheritDocVisitor.CONTINUE)
		return result;

	IType superClass;
	if (currentType.isInterface())
		superClass= currentType.getJavaProject().findType("java.lang.Object"); //$NON-NLS-1$
	else
		superClass= typeHierarchy.getSuperclass(currentType);

	while (superClass != null && ! visited.contains(superClass)) {
		result= visit(superClass);
		if (result == InheritDocVisitor.STOP_BRANCH) {
			return null;
		} else if (result == InheritDocVisitor.CONTINUE) {
			visited.add(superClass);
			result= visitInheritDocInterfaces(visited, superClass, typeHierarchy);
			if (result != InheritDocVisitor.CONTINUE)
				return result;
			else
				superClass= typeHierarchy.getSuperclass(superClass);
		} else {
			return result;
		}
	}

	return null;
}