blob: 535fda37ad6b8e0cf02e61fa8e829b148fbe3ea3 [file] [log] [blame]
Stephan Herrmann7b7062f2010-04-01 19:56:59 +00001/*******************************************************************************
Stephan Herrmann41038452020-07-07 18:50:44 +02002 * Copyright (c) 2000, 2020 IBM Corporation and others.
Stephan Herrmannaa0c80c2018-09-08 22:11:53 +02003 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
Stephan Herrmann7b7062f2010-04-01 19:56:59 +00006 * which accompanies this distribution, and is available at
Stephan Herrmannaa0c80c2018-09-08 22:11:53 +02007 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000010 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 * Technical University Berlin - extended API and implementation
14 *******************************************************************************/
15package org.eclipse.jdt.internal.compiler.lookup;
16
17import org.eclipse.jdt.core.compiler.CharOperation;
18import org.eclipse.jdt.internal.compiler.ast.ImportReference;
19
20public class ImportBinding extends Binding {
21 public char[][] compoundName;
22 public boolean onDemand;
23 public ImportReference reference;
24
25 public Binding resolvedImport; // must ensure the import is resolved
26
27//{ObjectTeams: base imports
28 public boolean isBase;
29 public ImportBinding(char[][] compoundName, boolean isOnDemand, boolean isBase, Binding binding, ImportReference reference)
30 {
31 this(compoundName, isOnDemand, binding, reference);
32 this.isBase = isBase;
33 }
34// SH}
35public ImportBinding(char[][] compoundName, boolean isOnDemand, Binding binding, ImportReference reference) {
36 this.compoundName = compoundName;
37 this.onDemand = isOnDemand;
38 this.resolvedImport = binding;
39 this.reference = reference;
40}
41/* API
42* Answer the receiver's binding type from Binding.BindingID.
43*/
44
Stephan Herrmanne4721882018-01-25 20:43:01 +010045@Override
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000046public final int kind() {
47 return IMPORT;
48}
49public boolean isStatic() {
50 return this.reference != null && this.reference.isStatic();
51}
Stephan Herrmann41038452020-07-07 18:50:44 +020052public char[] getSimpleName() {
53 if (this.reference != null) {
54 return this.reference.getSimpleName();
55 } else {
56 return this.compoundName[this.compoundName.length - 1];
57 }
58}
Stephan Herrmanne4721882018-01-25 20:43:01 +010059@Override
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000060public char[] readableName() {
61 if (this.onDemand)
62 return CharOperation.concat(CharOperation.concatWith(this.compoundName, '.'), ".*".toCharArray()); //$NON-NLS-1$
63 else
64 return CharOperation.concatWith(this.compoundName, '.');
65}
Stephan Herrmanne4721882018-01-25 20:43:01 +010066@Override
Stephan Herrmann7b7062f2010-04-01 19:56:59 +000067public String toString() {
68 return "import : " + new String(readableName()); //$NON-NLS-1$
69}
70}