use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createTypeParameter.
protected JvmTypeParameter createTypeParameter(ITypeBinding parameter, JvmMember container) {
resolveTypeParams.start();
JvmTypeParameter result = TypesFactory.eINSTANCE.createJvmTypeParameter();
result.setName(parameter.getName());
InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>) result.getConstraints();
ITypeBinding[] typeBounds = parameter.getTypeBounds();
if (typeBounds.length != 0) {
for (ITypeBinding bound : typeBounds) {
JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
upperBound.setTypeReference(createTypeReference(bound));
constraints.addUnique(upperBound);
}
} else {
JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
upperBound.setTypeReference(createObjectClassReference());
constraints.addUnique(upperBound);
}
resolveTypeParams.stop();
return result;
}
use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method setSuperTypes.
/**
* @since 2.4
*/
protected void setSuperTypes(ITypeBinding binding, String qualifiedName, JvmDeclaredType result) {
ITypeBinding superclass = binding.getSuperclass();
InternalEList<JvmTypeReference> superTypes = (InternalEList<JvmTypeReference>) result.getSuperTypes();
if (superclass != null) {
superTypes.addUnique(createTypeReference(superclass));
}
for (ITypeBinding intf : binding.getInterfaces()) {
superTypes.addUnique(createTypeReference(intf));
}
if (superTypes.isEmpty() && !OBJECT_CLASS_NAME.equals(qualifiedName)) {
superTypes.addUnique(createObjectClassReference());
}
}
use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createType.
/**
* @since 2.4
*/
protected JvmDeclaredType createType(ITypeBinding typeBinding, String handleIdentifier, List<String> path, StringBuilder fqn) {
if (typeBinding.isAnonymous() || typeBinding.isSynthetic())
throw new IllegalStateException("Cannot create type for anonymous or synthetic classes");
// Creates the right type of instance based on the type of binding.
//
JvmGenericType jvmGenericType;
JvmDeclaredType result;
if (typeBinding.isAnnotation()) {
jvmGenericType = null;
result = TypesFactory.eINSTANCE.createJvmAnnotationType();
} else if (typeBinding.isEnum()) {
jvmGenericType = null;
result = TypesFactory.eINSTANCE.createJvmEnumerationType();
} else {
result = jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
jvmGenericType.setInterface(typeBinding.isInterface());
}
// Populate the information computed from the modifiers.
//
int modifiers = typeBinding.getModifiers();
setTypeModifiers(result, modifiers);
result.setDeprecated(typeBinding.isDeprecated());
setVisibility(result, modifiers);
// Determine the simple name and compose the fully qualified name and path, remembering the fqn length and path size so we can reset them.
//
String simpleName = typeBinding.getName();
fqn.append(simpleName);
int length = fqn.length();
int size = path.size();
path.add(simpleName);
String qualifiedName = fqn.toString();
result.internalSetIdentifier(qualifiedName);
result.setSimpleName(simpleName);
// Traverse the nested types using '$' as the qualified name separator.
//
fqn.append('$');
createNestedTypes(typeBinding, result, handleIdentifier, path, fqn);
// Traverse the methods using '.'as the qualifed name separator.
//
fqn.setLength(length);
fqn.append('.');
createMethods(typeBinding, handleIdentifier, path, fqn, result);
createFields(typeBinding, fqn, result);
// Set the super types.
//
setSuperTypes(typeBinding, qualifiedName, result);
//
if (jvmGenericType != null) {
ITypeBinding[] typeParameterBindings = typeBinding.getTypeParameters();
if (typeParameterBindings.length > 0) {
InternalEList<JvmTypeParameter> typeParameters = (InternalEList<JvmTypeParameter>) jvmGenericType.getTypeParameters();
for (ITypeBinding variable : typeParameterBindings) {
typeParameters.addUnique(createTypeParameter(variable, result));
}
}
}
// Populate the annotation values.
//
createAnnotationValues(typeBinding, result);
// Restore the path.
//
path.remove(size);
return result;
}
use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method enhanceExecutable.
/**
* @since 2.4
*/
protected void enhanceExecutable(StringBuilder fqn, String handleIdentifier, String[] path, JvmExecutable result, IMethodBinding method) {
String name = method.getName();
fqn.append(name);
fqn.append('(');
ITypeBinding[] parameterTypes = method.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
if (i != 0)
fqn.append(',');
fqn.append(getQualifiedName(parameterTypes[i]));
}
fqn.append(')');
result.internalSetIdentifier(fqn.toString());
result.setSimpleName(name);
setVisibility(result, method.getModifiers());
result.setDeprecated(method.isDeprecated());
if (parameterTypes.length > 0) {
result.setVarArgs(method.isVarargs());
String[] parameterNames = null;
// If the method is derived from source, we can efficiently determine the parameter names now.
//
ITypeBinding declaringClass = method.getDeclaringClass();
if (declaringClass.isFromSource()) {
parameterNames = getParameterNamesFromSource(fqn, method);
} else {
// Use the key to determine the signature for the method.
//
SegmentSequence signaturex = getSignatureAsSegmentSequence(method);
ParameterNameInitializer initializer = jdtCompliance.createParameterNameInitializer(method, workingCopyOwner, result, handleIdentifier, path, name, signaturex);
((JvmExecutableImplCustom) result).setParameterNameInitializer(initializer);
}
setParameterNamesAndAnnotations(method, parameterTypes, parameterNames, result);
}
ITypeBinding[] exceptionTypes = method.getExceptionTypes();
if (exceptionTypes.length > 0) {
InternalEList<JvmTypeReference> exceptions = (InternalEList<JvmTypeReference>) result.getExceptions();
for (ITypeBinding exceptionType : exceptionTypes) {
exceptions.addUnique(createTypeReference(exceptionType));
}
}
}
use of org.eclipse.emf.ecore.util.InternalEList in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createTypeReference.
/**
* Returns a type reference for the given type binding. If the binding is null, an {@link JvmUnknownTypeReference unknown}
* type reference is returned.
*/
// @NonNull
protected JvmTypeReference createTypeReference(/* @Nullable */
ITypeBinding typeBinding) {
if (typeBinding == null) {
return TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
}
if (typeBinding.isArray()) {
ITypeBinding componentType = typeBinding.getComponentType();
JvmTypeReference componentTypeReference = createTypeReference(componentType);
JvmGenericArrayTypeReference typeReference = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference();
typeReference.setComponentType(componentTypeReference);
return typeReference;
}
ITypeBinding outer = null;
if (typeBinding.isMember() && !Modifier.isStatic(typeBinding.getModifiers())) {
outer = typeBinding.getDeclaringClass();
}
JvmParameterizedTypeReference result;
if (outer != null) {
JvmParameterizedTypeReference outerReference = (JvmParameterizedTypeReference) createTypeReference(outer);
result = TypesFactory.eINSTANCE.createJvmInnerTypeReference();
((JvmInnerTypeReference) result).setOuter(outerReference);
} else {
result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
}
ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
if (typeArguments.length != 0) {
ITypeBinding erasure = typeBinding.getErasure();
result.setType(createProxy(erasure));
InternalEList<JvmTypeReference> arguments = (InternalEList<JvmTypeReference>) result.getArguments();
for (int i = 0; i < typeArguments.length; i++) {
JvmTypeReference argument = createTypeArgument(typeArguments[i]);
arguments.addUnique(argument);
}
} else {
result.setType(createProxy(typeBinding));
}
return result;
}
Aggregations