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

The following examples show how to use org.eclipse.jdt.core.ITypeHierarchy#getSupertypes() . 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: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the visibility threshold from a type to a field.
 *
 * @param referencing the referencing type
 * @param referenced the referenced field
 * @param monitor the progress monitor to use
 * @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility
 * @throws JavaModelException if the java elements could not be accessed
 */
private ModifierKeyword thresholdTypeToField(final IType referencing, final IField referenced, final IProgressMonitor monitor) throws JavaModelException {
	ModifierKeyword keyword= ModifierKeyword.PUBLIC_KEYWORD;
	final ICompilationUnit referencedUnit= referenced.getCompilationUnit();
	if (referenced.getDeclaringType().equals(referencing))
		keyword= ModifierKeyword.PRIVATE_KEYWORD;
	else {
		final ITypeHierarchy hierarchy= getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1));
		final IType[] types= hierarchy.getSupertypes(referencing);
		IType superType= null;
		for (int index= 0; index < types.length; index++) {
			superType= types[index];
			if (superType.equals(referenced.getDeclaringType())) {
				keyword= ModifierKeyword.PROTECTED_KEYWORD;
				return keyword;
			}
		}
	}
	final ICompilationUnit typeUnit= referencing.getCompilationUnit();
	if (referencedUnit != null && referencedUnit.equals(typeUnit))
		keyword= ModifierKeyword.PRIVATE_KEYWORD;
	else if (referencedUnit != null && typeUnit != null && referencedUnit.getParent().equals(typeUnit.getParent()))
		keyword= null;
	return keyword;
}
 
Example 2
Source File: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the visibility threshold from a type to a method.
 *
 * @param referencing the referencing type
 * @param referenced the referenced method
 * @param monitor the progress monitor to use
 * @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility
 * @throws JavaModelException if the java elements could not be accessed
 */
private ModifierKeyword thresholdTypeToMethod(final IType referencing, final IMethod referenced, final IProgressMonitor monitor) throws JavaModelException {
	final ICompilationUnit referencedUnit= referenced.getCompilationUnit();
	ModifierKeyword keyword= ModifierKeyword.PUBLIC_KEYWORD;
	if (referenced.getDeclaringType().equals(referencing))
		keyword= ModifierKeyword.PRIVATE_KEYWORD;
	else {
		final ITypeHierarchy hierarchy= getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1));
		final IType[] types= hierarchy.getSupertypes(referencing);
		IType superType= null;
		for (int index= 0; index < types.length; index++) {
			superType= types[index];
			if (superType.equals(referenced.getDeclaringType())) {
				keyword= ModifierKeyword.PROTECTED_KEYWORD;
				return keyword;
			}
		}
	}
	final ICompilationUnit typeUnit= referencing.getCompilationUnit();
	if (referencedUnit != null && referencedUnit.equals(typeUnit)) {
		if (referenced.getDeclaringType().getDeclaringType() != null)
			keyword= null;
		else
			keyword= ModifierKeyword.PRIVATE_KEYWORD;
	} else if (referencedUnit != null && referencedUnit.getParent().equals(typeUnit.getParent()))
		keyword= null;
	return keyword;
}
 
Example 3
Source File: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the visibility threshold from a type to another type.
 *
 * @param referencing the referencing type
 * @param referenced the referenced type
 * @param monitor the progress monitor to use
 * @return the visibility keyword corresponding to the threshold, or <code>null</code> for default visibility
 * @throws JavaModelException if the java elements could not be accessed
 */
private ModifierKeyword thresholdTypeToType(final IType referencing, final IType referenced, final IProgressMonitor monitor) throws JavaModelException {
	ModifierKeyword keyword= ModifierKeyword.PUBLIC_KEYWORD;
	final ICompilationUnit referencedUnit= referenced.getCompilationUnit();
	if (referencing.equals(referenced.getDeclaringType()))
		keyword= ModifierKeyword.PRIVATE_KEYWORD;
	else {
		final ITypeHierarchy hierarchy= getTypeHierarchy(referencing, new SubProgressMonitor(monitor, 1));
		final IType[] types= hierarchy.getSupertypes(referencing);
		IType superType= null;
		for (int index= 0; index < types.length; index++) {
			superType= types[index];
			if (superType.equals(referenced)) {
				keyword= null;
				return keyword;
			}
		}
	}
	final ICompilationUnit typeUnit= referencing.getCompilationUnit();
	if (referencedUnit != null && referencedUnit.equals(typeUnit)) {
		if (referenced.getDeclaringType() != null)
			keyword= null;
		else
			keyword= ModifierKeyword.PRIVATE_KEYWORD;
	} else if (referencedUnit != null && typeUnit != null && referencedUnit.getParent().equals(typeUnit.getParent()))
		keyword= null;
	return keyword;
}
 
Example 4
Source File: SuperTypeHierarchyViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected final void getTypesInHierarchy(IType type, List<IType> res) {
	ITypeHierarchy hierarchy= getHierarchy();
	if (hierarchy != null) {
		IType[] types= hierarchy.getSupertypes(type);
		for (int i= 0; i < types.length; i++) {
			res.add(types[i]);
		}
	}
}