Stephan Herrmann | 7b7062f | 2010-04-01 19:56:59 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
Stephan Herrmann | 4103845 | 2020-07-07 18:50:44 +0200 | [diff] [blame] | 2 | * Copyright (c) 2000, 2020 IBM Corporation and others. |
Stephan Herrmann | aa0c80c | 2018-09-08 22:11:53 +0200 | [diff] [blame] | 3 | * |
| 4 | * This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License 2.0 |
Stephan Herrmann | 7b7062f | 2010-04-01 19:56:59 +0000 | [diff] [blame] | 6 | * which accompanies this distribution, and is available at |
Stephan Herrmann | aa0c80c | 2018-09-08 22:11:53 +0200 | [diff] [blame] | 7 | * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | * |
| 9 | * SPDX-License-Identifier: EPL-2.0 |
Stephan Herrmann | 7b7062f | 2010-04-01 19:56:59 +0000 | [diff] [blame] | 10 | * |
| 11 | * Contributors: |
| 12 | * IBM Corporation - initial API and implementation |
| 13 | * Technical University Berlin - extended API and implementation |
| 14 | *******************************************************************************/ |
| 15 | package org.eclipse.jdt.internal.compiler.lookup; |
| 16 | |
| 17 | import org.eclipse.jdt.core.compiler.CharOperation; |
| 18 | import org.eclipse.jdt.internal.compiler.ast.ImportReference; |
| 19 | |
| 20 | public 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} |
| 35 | public 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 Herrmann | e472188 | 2018-01-25 20:43:01 +0100 | [diff] [blame] | 45 | @Override |
Stephan Herrmann | 7b7062f | 2010-04-01 19:56:59 +0000 | [diff] [blame] | 46 | public final int kind() { |
| 47 | return IMPORT; |
| 48 | } |
| 49 | public boolean isStatic() { |
| 50 | return this.reference != null && this.reference.isStatic(); |
| 51 | } |
Stephan Herrmann | 4103845 | 2020-07-07 18:50:44 +0200 | [diff] [blame] | 52 | public 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 Herrmann | e472188 | 2018-01-25 20:43:01 +0100 | [diff] [blame] | 59 | @Override |
Stephan Herrmann | 7b7062f | 2010-04-01 19:56:59 +0000 | [diff] [blame] | 60 | public 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 Herrmann | e472188 | 2018-01-25 20:43:01 +0100 | [diff] [blame] | 66 | @Override |
Stephan Herrmann | 7b7062f | 2010-04-01 19:56:59 +0000 | [diff] [blame] | 67 | public String toString() { |
| 68 | return "import : " + new String(readableName()); //$NON-NLS-1$ |
| 69 | } |
| 70 | } |