1 /******************************************************************************* 2 * Copyright (c) 2000, 2016 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types; 15 16 import org.eclipse.jdt.core.dom.ITypeBinding; 17 18 19 public abstract class AbstractTypeVariable extends TType { 20 21 protected TType[] fBounds; 22 AbstractTypeVariable(TypeEnvironment environment)23 protected AbstractTypeVariable(TypeEnvironment environment) { 24 super(environment); 25 } 26 27 @Override initialize(ITypeBinding binding)28 protected void initialize(ITypeBinding binding) { 29 super.initialize(binding); 30 ITypeBinding[] bounds= binding.getTypeBounds(); 31 if (bounds.length == 0) { 32 fBounds= EMPTY_TYPE_ARRAY; 33 if (getEnvironment().getJavaLangObject() == null) { 34 getEnvironment().initializeJavaLangObject(binding.getErasure()); 35 } 36 } else { 37 fBounds= new TType[bounds.length]; 38 for (int i= 0; i < bounds.length; i++) { 39 fBounds[i]= getEnvironment().create(bounds[i]); 40 } 41 } 42 } 43 44 @Override getErasure()45 public TType getErasure() { 46 if (fBounds.length == 0) 47 return getEnvironment().getJavaLangObject(); 48 return fBounds[0].getErasure(); 49 } 50 isUnbounded()51 /* package */ final boolean isUnbounded() { 52 if (fBounds.length == 0) 53 return true; 54 return fBounds[0].isJavaLangObject(); 55 } 56 getBounds()57 public final TType[] getBounds() { 58 return fBounds.clone(); 59 } 60 61 @Override getSubTypes()62 public final TType[] getSubTypes() { 63 return EMPTY_TYPE_ARRAY; 64 } 65 checkAssignmentBound(TType rhs)66 protected final boolean checkAssignmentBound(TType rhs) { 67 if (fBounds.length == 0) 68 return true; 69 for (TType bound : fBounds) { 70 if (rhs.canAssignTo(bound)) { 71 return true; 72 } 73 } 74 return false; 75 } 76 canAssignOneBoundTo(TType lhs)77 protected final boolean canAssignOneBoundTo(TType lhs) { 78 if (fBounds.length == 0) 79 return lhs.isJavaLangObject(); 80 for (TType bound : fBounds) { 81 if (bound.canAssignTo(lhs)) { 82 return true; 83 } 84 } 85 return false; 86 } 87 88 } 89