Java Code Examples for org.eclipse.emf.ecore.util.InternalEList#addUnique()

The following examples show how to use org.eclipse.emf.ecore.util.InternalEList#addUnique() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private JvmAnnotationValue createBooleanAnnotationValue(Object value) {
	JvmBooleanAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmBooleanAnnotationValue();
	if (value != null) {
		@SuppressWarnings("unchecked")
		InternalEList<Object> values = (InternalEList<Object>)(InternalEList<?>)annotationValue.getValues();
		if (value instanceof Object[]) {
			for (Object element : (Object[])value) {
				if (element instanceof Boolean) {
					values.addUnique(element);
				}
			}
		} else {
			values.addUnique(value);
		}
	}
	return annotationValue;
}
 
Example 2
Source File: JvmDeclaredTypeBuilder.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
private void setSuperTypes(String name, BinarySuperTypeSignature signature, String superName, String[] interfaces) {
   	InternalEList<JvmTypeReference> superTypes = (InternalEList<JvmTypeReference>) result.getSuperTypes();
	if (signature != null) {
		List<BinaryGenericTypeSignature> superTypeSignatures = signature.getSuperTypes();
		if (result.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE && ((JvmGenericType) result).isInterface()) {
			if (superTypeSignatures.size() > 1) {
				superTypeSignatures = superTypeSignatures.subList(1, superTypeSignatures.size());
			}
		}
		for (int i = 0; i < superTypeSignatures.size(); i++) {
			superTypes.addUnique(proxies.createTypeReference(superTypeSignatures.get(i), typeParameters));
		}
	} else {
		if (superName != null && result.eClass() != TypesPackage.Literals.JVM_ANNOTATION_TYPE) {
			superTypes.addUnique(proxies.createTypeReference(BinarySignatures.createObjectTypeSignature(superName), typeParameters));
		}
		setInterfaces(interfaces, typeParameters, superTypes);
		if (superTypes.isEmpty() && !Proxies.JAVA_LANG_OBJECT.equals(name)) {
			superTypes.addUnique(proxies.createObjectTypeReference());
		}
	}
}
 
Example 3
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private JvmAnnotationValue createCharAnnotationValue(Object value) {
	JvmCharAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmCharAnnotationValue();
	if (value != null) {
		@SuppressWarnings("unchecked")
		InternalEList<Object> values = (InternalEList<Object>)(InternalEList<?>)annotationValue.getValues();
		if (value instanceof Object[]) {
			for (Object element : (Object[])value) {
				if (element instanceof Character) {
					values.addUnique(element);
				}
			}
		} else {
			values.addUnique(value);
		}
	}
	return annotationValue;
}
 
Example 4
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private JvmAnnotationValue createTypeAnnotationValue(Object value) {
	JvmTypeAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmTypeAnnotationValue();
	if (value != null) {
		InternalEList<JvmTypeReference> values = (InternalEList<JvmTypeReference>)annotationValue.getValues();
		if (value instanceof Object[]) {
			for (Object element : (Object[])value) {
				if (element instanceof ITypeBinding) {
					values.addUnique(createTypeReference((ITypeBinding)element));
				}
			}
		} else if (value instanceof ITypeBinding) {
			values.addUnique(createTypeReference((ITypeBinding)value));
		}
	}
	return annotationValue;
}
 
Example 5
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private JvmAnnotationValue createLongAnnotationValue(Object value) {
	JvmLongAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmLongAnnotationValue();
	if (value != null) {
		@SuppressWarnings("unchecked")
		InternalEList<Object> values = (InternalEList<Object>)(InternalEList<?>)annotationValue.getValues();
		if (value instanceof Object[]) {
			for (Object element : (Object[])value) {
				if (element instanceof Long) {
					values.addUnique(element);
				} else if (element != null) {
					values.addUnique(((Number)element).longValue());
				}
			}
		} else if (value instanceof Long) {
			values.addUnique(value);
		} else if (value instanceof Number) {
			values.addUnique(((Number)value).longValue());
		}
	}
	return annotationValue;
}
 
Example 6
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmAnnotationValue createAnnotationValue(Object value, Class<?> type) {
	EStructuralFeature.Setting result = createAnnotationValue(type);
	@SuppressWarnings("unchecked")
	InternalEList<Object> values = (InternalEList<Object>)result;
	if (type.isPrimitive() || String.class == type) {
		values.addUnique(value);
	} else if (type == Class.class) {
		Class<?> referencedClass = (Class<?>) value;
		JvmTypeReference reference = createTypeReference(referencedClass);
		values.addUnique(reference);
	} else if (type.isAnnotation()) {
		Annotation nestedAnnotation = (Annotation) value;
		values.addUnique(createAnnotationReference(nestedAnnotation));
	} else if (type.isEnum()) {
		Enum<?> e = (Enum<?>) value;
		JvmEnumerationLiteral proxy = createEnumLiteralProxy(e);
		values.addUnique(proxy);
	}
	return (JvmAnnotationValue)result.getEObject();
}
 
Example 7
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private JvmAnnotationValue createFloatAnnotationValue(Object value) {
	JvmFloatAnnotationValue annotationValue = TypesFactory.eINSTANCE.createJvmFloatAnnotationValue();
	if (value != null) {
		@SuppressWarnings("unchecked")
		InternalEList<Object> values = (InternalEList<Object>)(InternalEList<?>)annotationValue.getValues();
		if (value instanceof Object[]) {
			for (Object element : (Object[])value) {
				if (element instanceof Float) {
					values.addUnique(element);
				} else if (element != null) {
					values.addUnique(((Number)element).floatValue());
				}
			}
		} else if (value instanceof Float) {
			values.addUnique(value);
		} else if (value instanceof Number) {
			values.addUnique(((Number)value).floatValue());
		}
	}
	return annotationValue;
}
 
Example 8
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.4
 */
protected JvmAnnotationReference createAnnotationReference(/* @NonNull */ IAnnotationBinding annotation) {
	JvmAnnotationReference annotationReference = TypesFactory.eINSTANCE.createJvmAnnotationReference();
	ITypeBinding annotationType = annotation.getAnnotationType();
	annotationReference.setAnnotation(createAnnotationProxy(annotationType));
	InternalEList<JvmAnnotationValue> values = (InternalEList<JvmAnnotationValue>)annotationReference.getExplicitValues();
	IMemberValuePairBinding[] allMemberValuePairs = annotation.getDeclaredMemberValuePairs();
	for (IMemberValuePairBinding memberValuePair : allMemberValuePairs) {
		IMethodBinding methodBinding = memberValuePair.getMethodBinding();
		if (methodBinding != null) {
			try {
				values.addUnique(createAnnotationValue(annotationType, memberValuePair.getValue(), methodBinding));
			} catch(NullPointerException npe) {
				// memberValuePair#getValue may throw an NPE if the methodBinding has no return type
				if (methodBinding.getReturnType() != null) {
					throw npe;
				} else {
					if (log.isDebugEnabled()) {
						log.debug(npe.getMessage(), npe);
					}
				}
			}
		}
	}
	return annotationReference;
}
 
Example 9
Source File: AbstractClosureTypeHelper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void applyToModel(IResolvedTypes resolvedTypes) {
	if (!closure.isExplicitSyntax()) {
		List<JvmFormalParameter> parametersToAdd = getParameters();
		InternalEList<JvmFormalParameter> targetList = (InternalEList<JvmFormalParameter>) closure.getImplicitFormalParameters();
		if (!targetList.isEmpty()) {
			// things are already available, do nothing
			return;
		}
		for(int i = 0; i < parametersToAdd.size(); i++) {
			JvmFormalParameter parameter = parametersToAdd.get(i);
			LightweightTypeReference parameterType = resolvedTypes.getActualType(parameter);
			if (parameterType == null) {
				throw new IllegalStateException("Cannot find type for parameter " + parameter.getSimpleName());
			}
			JvmTypeReference typeReference = parameterType.toTypeReference();
			parameter.setParameterType(typeReference);
			targetList.addUnique(parameter);
		}
	}
	((XClosureImplCustom) closure).setLinked(true);
}
 
Example 10
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void createMethods(Class<?> clazz, JvmDeclaredType result) {
	try {
		Method[] declaredMethods = clazz.getDeclaredMethods();
		if (declaredMethods.length != 0) {
			boolean intf = clazz.isInterface() && !clazz.isAnnotation();
			InternalEList<JvmMember> members = (InternalEList<JvmMember>)result.getMembers();
			for (Method method : declaredMethods) {
				if (!method.isSynthetic()) {
					JvmOperation operation = createOperation(method);
					if (clazz.isAnnotation()) {
						setDefaultValue(operation, method);
					} else if (intf && !operation.isAbstract() && !operation.isStatic()) {
						operation.setDefault(true);
					}
					members.addUnique(operation);
				}
			}
		}
	} catch (NoClassDefFoundError e) {
		logNoClassDefFoundError(e, clazz, "methods");
	}
}
 
Example 11
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void setParameterNamesAndAnnotations(IMethodBinding method, ITypeBinding[] parameterTypes,
		String[] parameterNames, JvmExecutable result) {
	InternalEList<JvmFormalParameter> parameters = (InternalEList<JvmFormalParameter>)result.getParameters();
	for (int i = 0; i < parameterTypes.length; i++) {
		IAnnotationBinding[] parameterAnnotations;
		try {
			parameterAnnotations = method.getParameterAnnotations(i);
		} catch(AbortCompilation aborted) {
			parameterAnnotations = null;
		}
		ITypeBinding parameterType = parameterTypes[i];
		String parameterName = parameterNames == null ? null /* lazy */ : i < parameterNames.length ? parameterNames[i] : "arg" + i;
		JvmFormalParameter formalParameter = createFormalParameter(parameterType, parameterName, parameterAnnotations);
		parameters.addUnique(formalParameter);
	}
}
 
Example 12
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createAnnotationValues(IBinding annotated, JvmAnnotationTarget result) {
	try {
		resolveAnnotations.start();
		IAnnotationBinding[] annotationBindings = annotated.getAnnotations();
		if (annotationBindings.length != 0) {
			InternalEList<JvmAnnotationReference> annotations = (InternalEList<JvmAnnotationReference>)result.getAnnotations();
			for (IAnnotationBinding annotation : annotationBindings) {
				annotations.addUnique(createAnnotationReference(annotation));
			}
		}
	} catch(AbortCompilation aborted) {
		if (aborted.problem.getID() == IProblem.IsClassPathCorrect) {
			// ignore
		} else {
			log.info("Couldn't resolve annotations of "+annotated, aborted);
		}
	} finally {
		resolveAnnotations.stop();
	}
}
 
Example 13
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void createConstructors(Class<?> clazz, JvmDeclaredType result) {
	try {
		Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors();
		if (declaredConstructors.length != 0) {
			InternalEList<JvmMember> members = (InternalEList<JvmMember>)result.getMembers();
			for (Constructor<?> constructor : declaredConstructors) {
				if (!constructor.isSynthetic()) {
					members.addUnique(createConstructor(constructor));
				}
			}
		}
	} catch (NoClassDefFoundError e) {
		logNoClassDefFoundError(e, clazz, "constructors");
	}
}
 
Example 14
Source File: BuilderStateUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void copyReferenceDescriptions(IResourceDescription from, ResourceDescriptionImpl result) {
	Iterator<IReferenceDescription> sourceReferenceDescriptions = from.getReferenceDescriptions().iterator();
	if (sourceReferenceDescriptions.hasNext()) {
		InternalEList<IReferenceDescription> targetReferenceDescriptions = (InternalEList<IReferenceDescription>) result.getReferenceDescriptions();
		do {
			targetReferenceDescriptions.addUnique(BuilderStateUtil.create(sourceReferenceDescriptions.next()));	
		} while(sourceReferenceDescriptions.hasNext());
	}
}
 
Example 15
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void enhanceGenericDeclaration(JvmExecutable result, GenericDeclaration declaration) {
	TypeVariable<?>[] typeParameters = declaration.getTypeParameters();
	if (typeParameters.length != 0) {
		InternalEList<JvmTypeParameter> jvmTypeParameters = (InternalEList<JvmTypeParameter>)result.getTypeParameters();
		for (TypeVariable<?> variable : typeParameters) {
			jvmTypeParameters.addUnique(createTypeParameter(variable, result));
		}
	}
}
 
Example 16
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private JvmTypeReference enhanceTypeReference(ParameterizedType parameterizedType,
		JvmParameterizedTypeReference result) {
	result.setType(createProxy(parameterizedType.getRawType()));
	Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
	if (actualTypeArguments.length != 0) {
		InternalEList<JvmTypeReference> arguments = (InternalEList<JvmTypeReference>)result.getArguments();
		for (Type actualTypeArgument : actualTypeArguments) {
			JvmTypeReference argument = createTypeArgument(actualTypeArgument);
			arguments.addUnique(argument);
		}
	}
	return result;
}
 
Example 17
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected JvmTypeParameter createTypeParameter(TypeVariable<?> variable, JvmMember container) {
	JvmTypeParameter result = TypesFactory.eINSTANCE.createJvmTypeParameter();
	result.setName(variable.getName());
	Type[] bounds = variable.getBounds();
	if (bounds.length != 0) {
		InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>)result.getConstraints();
		for (Type bound : variable.getBounds()) {
			JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
			((JvmTypeConstraintImplCustom) upperBound).internalSetTypeReference(createTypeReference(bound));
			constraints.addUnique(upperBound);
		}
	}
	return result;
}
 
Example 18
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void createAnnotationValues(final AnnotatedElement annotated, final JvmAnnotationTarget result) {
	Annotation[] declaredAnnotations = annotated.getDeclaredAnnotations();
	if (declaredAnnotations.length != 0) {
		InternalEList<JvmAnnotationReference> annotations = (InternalEList<JvmAnnotationReference>)result.getAnnotations();
		for (Annotation annotation : declaredAnnotations) {
			annotations.addUnique(createAnnotationReference(annotation));
		}
	}
}
 
Example 19
Source File: JvmExecutableBuilder.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void visitEnd() {
	InternalEList<JvmMember> members = (InternalEList<JvmMember>) declarator.getMembers();
	members.addUnique(result);
}
 
Example 20
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @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));
		}
	}
}