Java Code Examples for org.eclipse.xtext.common.types.JvmOperation#setFinal()

The following examples show how to use org.eclipse.xtext.common.types.JvmOperation#setFinal() . 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
/**
 * @since 2.4
 */
protected JvmOperation createOperation(StringBuilder qualifiedName, String handleIdentifier, String[] path, IMethodBinding method) {
	JvmOperation result = TypesFactory.eINSTANCE.createJvmOperation();
	enhanceGenericDeclaration(result, method.getTypeParameters());
	enhanceExecutable(qualifiedName, handleIdentifier, path, result, method);
	int modifiers = method.getModifiers();
	result.setAbstract(Modifier.isAbstract(modifiers));
	result.setFinal(Modifier.isFinal(modifiers));
	result.setStatic(Modifier.isStatic(modifiers));
	result.setStrictFloatingPoint(Modifier.isStrictfp(modifiers));
	result.setSynchronized(Modifier.isSynchronized(modifiers));
	result.setNative(Modifier.isNative(modifiers));
	result.setReturnType(createTypeReference(method.getReturnType()));
	createAnnotationValues(method, result);
	return result;
}
 
Example 2
Source File: XtendJvmModelInferrer.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected void transform(XtendFunction source, JvmGenericType container, boolean allowDispatch) {
	JvmOperation operation = typesFactory.createJvmOperation();
	operation.setAbstract(source.isAbstract());
	operation.setNative(source.isNative());
	operation.setSynchronized(source.isSynchonized());
	operation.setStrictFloatingPoint(source.isStrictFloatingPoint());
	if (!source.isAbstract())
		operation.setFinal(source.isFinal());
	container.getMembers().add(operation);
	associator.associatePrimary(source, operation);
	String sourceName = source.getName();
	JvmVisibility visibility = source.getVisibility();
	if (allowDispatch && source.isDispatch()) {
		if (source.getDeclaredVisibility() == null)
			visibility = JvmVisibility.PROTECTED;
		sourceName = "_" + sourceName;
	}
	operation.setSimpleName(sourceName);
	operation.setVisibility(visibility);
	operation.setStatic(source.isStatic());
	if (!operation.isAbstract() && !operation.isStatic() && container.isInterface())
		operation.setDefault(true);
	for (XtendParameter parameter : source.getParameters()) {
		translateParameter(operation, parameter);
	}
	XExpression expression = source.getExpression();
	CreateExtensionInfo createExtensionInfo = source.getCreateExtensionInfo();
	
	JvmTypeReference returnType = null;
	if (source.getReturnType() != null) {
		returnType = jvmTypesBuilder.cloneWithProxies(source.getReturnType());
	} else if (createExtensionInfo != null) {
		returnType = jvmTypesBuilder.inferredType(createExtensionInfo.getCreateExpression());
	} else if (expression != null) {
		returnType = jvmTypesBuilder.inferredType(expression);
	} else {
		returnType = jvmTypesBuilder.inferredType();
	}
	
	operation.setReturnType(returnType);
	copyAndFixTypeParameters(source.getTypeParameters(), operation);
	for (JvmTypeReference exception : source.getExceptions()) {
		operation.getExceptions().add(jvmTypesBuilder.cloneWithProxies(exception));
	}
	translateAnnotationsTo(source.getAnnotations(), operation);
	if (source.isOverride() && typeReferences.findDeclaredType(Override.class, source) != null)
		setOverride(operation);
	if (createExtensionInfo != null) {
		transformCreateExtension(source, createExtensionInfo, container, operation, returnType);
	} else {
		setBody(operation, expression);
	}
	jvmTypesBuilder.copyDocumentationTo(source, operation);
}
 
Example 3
Source File: SARLJvmModelInferrer.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Append the guard evaluators.
 *
 * @param container the container type.
 */
protected void appendEventGuardEvaluators(JvmGenericType container) {
	final GenerationContext context = getContext(container);
	if (context != null) {
		final Collection<Pair<SarlBehaviorUnit, Collection<Procedure1<? super ITreeAppendable>>>> allEvaluators
				= context.getGuardEvaluationCodes();
		if (allEvaluators == null || allEvaluators.isEmpty()) {
			return;
		}

		final JvmTypeReference voidType = this._typeReferenceBuilder.typeRef(Void.TYPE);
		final JvmTypeReference runnableType = this._typeReferenceBuilder.typeRef(Runnable.class);
		final JvmTypeReference collectionType = this._typeReferenceBuilder.typeRef(Collection.class, runnableType);
		for (final Pair<SarlBehaviorUnit, Collection<Procedure1<? super ITreeAppendable>>> evaluators : allEvaluators) {
			final SarlBehaviorUnit source = evaluators.getKey();
			// Determine the name of the operation for the behavior output
			final String behName = Utils.createNameForHiddenGuardGeneralEvaluatorMethod(source.getName().getSimpleName());

			// Create the main function
			final JvmOperation operation = this.typesFactory.createJvmOperation();

			// Annotation for the event bus

			appendGeneratedAnnotation(operation, context);
			addAnnotationSafe(operation, PerceptGuardEvaluator.class);

			// Guard evaluator unit parameters
			// - Event occurrence
			JvmFormalParameter jvmParam = this.typesFactory.createJvmFormalParameter();
			jvmParam.setName(this.grammarKeywordAccess.getOccurrenceKeyword());
			jvmParam.setParameterType(this.typeBuilder.cloneWithProxies(source.getName()));
			this.associator.associate(source, jvmParam);
			operation.getParameters().add(jvmParam);
			// - List of runnables
			jvmParam = this.typesFactory.createJvmFormalParameter();
			jvmParam.setName(RUNNABLE_COLLECTION);
			jvmParam.setParameterType(this.typeBuilder.cloneWithProxies(collectionType));
			operation.getParameters().add(jvmParam);

			operation.setAbstract(false);
			operation.setNative(false);
			operation.setSynchronized(false);
			operation.setStrictFloatingPoint(false);
			operation.setFinal(false);
			operation.setVisibility(JvmVisibility.PRIVATE);
			operation.setStatic(false);
			operation.setSimpleName(behName);
			operation.setReturnType(this.typeBuilder.cloneWithProxies(voidType));
			container.getMembers().add(operation);

			setBody(operation, it -> {
				it.append("assert "); //$NON-NLS-1$
				it.append(this.grammarKeywordAccess.getOccurrenceKeyword());
				it.append(" != null;"); //$NON-NLS-1$
				it.newLine();
				it.append("assert "); //$NON-NLS-1$
				it.append(RUNNABLE_COLLECTION);
				it.append(" != null;"); //$NON-NLS-1$
				for (final Procedure1<? super ITreeAppendable> code : evaluators.getValue()) {
					it.newLine();
					code.apply(it);
				}
			});

			this.associator.associatePrimary(source, operation);
			this.typeBuilder.copyDocumentationTo(source, operation);
		}
	}
}
 
Example 4
Source File: SARLJvmModelInferrer.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Copy the JVM operations from the source to the destination.
 *
 * @param source the source.
 * @param target the destination.
 * @param createdActions the set of actions that are created before (input) or during (output) the invocation.
 * @param bodyBuilder the builder of the target's operations.
 * @since 0.5
 */
@SuppressWarnings("checkstyle:npathcomplexity")
protected void copyNonStaticPublicJvmOperations(JvmGenericType source, JvmGenericType target,
		Set<ActionPrototype> createdActions, Procedure2<? super JvmOperation, ? super ITreeAppendable> bodyBuilder) {
	final Iterable<JvmOperation> operations = Iterables.transform(Iterables.filter(source.getMembers(), it -> {
		if (it instanceof JvmOperation) {
			final JvmOperation op = (JvmOperation) it;
			return !op.isStatic() && op.getVisibility() == JvmVisibility.PUBLIC;
		}
		return false;
	}), it -> (JvmOperation) it);
	for (final JvmOperation operation : operations) {
		final ActionParameterTypes types = this.sarlSignatureProvider.createParameterTypesFromJvmModel(
				operation.isVarArgs(), operation.getParameters());
		final ActionPrototype actSigKey = this.sarlSignatureProvider.createActionPrototype(
				operation.getSimpleName(), types);
		if (createdActions.add(actSigKey)) {
			final JvmOperation newOp = this.typesFactory.createJvmOperation();
			target.getMembers().add(newOp);

			newOp.setAbstract(false);
			newOp.setFinal(false);
			newOp.setNative(false);
			newOp.setStatic(false);
			newOp.setSynchronized(false);
			newOp.setVisibility(JvmVisibility.PUBLIC);

			newOp.setDefault(operation.isDefault());
			newOp.setDeprecated(operation.isDeprecated());
			newOp.setSimpleName(operation.getSimpleName());
			newOp.setStrictFloatingPoint(operation.isStrictFloatingPoint());

			copyTypeParametersFromJvmOperation(operation, newOp);

			for (final JvmTypeReference exception : operation.getExceptions()) {
				newOp.getExceptions().add(cloneWithTypeParametersAndProxies(exception, newOp));
			}

			for (final JvmFormalParameter parameter : operation.getParameters()) {
				final JvmFormalParameter newParam = this.typesFactory.createJvmFormalParameter();
				newOp.getParameters().add(newParam);
				newParam.setName(parameter.getSimpleName());
				newParam.setParameterType(cloneWithTypeParametersAndProxies(parameter.getParameterType(), newOp));
			}

			newOp.setVarArgs(operation.isVarArgs());

			newOp.setReturnType(cloneWithTypeParametersAndProxies(operation.getReturnType(), newOp));

			setBody(newOp, it -> bodyBuilder.apply(operation, it));
		}
	}
}