1 11 package org.eclipse.jdt.internal.ui.typehierarchy; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.Assert; 17 18 import org.eclipse.jface.viewers.IStructuredContentProvider; 19 import org.eclipse.jface.viewers.TableViewer; 20 import org.eclipse.jface.viewers.Viewer; 21 22 import org.eclipse.jdt.core.IType; 23 import org.eclipse.jdt.core.ITypeHierarchy; 24 import org.eclipse.jdt.core.JavaModelException; 25 26 import org.eclipse.jdt.ui.IWorkingCopyProvider; 27 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 30 34 public class MethodsContentProvider implements IStructuredContentProvider, IWorkingCopyProvider { 35 36 private static final Object [] NO_ELEMENTS = new Object [0]; 37 38 private boolean fShowInheritedMethods; 39 private TypeHierarchyLifeCycle fHierarchyLifeCycle; 40 private TableViewer fViewer; 41 42 public MethodsContentProvider(TypeHierarchyLifeCycle lifecycle) { 43 fHierarchyLifeCycle= lifecycle; 44 fShowInheritedMethods= false; 45 fViewer= null; 46 } 47 48 51 public void showInheritedMethods(boolean show) { 52 if (show != fShowInheritedMethods) { 53 fShowInheritedMethods= show; 54 if (fViewer != null) { 55 fViewer.refresh(); 56 } 57 } 58 } 59 60 63 public boolean providesWorkingCopies() { 64 return true; 65 } 66 67 70 public boolean isShowInheritedMethods() { 71 return fShowInheritedMethods; 72 } 73 74 75 private void addAll(Object [] arr, List res) { 76 if (arr != null) { 77 for (int j= 0; j < arr.length; j++) { 78 res.add(arr[j]); 79 } 80 } 81 } 82 83 86 public Object [] getElements(Object element) { 87 if (element instanceof IType) { 88 IType type= (IType)element; 89 90 List res= new ArrayList (); 91 try { 92 ITypeHierarchy hierarchy= fHierarchyLifeCycle.getHierarchy(); 93 if (fShowInheritedMethods && hierarchy != null) { 94 IType[] allSupertypes= hierarchy.getAllSupertypes(type); 95 for (int i= allSupertypes.length - 1; i >= 0; i--) { 98 IType superType= allSupertypes[i]; 99 if (superType.exists()) { 100 addAll(superType.getMethods(), res); 101 addAll(superType.getInitializers(), res); 102 addAll(superType.getFields(), res); 103 } 104 } 105 } 106 if (type.exists()) { 107 addAll(type.getMethods(), res); 108 addAll(type.getInitializers(), res); 109 addAll(type.getFields(), res); 110 } 111 } catch (JavaModelException e) { 112 JavaPlugin.log(e); 113 } 114 return res.toArray(); 115 } 116 return NO_ELEMENTS; 117 } 118 119 120 123 public void inputChanged(Viewer input, Object oldInput, Object newInput) { 124 Assert.isTrue(input instanceof TableViewer); 125 126 fViewer= (TableViewer) input; 127 } 128 129 132 public void dispose() { 133 } 134 135 } 136 | Popular Tags |