org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder Java Examples

The following examples show how to use org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder. 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: MissedMethodAddModification.java    From sarl with Apache License 2.0 6 votes vote down vote up
private List<JvmTypeParameter> cloneTypeParameters(JvmOperation fromOperation, JvmDeclaredType declaringType) {
	final SARLQuickfixProvider tools = getTools();
	final JvmTypeReferenceBuilder builder1 = tools.getJvmTypeParameterBuilder();
	final JvmTypesBuilder builder2 = tools.getJvmTypeBuilder();
	final TypeReferences builder3 = tools.getTypeServices().getTypeReferences();
	final TypesFactory builder4 = tools.getTypeServices().getTypesFactory();
	final List<JvmTypeParameter> outParameters = new ArrayList<>();
	// Get the type parameter mapping that is a consequence of the super type extension within the container.
	final Map<String, JvmTypeReference> superTypeParameterMapping = new HashMap<>();
	Utils.getSuperTypeParameterMap(declaringType, superTypeParameterMapping);
	Utils.copyTypeParametersFromJvmOperation(
			fromOperation.getTypeParameters(),
			outParameters,
			superTypeParameterMapping,
			builder1, builder2, builder3, builder4);
	return outParameters;
}
 
Example #2
Source File: JvmTypesBuilderTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void expectErrorLogging(final int numberOfloggings, final Runnable block) {
  final LoggingTester.LogCapture loggings = LoggingTester.captureLogging(Level.ERROR, JvmTypesBuilder.class, block);
  loggings.assertNumberOfLogEntries(numberOfloggings);
}
 
Example #3
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Pure
public JvmTypesBuilder getJvmTypesBuilder() {
  return this.jvmTypesBuilder;
}
 
Example #4
Source File: Utils.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Clone the given type reference that for being link to the given operation.
 *
 * <p>The proxies are not resolved, and the type parameters are clone when they are
 * related to the type parameter of the type container.
 *
 * @param type the source type.
 * @param executableTypeParameters the type parameters of the executable component that will contain the result type.
 * @param superTypeParameterMapping the mapping from the type parameters inherited from the super types.
 * @param typeParameterBuilder the builder if type parameter.
 * @param typeBuilder the builder of type.
 * @param typeReferences the builder of type references.
 * @param jvmTypesFactory the factory of Jvm types.
 * @return the result type, i.e. a copy of the source type.
 * @since 0.6
 */
public static JvmTypeReference cloneWithTypeParametersAndProxies(
		JvmTypeReference type,
		Iterable<JvmTypeParameter> executableTypeParameters,
		Map<String, JvmTypeReference> superTypeParameterMapping,
		JvmTypeReferenceBuilder typeParameterBuilder, JvmTypesBuilder typeBuilder,
		TypeReferences typeReferences, TypesFactory jvmTypesFactory) {
	if (type == null) {
		return typeParameterBuilder.typeRef(Object.class);
	}

	boolean cloneType = true;
	JvmTypeReference typeCandidate = type;

	// Use also cloneType as a flag that indicates if the type was already found in type parameters.
	if ((executableTypeParameters.iterator().hasNext() || !superTypeParameterMapping.isEmpty()) && cloneType) {
		final Map<String, JvmTypeParameter> typeParameterIdentifiers = new TreeMap<>();
		for (final JvmTypeParameter typeParameter : executableTypeParameters) {
			typeParameterIdentifiers.put(typeParameter.getIdentifier(), typeParameter);
		}

		if (type instanceof JvmParameterizedTypeReference) {
			// Try to clone the type parameters.
			cloneType = false;
			typeCandidate = cloneAndAssociate(type, typeParameterIdentifiers, superTypeParameterMapping,
					typeParameterBuilder, typeReferences, jvmTypesFactory);
		} else if (type instanceof XFunctionTypeRef) {
			// Try to clone the function reference.
			final XFunctionTypeRef functionRef = (XFunctionTypeRef) type;
			cloneType = false;
			final XFunctionTypeRef cloneReference = XtypeFactory.eINSTANCE.createXFunctionTypeRef();
			for (final JvmTypeReference paramType : functionRef.getParamTypes()) {
				cloneReference.getParamTypes().add(cloneAndAssociate(
						paramType, typeParameterIdentifiers, superTypeParameterMapping,
						typeParameterBuilder, typeReferences, jvmTypesFactory));
			}
			cloneReference.setReturnType(cloneAndAssociate(
					functionRef.getReturnType(), typeParameterIdentifiers, superTypeParameterMapping,
					typeParameterBuilder, typeReferences, jvmTypesFactory));
			cloneReference.setInstanceContext(functionRef.isInstanceContext());
			typeCandidate = cloneReference;
		}
	}

	// Do the clone according to the type of the entity.
	assert typeCandidate != null;
	final JvmTypeReference returnType;
	if (!cloneType) {
		returnType = typeCandidate;
	} else {
		returnType = typeBuilder.cloneWithProxies(typeCandidate);
	}
	return returnType;
}
 
Example #5
Source File: AbstractExtraLanguageGenerator.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Change the type builder.
 *
 * @param builder the builder.
 */
@Inject
public void setTypeBuilder(JvmTypesBuilder builder) {
	this.jvmTypesBuilder = builder;
}
 
Example #6
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Change the type builder.
 *
 * @param builder the builder.
 */
@Inject
public void setTypeBuilder(JvmTypesBuilder builder) {
	this.jvmTypesBuilder = builder;
}
 
Example #7
Source File: Utils.java    From sarl with Apache License 2.0 3 votes vote down vote up
/** Copy the type parameters from a JvmOperation.
 *
 * <p>This function differs from {@link XtendJvmModelInferrer#copyAndFixTypeParameters(List,
 * org.eclipse.xtext.common.types.JvmTypeParameterDeclarator)}
 * and {@link XtendJvmModelInferrer#copyTypeParameters(List, org.eclipse.xtext.common.types.JvmTypeParameterDeclarator)}
 * in the fact that the type parameters were already generated and fixed. The current function supper generic types by
 * clone the types references with {@link #cloneWithTypeParametersAndProxies(JvmTypeReference, Iterable, Map, JvmTypeReferenceBuilder,
 * JvmTypesBuilder, TypeReferences, TypesFactory)}.
 *
 * @param fromOperation the operation from which the type parameters are copied.
 * @param toOperation the operation that will receives the new type parameters.
 * @param typeParameterBuilder the builder if type parameter.
 * @param typeBuilder the builder of type.
 * @param typeReferences the builder of type references.
 * @param jvmTypesFactory the factory of Jvm types.
 * @since 0.6
 */
public static void copyTypeParametersFromJvmOperation(JvmOperation fromOperation, JvmOperation toOperation,
		JvmTypeReferenceBuilder typeParameterBuilder, JvmTypesBuilder typeBuilder,
		TypeReferences typeReferences, TypesFactory jvmTypesFactory) {
	// Get the type parameter mapping that is a consequence of the super type extension within the container.
	final Map<String, JvmTypeReference> superTypeParameterMapping = new HashMap<>();
	Utils.getSuperTypeParameterMap(toOperation.getDeclaringType(), superTypeParameterMapping);
	copyTypeParametersFromJvmOperation(
			fromOperation.getTypeParameters(),
			toOperation.getTypeParameters(),
			superTypeParameterMapping,
			typeParameterBuilder, typeBuilder, typeReferences, jvmTypesFactory);
}
 
Example #8
Source File: SARLQuickfixProvider.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies the type builder.
 *
 * @return the builder.
 * @since 0.6
 */
public JvmTypesBuilder getJvmTypeBuilder() {
	return this.typeBuilder;
}
 
Example #9
Source File: AbstractExtraLanguageGenerator.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies the type builder.
 *
 * @return the builder.
 */
public JvmTypesBuilder getTypeBuilder() {
	return this.jvmTypesBuilder;
}
 
Example #10
Source File: AbstractExpressionGenerator.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies the type builder.
 *
 * @return the builder.
 */
public JvmTypesBuilder getTypeBuilder() {
	return this.jvmTypesBuilder;
}