1 /******************************************************************************* 2 * Copyright (c) 2015, 2016 Google, Inc 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 * Stefan Xenos (Google) - Initial implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.core.nd.java; 15 16 import org.eclipse.jdt.internal.core.nd.Nd; 17 import org.eclipse.jdt.internal.core.nd.NdNode; 18 import org.eclipse.jdt.internal.core.nd.field.FieldByte; 19 import org.eclipse.jdt.internal.core.nd.field.FieldManyToOne; 20 import org.eclipse.jdt.internal.core.nd.field.StructDef; 21 import org.eclipse.jdt.internal.core.util.CharArrayBuffer; 22 23 public class NdTypeArgument extends NdNode { 24 public static final FieldManyToOne<NdComplexTypeSignature> PARENT; 25 public static final FieldManyToOne<NdTypeSignature> TYPE_SIGNATURE; 26 public static final FieldByte WILDCARD; 27 28 @SuppressWarnings("hiding") 29 public static final StructDef<NdTypeArgument> type; 30 31 static { 32 type = StructDef.create(NdTypeArgument.class, NdNode.type); 33 PARENT = FieldManyToOne.createOwner(type, NdComplexTypeSignature.TYPE_ARGUMENTS); 34 TYPE_SIGNATURE = FieldManyToOne.create(type, NdTypeSignature.USED_AS_TYPE_ARGUMENT); 35 WILDCARD = type.addByte(); type.done()36 type.done(); 37 } 38 39 public static final int WILDCARD_NONE = 0; 40 public static final int WILDCARD_EXTENDS = 1; 41 public static final int WILDCARD_SUPER = 2; 42 public static final int WILDCARD_QUESTION = 3; 43 NdTypeArgument(Nd nd, long address)44 public NdTypeArgument(Nd nd, long address) { 45 super(nd, address); 46 } 47 NdTypeArgument(Nd nd, NdComplexTypeSignature typeSignature)48 public NdTypeArgument(Nd nd, NdComplexTypeSignature typeSignature) { 49 super(nd); 50 51 PARENT.put(nd, this.address, typeSignature); 52 } 53 54 /** 55 * Sets the wildcard to use, one of the WILDCARD_* constants. 56 * 57 * @param wildcard 58 */ setWildcard(int wildcard)59 public void setWildcard(int wildcard) { 60 WILDCARD.put(getNd(), this.address, (byte) wildcard); 61 } 62 setType(NdTypeSignature typeSignature)63 public void setType(NdTypeSignature typeSignature) { 64 TYPE_SIGNATURE.put(getNd(), this.address, typeSignature); 65 } 66 getWildcard()67 public int getWildcard() { 68 return WILDCARD.get(getNd(), this.address); 69 } 70 getParent()71 public NdComplexTypeSignature getParent() { 72 return PARENT.get(getNd(), this.address); 73 } 74 getType()75 public NdTypeSignature getType() { 76 return TYPE_SIGNATURE.get(getNd(), this.address); 77 } 78 getSignature(CharArrayBuffer result)79 public void getSignature(CharArrayBuffer result) { 80 switch (getWildcard()) { 81 case NdTypeArgument.WILDCARD_EXTENDS: result.append('-'); break; 82 case NdTypeArgument.WILDCARD_QUESTION: result.append('*'); return; 83 case NdTypeArgument.WILDCARD_SUPER: result.append('+'); break; 84 } 85 86 NdTypeSignature theType = getType(); 87 if (theType != null) { 88 theType.getSignature(result); 89 } 90 } 91 } 92