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

The following examples show how to use org.eclipse.xtext.common.types.JvmGenericType#isInterface() . 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: ConstructorTypeScopeWrapper.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void addFeatureDescriptions(IEObjectDescription typeDescription, List<IEObjectDescription> result) {
	EObject proxy = getResolvedProxy(typeDescription);
	if (!proxy.eIsProxy() && proxy instanceof JvmGenericType) {
		JvmGenericType type = (JvmGenericType) proxy;
		if (!type.isInterface()) {
			for(JvmConstructor constructor: type.getDeclaredConstructors()) {
				boolean visible = visibilityHelper.isVisible(constructor);
				ConstructorDescription constructorDescription = createConstructorDescription(typeDescription, constructor, visible);
				result.add(constructorDescription);
			}
		} else if (!strict) {
			result.add(new SimpleIdentifiableElementDescription(typeDescription));
		}
	} else if (proxy instanceof JvmType) {
		if (!strict)
			result.add(new SimpleIdentifiableElementDescription(typeDescription));
	}
}
 
Example 2
Source File: XtendEObjectAtOffsetHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected EObject resolveCrossReferencedElement(INode node) {
	EObject referencedElement = super.resolveCrossReferencedElement(node);
	EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
	if(referenceOwner instanceof XConstructorCall) {
		if (referenceOwner.eContainer() instanceof AnonymousClass) {
			AnonymousClass anon = (AnonymousClass) referenceOwner.eContainer();
			JvmGenericType superType = anonymousClassUtil.getSuperType(anon);
			if(superType != null) {
				if (referencedElement instanceof JvmGenericType)  
					return superType;
				else if(referencedElement instanceof JvmConstructor) {
					if(superType.isInterface())
						return superType;
					JvmConstructor superConstructor = anonymousClassUtil.getSuperTypeConstructor(anon);
					if(superConstructor != null)
						return superConstructor;
				}
			}
		}
	}
	return referencedElement;
}
 
Example 3
Source File: XtendValidator.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Determine whether the given type contributes to the conflict caused by the given default interface implementation.
 */
private boolean contributesToConflict(JvmGenericType rootType, ConflictingDefaultOperation conflictingDefaultOperation) {
	Set<JvmDeclaredType> involvedInterfaces = Sets.newHashSet();
	involvedInterfaces.add(conflictingDefaultOperation.getDeclaration().getDeclaringType());
	for (IResolvedOperation conflictingOperation : conflictingDefaultOperation.getConflictingOperations()) {
		involvedInterfaces.add(conflictingOperation.getDeclaration().getDeclaringType());
	}
	RecursionGuard<JvmDeclaredType> recursionGuard = new RecursionGuard<JvmDeclaredType>();
	if (rootType.isInterface()) {
		int contributingCount = 0;
		for (JvmTypeReference typeRef : rootType.getExtendedInterfaces()) {
			JvmType rawType = typeRef.getType();
			if (rawType instanceof JvmDeclaredType && contributesToConflict((JvmDeclaredType) rawType, involvedInterfaces, recursionGuard)) {
				contributingCount++;
			}
		}
		return contributingCount >= 2;
	} else {
		return contributesToConflict(rootType, involvedInterfaces, recursionGuard);
	}
}
 
Example 4
Source File: JvmTypesResourceDescriptionStrategy.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void createUserData(EObject eObject, ImmutableMap.Builder<String, String> userData) {
	if (eObject instanceof JvmDeclaredType) {
		userData.put(SIGNATURE_HASH_KEY, hashProvider.getHash((JvmDeclaredType) eObject));
		if (eObject.eContainer() != null) {
			userData.put(IS_NESTED_TYPE, Boolean.TRUE.toString());
		}
	}
	if (eObject instanceof JvmGenericType) {
		JvmGenericType genericType = (JvmGenericType) eObject;
		if (genericType.isInterface())
			userData.put(IS_INTERFACE, Boolean.TRUE.toString());
		if (!genericType.getTypeParameters().isEmpty()) {
			String result = "<";
			for (Iterator<JvmTypeParameter> iterator = genericType.getTypeParameters().iterator(); iterator.hasNext();) {
				JvmTypeParameter type = iterator.next();
				result += type.getSimpleName();
				if (iterator.hasNext()) {
					result += ",";
				}
			}
			result +=">";
			userData.put(TYPE_PARAMETERS, result);
		}
	}
}
 
Example 5
Source File: AbstractConstructorScope.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Iterable<IEObjectDescription> getElements(final QualifiedName name) {
	IEObjectDescription typeDescription = typeScope.getSingleElement(name);
	if (typeDescription == null)
		return emptySet();
	JvmType type = (JvmType) typeDescription.getEObjectOrProxy();
	if (type.eIsProxy() || !(type instanceof JvmGenericType)) {
		return emptySet();
	}
	final JvmGenericType castedType = (JvmGenericType) type;
	if (castedType.isInterface()) {
		return emptySet();
	}
	Iterable<JvmConstructor> constructors = new Iterable<JvmConstructor>() {
		@Override
		public Iterator<JvmConstructor> iterator() {
			return castedType.getDeclaredConstructors().iterator();
		}
	};
	return transform(constructors, new Function<JvmConstructor,IEObjectDescription>(){
		@Override
		public IEObjectDescription apply(JvmConstructor from) {
			return EObjectDescription.create(name, from);
		}
	});
}
 
Example 6
Source File: JvmModelCompleter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void completeJvmGenericType(JvmGenericType element) {
	// if no super type add Object
	ensureSuperTypeObject(element);
	addAnnotations(element);
	if (!element.isInterface()) {
		// if no constructors have been added, add a default constructor
		if (isEmpty(element.getDeclaredConstructors())) {
			JvmConstructor constructor = TypesFactory.eINSTANCE.createJvmConstructor();
			constructor.setSimpleName(element.getSimpleName());
			constructor.setVisibility(JvmVisibility.PUBLIC);
			typeExtensions.setSynthetic(constructor, true);
			EObject primarySourceElement = associations.getPrimarySourceElement(element);
			if (primarySourceElement != null) {
				associator.associate(primarySourceElement, constructor);
			}
			element.getMembers().add(constructor);
		}
	}
}
 
Example 7
Source File: XbaseHighlightingCalculator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected String getStyle(JvmGenericType type) {
	if (type.isInterface()) {
		return INTERFACE;
	} else if (type.isAbstract()) {
		return ABSTRACT_CLASS;
	} else {
		return CLASS;
	}
}
 
Example 8
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ITreeAppendable _generateModifier(final JvmGenericType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    this.generateVisibilityModifier(it, appendable);
    boolean _isInterface = it.isInterface();
    boolean _not = (!_isInterface);
    if (_not) {
      if ((it.isStatic() && (!this.isDeclaredWithinInterface(it)))) {
        appendable.append("static ");
      }
      boolean _isAbstract = it.isAbstract();
      if (_isAbstract) {
        appendable.append("abstract ");
      }
    }
    boolean _isFinal = it.isFinal();
    if (_isFinal) {
      appendable.append("final ");
    }
    ITreeAppendable _xifexpression = null;
    boolean _isStrictFloatingPoint = it.isStrictFloatingPoint();
    if (_isStrictFloatingPoint) {
      _xifexpression = appendable.append("strictfp ");
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 9
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ITreeAppendable _generateBody(final JvmGenericType it, final ITreeAppendable appendable, final GeneratorConfig config) {
  ITreeAppendable _xblockexpression = null;
  {
    this.generateJavaDoc(it, appendable, config);
    final ITreeAppendable childAppendable = appendable.trace(it);
    this.generateAnnotations(it.getAnnotations(), childAppendable, true, config);
    this.generateModifier(it, childAppendable, config);
    boolean _isInterface = it.isInterface();
    if (_isInterface) {
      childAppendable.append("interface ");
    } else {
      childAppendable.append("class ");
    }
    this._treeAppendableUtil.traceSignificant(childAppendable, it).append(this.makeJavaIdentifier(it.getSimpleName()));
    this.generateTypeParameterDeclaration(it, childAppendable, config);
    boolean _isEmpty = it.getTypeParameters().isEmpty();
    if (_isEmpty) {
      childAppendable.append(" ");
    }
    this.generateExtendsClause(it, childAppendable, config);
    this.generateMembersInBody(it, childAppendable, config);
    ITreeAppendable _xifexpression = null;
    if (((!it.isAnonymous()) && (!(it.eContainer() instanceof JvmType)))) {
      _xifexpression = appendable.newLine();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 10
Source File: Utils.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies if the given type is a functional interface.
 *
 * <p>This function does not test if the {@code @FunctionalInterface} is attached to the type.
 * The function counts the number of operations.
 *
 * @param type the type to test.
 * @param sarlSignatureProvider the provider of SARL operation signatures.
 * @return {@code true} if the given type is final.
 */
public static boolean isFunctionalInterface(JvmGenericType type, IActionPrototypeProvider sarlSignatureProvider) {
	if (type != null && type.isInterface()) {
		final Map<ActionPrototype, JvmOperation> operations = new HashMap<>();
		populateInterfaceElements(type, operations, null, sarlSignatureProvider);
		if (operations.size() == 1) {
			final JvmOperation op = operations.values().iterator().next();
			return !op.isStatic() && !op.isDefault();
		}
	}
	return false;
}
 
Example 11
Source File: XbaseLabelProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected ImageDescriptor _imageDescriptor(JvmGenericType genericType) {
	return genericType.isInterface() // 
			? images.forInterface(genericType.getVisibility(), adornments.get(genericType)) //
			: images.forClass(genericType.getVisibility(), adornments.get(genericType));
}
 
Example 12
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 13
Source File: SARLLabelProvider.java    From sarl with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("checkstyle:npathcomplexity")
@Override
public ImageDescriptor getImageDescriptorForQualifiedName(String qualifiedName, Notifier context,
		IJvmTypeProvider typeProvider) {
	JvmType type = null;
	if (typeProvider != null) {
		type = typeProvider.findTypeByName(qualifiedName);
	}
	if (type == null && context != null) {
		type = this.services.getTypeReferences().findDeclaredType(qualifiedName, context);
	}
	int adornments = this.adornments.get(type);
	JvmVisibility visibility = JvmVisibility.DEFAULT;
	if (type != null) {
		if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
			final JvmGenericType gtype = (JvmGenericType) type;
			visibility = gtype.getVisibility();
			final int ecoreCode = this.inheritanceHelper.getSarlElementEcoreType(gtype);
			switch (ecoreCode) {
			case SarlPackage.SARL_AGENT:
				return this.images.forAgent(visibility, this.adornments.get(gtype));
			case SarlPackage.SARL_BEHAVIOR:
				return this.images.forBehavior(visibility, this.adornments.get(gtype));
			case SarlPackage.SARL_CAPACITY:
				// Remove the "abstract" ornment because capacities are always abstract.
				adornments = (adornments & JavaElementImageDescriptor.ABSTRACT) ^ adornments;
				return this.images.forCapacity(visibility, adornments);
			case SarlPackage.SARL_EVENT:
				return this.images.forEvent(visibility, this.adornments.get(gtype));
			case SarlPackage.SARL_SKILL:
				return this.images.forSkill(visibility, this.adornments.get(gtype));
			default:
				if (gtype.isInterface()) {
					return this.images.forInterface(visibility, this.adornments.get(gtype));
				}
			}
		} else if (type.eClass() == TypesPackage.Literals.JVM_ENUMERATION_TYPE) {
			final JvmEnumerationType etype = (JvmEnumerationType) type;
			visibility = etype.getVisibility();
			return this.images.forEnum(visibility, adornments);
		} else if (type.eClass() == TypesPackage.Literals.JVM_ANNOTATION_TYPE) {
			final JvmAnnotationType atype = (JvmAnnotationType) type;
			visibility = atype.getVisibility();
			return this.images.forAnnotation(visibility, adornments);
		} else {
			visibility = JvmVisibility.DEFAULT;
		}
	}
	// Default icon is the class icon.
	return this.images.forClass(visibility, adornments);
}
 
Example 14
Source File: InheritanceHelper.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies if the given JVM element is a SARL agent.
 *
 * @param type the JVM type to test.
 * @return {@code true} if the given type is a SARL agent, or not.
 * @since 0.6
 */
public boolean isSarlAgent(JvmGenericType type) {
	return !type.isInterface() && getSarlElementEcoreType(type) == SarlPackage.SARL_AGENT;
}
 
Example 15
Source File: InheritanceHelper.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies if the given JVM element is a SARL behavior.
 *
 * @param type the JVM type to test.
 * @return {@code true} if the given type is a SARL behavior, or not.
 * @since 0.6
 */
public boolean isSarlBehavior(JvmGenericType type) {
	return !type.isInterface() && getSarlElementEcoreType(type) == SarlPackage.SARL_BEHAVIOR;
}
 
Example 16
Source File: InheritanceHelper.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies if the given JVM element is a SARL capacity.
 *
 * @param type the JVM type to test.
 * @return {@code true} if the given type is a SARL capacity, or not.
 * @since 0.6
 */
public boolean isSarlCapacity(JvmGenericType type) {
	return type.isInterface() && getSarlElementEcoreType(type) == SarlPackage.SARL_CAPACITY;
}
 
Example 17
Source File: InheritanceHelper.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies if the given JVM element is a SARL event.
 *
 * @param type the JVM type to test.
 * @return {@code true} if the given type is a SARL event, or not.
 * @since 0.6
 */
public boolean isSarlEvent(JvmGenericType type) {
	return !type.isInterface() && getSarlElementEcoreType(type) == SarlPackage.SARL_EVENT;
}
 
Example 18
Source File: InheritanceHelper.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies if the given JVM element is a SARL skill.
 *
 * @param type the JVM type to test.
 * @return {@code true} if the given type is a SARL skill, or not.
 * @since 0.6
 */
public boolean isSarlSkill(JvmGenericType type) {
	return !type.isInterface() && getSarlElementEcoreType(type) == SarlPackage.SARL_SKILL;
}
 
Example 19
Source File: SARLJvmModelInferrer.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Append the serial number field if and only if the container type is serializable.
 *
 * <p>The serial number field is computed from the given context and from the generated fields.
 *
 * @param context the current generation context.
 * @param source the source object.
 * @param target the inferred JVM object.
 * @see #appendSerialNumber(GenerationContext, XtendTypeDeclaration, JvmGenericType)
 */
protected void appendSerialNumberIfSerializable(GenerationContext context, XtendTypeDeclaration source, JvmGenericType target) {
	if (!target.isInterface() && this.inheritanceHelper.isSubTypeOf(target, Serializable.class, null)) {
		appendSerialNumber(context, source, target);
	}
}
 
Example 20
Source File: SARLJvmModelInferrer.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Append the clone function only if the type is a subtype of {@link Cloneable}.
 *
 * <p>The clone function replies a value of the current type, not {@code Object}.
 *
 * @param context the current generation context.
 * @param source the source object.
 * @param target the inferred JVM object.
 * @since 0.6
 * @see #appendCloneFunction(GenerationContext, XtendTypeDeclaration, JvmGenericType)
 */
protected void appendCloneFunctionIfCloneable(GenerationContext context, XtendTypeDeclaration source, JvmGenericType target) {
	if (!target.isInterface() && this.inheritanceHelper.isSubTypeOf(target, Cloneable.class, null)) {
		appendCloneFunction(context, source, target);
	}
}