-
Notifications
You must be signed in to change notification settings - Fork 316
/
XtendTypeDeclarationImpl.java
181 lines (161 loc) · 7.64 KB
/
XtendTypeDeclarationImpl.java
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* Copyright (c) 2013, 2016 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtend.core.macro.declaration;
import com.google.common.collect.Iterables;
import java.util.List;
import java.util.Objects;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtend.core.xtend.XtendFile;
import org.eclipse.xtend.core.xtend.XtendMember;
import org.eclipse.xtend.core.xtend.XtendTypeDeclaration;
import org.eclipse.xtend.lib.macro.declaration.AnnotationTypeDeclaration;
import org.eclipse.xtend.lib.macro.declaration.ClassDeclaration;
import org.eclipse.xtend.lib.macro.declaration.ConstructorDeclaration;
import org.eclipse.xtend.lib.macro.declaration.EnumerationTypeDeclaration;
import org.eclipse.xtend.lib.macro.declaration.FieldDeclaration;
import org.eclipse.xtend.lib.macro.declaration.InterfaceDeclaration;
import org.eclipse.xtend.lib.macro.declaration.MemberDeclaration;
import org.eclipse.xtend.lib.macro.declaration.MethodDeclaration;
import org.eclipse.xtend.lib.macro.declaration.ParameterDeclaration;
import org.eclipse.xtend.lib.macro.declaration.Type;
import org.eclipse.xtend.lib.macro.declaration.TypeDeclaration;
import org.eclipse.xtend.lib.macro.declaration.TypeReference;
import org.eclipse.xtend.lib.macro.declaration.Visibility;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
@SuppressWarnings("all")
public abstract class XtendTypeDeclarationImpl<T extends XtendTypeDeclaration> extends XtendMemberDeclarationImpl<T> implements TypeDeclaration {
public String getPackageName() {
return EcoreUtil2.<XtendFile>getContainerOfType(this.getDelegate(), XtendFile.class).getPackage();
}
@Override
public String getSimpleName() {
return this.getDelegate().getName();
}
@Override
public String getQualifiedName() {
return this.getQualifiedName(this.getDelegate());
}
private String getQualifiedName(final XtendTypeDeclaration decl) {
boolean _isAnonymous = decl.isAnonymous();
if (_isAnonymous) {
return null;
}
final EObject container = decl.eContainer();
if ((container instanceof XtendFile)) {
final String package_ = ((XtendFile)container).getPackage();
if ((package_ == null)) {
return decl.getName();
}
String _name = decl.getName();
return ((package_ + ".") + _name);
}
if ((container instanceof XtendTypeDeclaration)) {
final String containerName = this.getQualifiedName(((XtendTypeDeclaration)container));
if ((containerName == null)) {
return null;
}
String _name_1 = decl.getName();
return ((containerName + ".") + _name_1);
}
return null;
}
@Override
public Visibility getVisibility() {
return this.getCompilationUnit().toVisibility(this.getDelegate().getVisibility());
}
@Override
public Iterable<? extends MemberDeclaration> getDeclaredMembers() {
final Function1<XtendMember, MemberDeclaration> _function = (XtendMember it) -> {
return this.getCompilationUnit().toXtendMemberDeclaration(it);
};
return ListExtensions.<XtendMember, MemberDeclaration>map(this.getDelegate().getMembers(), _function);
}
@Override
public boolean isAssignableFrom(final Type otherType) {
if ((otherType == null)) {
return false;
}
final TypeReference thisTypeRef = this.getCompilationUnit().getTypeReferenceProvider().newTypeReference(this);
final TypeReference thatTypeRef = this.getCompilationUnit().getTypeReferenceProvider().newTypeReference(otherType);
return thisTypeRef.isAssignableFrom(thatTypeRef);
}
@Override
public ConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
final Function1<ConstructorDeclaration, Boolean> _function = (ConstructorDeclaration constructor) -> {
final Function1<ParameterDeclaration, TypeReference> _function_1 = (ParameterDeclaration it) -> {
return it.getType();
};
List<TypeReference> _list = IterableExtensions.<TypeReference>toList(IterableExtensions.map(constructor.getParameters(), _function_1));
List<TypeReference> _list_1 = IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>)Conversions.doWrapArray(parameterTypes)));
return Boolean.valueOf(Objects.equals(_list, _list_1));
};
return IterableExtensions.findFirst(this.getDeclaredConstructors(), _function);
}
@Override
public FieldDeclaration findDeclaredField(final String name) {
final Function1<FieldDeclaration, Boolean> _function = (FieldDeclaration field) -> {
String _simpleName = field.getSimpleName();
return Boolean.valueOf(Objects.equals(_simpleName, name));
};
return IterableExtensions.findFirst(this.getDeclaredFields(), _function);
}
@Override
public TypeDeclaration findDeclaredType(final String name) {
final Function1<TypeDeclaration, Boolean> _function = (TypeDeclaration type) -> {
String _simpleName = type.getSimpleName();
return Boolean.valueOf(Objects.equals(_simpleName, name));
};
return IterableExtensions.findFirst(this.getDeclaredTypes(), _function);
}
@Override
public MethodDeclaration findDeclaredMethod(final String name, final TypeReference... parameterTypes) {
final Function1<MethodDeclaration, Boolean> _function = (MethodDeclaration method) -> {
return Boolean.valueOf((Objects.equals(method.getSimpleName(), name) && Objects.equals(IterableExtensions.<TypeReference>toList(IterableExtensions.map(method.getParameters(), ((Function1<ParameterDeclaration, TypeReference>) (ParameterDeclaration it) -> {
return it.getType();
}))), IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>)Conversions.doWrapArray(parameterTypes))))));
};
return IterableExtensions.findFirst(this.getDeclaredMethods(), _function);
}
@Override
public Iterable<? extends MethodDeclaration> getDeclaredMethods() {
return Iterables.<MethodDeclaration>filter(this.getDeclaredMembers(), MethodDeclaration.class);
}
@Override
public Iterable<? extends FieldDeclaration> getDeclaredFields() {
return Iterables.<FieldDeclaration>filter(this.getDeclaredMembers(), FieldDeclaration.class);
}
@Override
public Iterable<? extends ClassDeclaration> getDeclaredClasses() {
return Iterables.<ClassDeclaration>filter(this.getDeclaredMembers(), ClassDeclaration.class);
}
@Override
public Iterable<? extends ConstructorDeclaration> getDeclaredConstructors() {
return Iterables.<ConstructorDeclaration>filter(this.getDeclaredMembers(), ConstructorDeclaration.class);
}
@Override
public Iterable<? extends InterfaceDeclaration> getDeclaredInterfaces() {
return Iterables.<InterfaceDeclaration>filter(this.getDeclaredMembers(), InterfaceDeclaration.class);
}
@Override
public Iterable<? extends AnnotationTypeDeclaration> getDeclaredAnnotationTypes() {
return Iterables.<AnnotationTypeDeclaration>filter(this.getDeclaredMembers(), AnnotationTypeDeclaration.class);
}
@Override
public Iterable<? extends EnumerationTypeDeclaration> getDeclaredEnumerationTypes() {
return Iterables.<EnumerationTypeDeclaration>filter(this.getDeclaredMembers(), EnumerationTypeDeclaration.class);
}
@Override
public Iterable<? extends TypeDeclaration> getDeclaredTypes() {
return Iterables.<TypeDeclaration>filter(this.getDeclaredMembers(), TypeDeclaration.class);
}
}