else if (element instanceof IImportContainer || element instanceof IImportDeclaration) { IJavaElement parent= ((IJavaElement)element).getParent(); if (parent.getElementType() == IJavaElement.CLASS_FILE) { IType type; try { type= ((IClassFile)parent).getType(); } catch (JavaModelException ex) { return false; } return isValidElement(type); } else if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) { IType[] types; try { types= ((ICompilationUnit)parent).getAllTypes(); } catch (JavaModelException ex) { return false; } for (int i= 0; i < types.length; i++) { boolean result= isValidElement(types[i]); if (result) return true;
else if (element instanceof IImportDeclaration) return isValidElement(((IJavaElement)element).getParent()); else if (element instanceof IImportContainer) { Object input= getViewer().getInput(); if (input instanceof IJavaElement) { ICompilationUnit cu= (ICompilationUnit)((IJavaElement)input).getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) { ICompilationUnit importContainerCu= (ICompilationUnit)((IJavaElement)element).getAncestor(IJavaElement.COMPILATION_UNIT); return cu.equals(importContainerCu); } else { IClassFile cf= (IClassFile)((IJavaElement)input).getAncestor(IJavaElement.CLASS_FILE); IClassFile importContainerCf= (IClassFile)((IJavaElement)element).getAncestor(IJavaElement.CLASS_FILE); return cf != null && cf.equals(importContainerCf);
	protected boolean isValidElement(Object element) {		if (element instanceof IMember)			return super.isValidElement(((IMember)element).getDeclaringType());		else if (element instanceof IImportContainer || element instanceof IImportDeclaration) {			IJavaElement parent= ((IJavaElement)element).getParent();			if (parent.getElementType() == IJavaElement.CLASS_FILE) {				IType type;				try {					type= ((IClassFile)parent).getType();				} catch (JavaModelException ex) {					return false;				}				return isValidElement(type);			}			else if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {				IType[] types;				try {					types= ((ICompilationUnit)parent).getAllTypes();				} catch (JavaModelException ex) {					return false;				}				for (int i= 0; i < types.length; i++) {					boolean result= isValidElement(types[i]);					if (result)						return true;				}			}		}		return false;	}