Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 47ca684a6150ed56cd145bfa185f40e0cf888eb3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*******************************************************************************
 * Copyright (c) 2007, 2017 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.jdt.internal.compiler.apt.model;

import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.Name;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;

import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;

/**
 * Element corresponding to the Error type mirror
 */
public class ErrorTypeElement extends TypeElementImpl {
	
	ErrorTypeElement(BaseProcessingEnvImpl env, ReferenceBinding binding) {
		super(env, binding, null);
	}
	/* (non-Javadoc)
	 * @see javax.lang.model.element.TypeElement#getInterfaces()
	 */
	@Override
	public List<? extends TypeMirror> getInterfaces() {
		return Collections.emptyList();
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.TypeElement#getNestingKind()
	 */
	@Override
	public NestingKind getNestingKind() {
		return NestingKind.TOP_LEVEL;
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.TypeElement#getQualifiedName()
	 */
	@Override
	public Name getQualifiedName() {
		ReferenceBinding binding = (ReferenceBinding)_binding;
		char[] qName;
		if (binding.isMemberType()) {
			qName = CharOperation.concatWith(binding.enclosingType().compoundName, binding.sourceName, '.');
			CharOperation.replace(qName, '$', '.');
		} else {
			qName = CharOperation.concatWith(binding.compoundName, '.');
		}
		return new NameImpl(qName);
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.TypeElement#getSuperclass()
	 */
	@Override
	public TypeMirror getSuperclass() {
		return this._env.getFactory().getNoType(TypeKind.NONE);
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.TypeElement#getTypeParameters()
	 */
	@Override
	public List<? extends TypeParameterElement> getTypeParameters() {
		return Collections.emptyList();
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.Element#asType()
	 */
	@Override
	public TypeMirror asType() {
		return this._env.getFactory().getErrorType((ReferenceBinding) this._binding);
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.Element#getAnnotation(java.lang.Class)
	 */
	@Override
	public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
		return null;
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.Element#getAnnotationMirrors()
	 */
	@Override
	public List<? extends AnnotationMirror> getAnnotationMirrors() {
		return Collections.emptyList();
	}
	
	@SuppressWarnings("unchecked")
	public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
		return (A[]) Array.newInstance(annotationType, 0);
	}


	/* (non-Javadoc)
	 * @see javax.lang.model.element.Element#getEnclosedElements()
	 */
	@Override
	public List<? extends Element> getEnclosedElements() {
		return Collections.emptyList();
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.Element#getEnclosingElement()
	 */
	@Override
	public Element getEnclosingElement() {
		return this._env.getFactory().newPackageElement(this._env.getLookupEnvironment().defaultPackage);
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.Element#getKind()
	 */
	@Override
	public ElementKind getKind() {
		return ElementKind.CLASS;
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.Element#getModifiers()
	 */
	@Override
	public Set<Modifier> getModifiers() {
		return Collections.emptySet();
	}

	/* (non-Javadoc)
	 * @see javax.lang.model.element.Element#getSimpleName()
	 */
	@Override
	public Name getSimpleName() {
		ReferenceBinding binding = (ReferenceBinding)_binding;
		return new NameImpl(binding.sourceName());
	}
}

Back to the top