Java Code Examples for org.eclipse.xtext.common.types.JvmGenericType#setVisibility()

The following examples show how to use org.eclipse.xtext.common.types.JvmGenericType#setVisibility() . 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
protected void initialize(XtendInterface source, JvmGenericType inferredJvmType) {
	inferredJvmType.setVisibility(source.getVisibility());
	inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
	inferredJvmType.setAbstract(true);
	inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
	translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
	for (JvmTypeReference intf : source.getExtends()) {
		inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
	}
	fixTypeParameters(inferredJvmType);
	for (XtendMember member : source.getMembers()) {
		if (member instanceof XtendField
				|| (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)) {
			transform(member, inferredJvmType, false);
		}
	}
	jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
	nameClashResolver.resolveNameClashes(inferredJvmType);
}
 
Example 2
protected JvmGenericType createJvmGenericType(/* @Nullable */ EObject sourceElement, /* @Nullable */ String name) {
	if (sourceElement == null || name == null)
		return null;
	Pair<String, String> fullName = splitQualifiedName(name);
	final JvmGenericType result = typesFactory.createJvmGenericType();
	result.setSimpleName(fullName.getSecond());
	if (fullName.getFirst() != null)
		result.setPackageName(fullName.getFirst());
	result.setVisibility(JvmVisibility.PUBLIC);
	return result;
}
 
Example 3
/**
 * Anonymous classes are not inferred in the type inference phase, but later during type resolution. 
 */
public void inferLocalClass(
		AnonymousClass anonymousClass,
		String localClassName,
		JvmFeature container) {
	final JvmGenericType inferredType = typesFactory.createJvmGenericType();
	inferredType.setSimpleName(localClassName);
	inferredType.setAnonymous(!hasAdditionalMembers(anonymousClass));
	inferredType.setFinal(true);
	inferredType.setVisibility(JvmVisibility.DEFAULT);
	inferredType.getSuperTypes().add(jvmTypesBuilder.inferredType(anonymousClass));
	container.getLocalClasses().add(inferredType);
	associator.associatePrimary(anonymousClass, inferredType);
	for (XtendMember member : anonymousClass.getMembers()) {
		if (member instanceof XtendField
				|| (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)
				|| member instanceof XtendConstructor) {
			transform(member, inferredType, true);
		}
	}
	
	appendSyntheticDispatchMethods(anonymousClass, inferredType);
	nameClashResolver.resolveNameClashes(inferredType);
	final XConstructorCall constructorCall = anonymousClass.getConstructorCall();
	for (XExpression actualParameter : constructorCall.getArguments()) {
		associator.associateLogicalContainer(actualParameter, container);
	}
}
 
Example 4
@Override
public void registerClass(final String qualifiedName) throws IllegalArgumentException {
  final JvmGenericType newType = TypesFactory.eINSTANCE.createJvmGenericType();
  newType.setVisibility(JvmVisibility.PUBLIC);
  EList<JvmTypeReference> _superTypes = newType.getSuperTypes();
  JvmTypeReference _typeForName = this.compilationUnit.getTypeReferences().getTypeForName(Object.class, this.compilationUnit.getXtendFile());
  _superTypes.add(_typeForName);
  this.setNameAndAccept(newType, qualifiedName);
}
 
Example 5
@Override
public void registerInterface(final String qualifiedName) throws IllegalArgumentException {
  final JvmGenericType newType = TypesFactory.eINSTANCE.createJvmGenericType();
  newType.setVisibility(JvmVisibility.PUBLIC);
  newType.setInterface(true);
  this.setNameAndAccept(newType, qualifiedName);
}
 
Example 6
protected void initialize(XtendClass source, JvmGenericType inferredJvmType) {
	inferredJvmType.setVisibility(source.getVisibility());
	boolean isStatic = source.isStatic() && !isTopLevel(source);
	if (!isStatic) {
		JvmDeclaredType declaringType = inferredJvmType.getDeclaringType();
		if (declaringType instanceof JvmGenericType) {
			if (((JvmGenericType) declaringType).isInterface())
				isStatic = true;
		} else if (declaringType instanceof JvmAnnotationType) {
			isStatic = true;
		}
	}
	inferredJvmType.setStatic(isStatic);
	inferredJvmType.setAbstract(source.isAbstract());
	inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
	if (!inferredJvmType.isAbstract()) {
		inferredJvmType.setFinal(source.isFinal());
	}
	translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
	JvmTypeReference extendsClause = source.getExtends();
	if (extendsClause == null || extendsClause.getType() == null) {
		JvmTypeReference typeRefToObject = typeReferences.getTypeForName(Object.class, source);
		if (typeRefToObject != null)
			inferredJvmType.getSuperTypes().add(typeRefToObject);
	} else {
		inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(extendsClause));
	}
	for (JvmTypeReference intf : source.getImplements()) {
		inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
	}
	fixTypeParameters(inferredJvmType);
	addDefaultConstructor(source, inferredJvmType);
	for (XtendMember member : source.getMembers()) {
		if (member instanceof XtendField
				|| (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)
				|| member instanceof XtendConstructor) {
			transform(member, inferredJvmType, true);
		}
	}
	
	appendSyntheticDispatchMethods(source, inferredJvmType);
	jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
	nameClashResolver.resolveNameClashes(inferredJvmType);
	
}
 
Example 7
Source Project: sarl   File: SARLJvmModelInferrer.java    License: Apache License 2.0 4 votes vote down vote up
/** Initialize the SARL capacity context-aware wrapper.
 *
 * @param source the source.
 * @param inferredJvmType the JVM type.
 * @since 0.6
 */
protected void appendCapacityContextAwareWrapper(SarlCapacity source, JvmGenericType inferredJvmType) {
	final JvmGenericType innerType = this.typesFactory.createJvmGenericType();
	innerType.setInterface(false);
	innerType.setAbstract(false);
	innerType.setVisibility(JvmVisibility.PUBLIC);
	innerType.setStatic(true);
	innerType.setStrictFloatingPoint(false);
	innerType.setFinal(false);
	final String innerTypeName = Capacity.ContextAwareCapacityWrapper.class.getSimpleName();
	innerType.setSimpleName(innerTypeName);

	inferredJvmType.getMembers().add(innerType);

	this.typeBuilder.setDocumentation(innerType, "@ExcludeFromApidoc"); //$NON-NLS-1$

	final JvmTypeParameter typeParameter = this.typesFactory.createJvmTypeParameter();
	typeParameter.setName("C"); //$NON-NLS-1$
	final JvmUpperBound constraint = this.typesFactory.createJvmUpperBound();
	constraint.setTypeReference(this._typeReferenceBuilder.typeRef(inferredJvmType));
	typeParameter.getConstraints().add(constraint);
	innerType.getTypeParameters().add(typeParameter);

	final Iterator<JvmTypeReference> extendedTypeIterator = inferredJvmType.getExtendedInterfaces().iterator();
	if (extendedTypeIterator.hasNext()) {
		final JvmTypeReference extendedType = extendedTypeIterator.next();
		final JvmTypeReference superType = this._typeReferenceBuilder.typeRef(
				extendedType.getQualifiedName() + "$" + innerTypeName, //$NON-NLS-1$
				this._typeReferenceBuilder.typeRef(typeParameter));
		innerType.getSuperTypes().add(superType);
	}

	innerType.getSuperTypes().add(this._typeReferenceBuilder.typeRef(inferredJvmType));

	final JvmConstructor constructor = this.typesFactory.createJvmConstructor();
	constructor.setVisibility(JvmVisibility.PUBLIC);
	innerType.getMembers().add(constructor);
	final JvmFormalParameter parameter1 = this.typesFactory.createJvmFormalParameter();
	parameter1.setName("capacity"); //$NON-NLS-1$
	parameter1.setParameterType(this._typeReferenceBuilder.typeRef(typeParameter));
	constructor.getParameters().add(parameter1);
	final JvmFormalParameter parameter2 = this.typesFactory.createJvmFormalParameter();
	parameter2.setName("caller"); //$NON-NLS-1$
	parameter2.setParameterType(this._typeReferenceBuilder.typeRef(AgentTrait.class));
	constructor.getParameters().add(parameter2);
	setBody(constructor, it -> {
		it.append("super(capacity, caller);"); //$NON-NLS-1$
	});

	final Set<ActionPrototype> createdActions = new TreeSet<>();
	for (final JvmGenericType sourceType : Iterables.concat(
			Collections.singletonList(inferredJvmType),
			Iterables.transform(Iterables.skip(inferredJvmType.getExtendedInterfaces(), 1), it -> {
				return (JvmGenericType) it.getType();
			}))) {
		copyNonStaticPublicJvmOperations(sourceType, innerType, createdActions, (operation, it) -> {
			it.append("try {"); //$NON-NLS-1$
			it.newLine();
			it.append("  ensureCallerInLocalThread();"); //$NON-NLS-1$
			it.newLine();
			it.append("  "); //$NON-NLS-1$
			if (operation.getReturnType() != null && !Objects.equal("void", operation.getReturnType().getIdentifier())) { //$NON-NLS-1$
				it.append("return "); //$NON-NLS-1$
			}
			it.append("this.capacity."); //$NON-NLS-1$
			it.append(operation.getSimpleName());
			it.append("("); //$NON-NLS-1$
			boolean first = true;
			for (final JvmFormalParameter fparam : operation.getParameters()) {
				if (first) {
					first = false;
				} else {
					it.append(", "); //$NON-NLS-1$
				}
				it.append(fparam.getName());
			}
			it.append(");"); //$NON-NLS-1$
			it.newLine();
			it.append("} finally {"); //$NON-NLS-1$
			it.newLine();
			it.append("  resetCallerInLocalThread();"); //$NON-NLS-1$
			it.newLine();
			it.append("}"); //$NON-NLS-1$
		});
	}
}