]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/ChangeTypeContentProvider.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui refactoring / org / eclipse / jdt / internal / ui / refactoring / ChangeTypeContentProvider.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.refactoring;
12
13import java.util.Arrays;
14import java.util.Comparator;
15import java.util.HashSet;
16import java.util.Set;
17
18import org.eclipse.core.runtime.Assert;
19
20import org.eclipse.jface.viewers.ITreeContentProvider;
21import org.eclipse.jface.viewers.Viewer;
22
23import org.eclipse.jdt.core.dom.ITypeBinding;
24
25import org.eclipse.jdt.internal.corext.refactoring.structure.ChangeTypeRefactoring;
26import org.eclipse.jdt.internal.corext.util.CollectionsUtil;
27
28public class ChangeTypeContentProvider implements ITreeContentProvider {
29
30 public ChangeTypeRefactoring fGeneralizeType;
31
32 ChangeTypeContentProvider(ChangeTypeRefactoring gt){
33 fGeneralizeType= gt;
34 }
35
36 public Object[] getChildren(Object element) {
37 if (element instanceof RootType){
38 return ((RootType)element).getChildren();
39 }
40 ITypeBinding[] superTypes = CollectionsUtil.toArray(getDirectSuperTypes((ITypeBinding)element), ITypeBinding.class);
41 Arrays.sort(superTypes, new Comparator<ITypeBinding>(){
42 public int compare(ITypeBinding o1, ITypeBinding o2) {
43 String name1 = o1.getQualifiedName();
44 String name2 = o2.getQualifiedName();
45 return name1.compareTo(name2);
46 }
47 });
48 return superTypes;
49 }
50
51 /**
52 * @param type a type
53 * @return the direct superclass and direct superinterfaces. Class Object is
54 * included in the result if the root of the hierarchy is a top-level
55 * interface.
56 */
57 public Set<ITypeBinding> getDirectSuperTypes(ITypeBinding type){
58 Set<ITypeBinding> result= new HashSet<ITypeBinding>();
59 if (type.getSuperclass() != null){
60 result.add(type.getSuperclass());
61 }
62 ITypeBinding[] interfaces= type.getInterfaces();
63 for (int i=0; i < interfaces.length; i++){
64 result.add(interfaces[i]);
65 }
66 fGeneralizeType.generated_4646330632040955199(type, result);
67 return result;
68 }
69
70 public Object[] getElements(Object element) {
71 Assert.isTrue(element instanceof RootType);
72 return ((RootType)element).getChildren();
73 }
74
75 public boolean hasChildren(Object element) {
76 return getChildren(element).length > 0;
77 }
78
79 public Object getParent(Object element) {
80 return null;
81 }
82
83 public void dispose() {
84 }
85
86 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
87 }
88
89 /**
90 * Artificial "root node" of the tree view. This is needed to handle situations where the replacement
91 * types do not have a single common supertype. Also, the tree view does not show the root node by
92 * default.
93 */
94 static class RootType {
95 RootType(ITypeBinding root){
96 fRoot = root;
97 }
98 public ITypeBinding[] getChildren(){
99 return new ITypeBinding[]{ fRoot };
100 }
101 private ITypeBinding fRoot;
102 }
103}