Java Code Examples for org.eclipse.xtext.common.types.JvmType#eIsProxy()
The following examples show how to use
org.eclipse.xtext.common.types.JvmType#eIsProxy() .
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: RawTypeHelper.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public JvmTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference, Resource resource) { JvmType type = reference.getType(); if (type != null && !type.eIsProxy()) { if (type instanceof JvmTypeParameterDeclarator) { if (!((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty()) { JvmParameterizedTypeReference result = factory.createJvmParameterizedTypeReference(); result.setType(type); return result; } } else if (type instanceof JvmTypeParameter) { return getRawTypeFromConstraints(((JvmTypeParameter) type).getConstraints(), resource); } } return reference; }
Example 2
Source File: AbstractRuntimeJvmTypeProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public JvmType tryFindTypeInIndex(String name, AbstractRuntimeJvmTypeProvider typeProvider, boolean binaryNestedTypeDelimiter) throws UnknownNestedTypeException { JvmType result = typeByQueryString.get(name); if (result != null) { if (result.eIsProxy()) { typeByQueryString.remove(name); } else { return result; } } JvmType candidate = typeProvider.doTryFindInIndex(name, binaryNestedTypeDelimiter); if (candidate != null) { typeByQueryString.put(name, candidate); return candidate; } return null; }
Example 3
Source File: SARLValidator.java From sarl with Apache License 2.0 | 6 votes |
/** Check for {@code @Inline} annotation usage. * * @param annotationTarget thee target to test. */ @Check public void checkManualInlineDefinition(XtendAnnotationTarget annotationTarget) { if (!isIgnored(MANUAL_INLINE_DEFINITION)) { if (annotationTarget.getAnnotations().isEmpty() || !isRelevantAnnotationTarget(annotationTarget)) { return; } final String inlineAnnotation = Inline.class.getName(); for (final XAnnotation annotation : annotationTarget.getAnnotations()) { final JvmType type = annotation.getAnnotationType(); if (type != null && !type.eIsProxy()) { if (Objects.equal(type.getIdentifier(), inlineAnnotation)) { addIssue( Messages.SARLValidator_16, annotation, MANUAL_INLINE_DEFINITION); } } } } }
Example 4
Source File: RawTypeReferenceComputer.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public JvmTypeReference doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference, Pair<Resource, Set<JvmType>> context) { JvmType type = reference.getType(); if (type != null && !type.eIsProxy()) { if (type instanceof JvmTypeParameterDeclarator) { if (!((JvmTypeParameterDeclarator) type).getTypeParameters().isEmpty()) { JvmParameterizedTypeReference result = factory.createJvmParameterizedTypeReference(); result.setType(type); return result; } } else if (type instanceof JvmTypeParameter) { Set<JvmType> recursionGuard = context.getSecond(); if (recursionGuard.add(type)) { return getRawTypeFromConstraints(((JvmTypeParameter) type).getConstraints(), context); } else { return createObjectReference(context.getFirst()); } } } return reference; }
Example 5
Source File: XbaseWithAnnotationsValidator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Check public void checkAllAttributesConfigured(XAnnotation annotation) { JvmType annotationType = annotation.getAnnotationType(); if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) return; Iterable<JvmOperation> attributes = ((JvmAnnotationType) annotationType).getDeclaredOperations(); for (JvmOperation jvmOperation : attributes) { XExpression value = annotationUtil.findValue(annotation, jvmOperation); if(value == null) { if (jvmOperation.getDefaultValue() == null) { error("The annotation must define the attribute '"+jvmOperation.getSimpleName()+"'.", annotation, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ANNOTATIONS_MISSING_ATTRIBUTE_DEFINITION); } } else annotationValueValidator.validateAnnotationValue(value, this); } }
Example 6
Source File: IndexingLightweightTypeReferenceFactory.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
public boolean isProcedure(XFunctionTypeRefImplCustom it) { JvmTypeReference returnType = it.getReturnType(); if (returnType == null) { return true; } JvmType type = getType(returnType); if (type == null) { return false; } if (type.eIsProxy()) { return false; } if (type instanceof JvmVoid) { return true; } return false; }
Example 7
Source File: ImportsCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private void addJavaDocReferences(final INode documentationNode, final ITextRegion selectedRegion, final ImportsAcceptor acceptor) { List<ReplaceRegion> _computeTypeRefRegions = this.javaDocTypeReferenceProvider.computeTypeRefRegions(documentationNode); for (final ReplaceRegion docTypeReference : _computeTypeRefRegions) { { int _offset = docTypeReference.getOffset(); int _length = docTypeReference.getLength(); final TextRegion referenceRange = new TextRegion(_offset, _length); boolean _contains = selectedRegion.contains(referenceRange); if (_contains) { String docTypeText = docTypeReference.getText(); final EObject element = NodeModelUtils.findActualSemanticObjectFor(documentationNode); IScope scope = this.scopeProvider.getScope(element, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE); IEObjectDescription singleElement = scope.getSingleElement(QualifiedName.create(docTypeText)); JvmType referencedType = null; if ((singleElement != null)) { EObject _eObjectOrProxy = singleElement.getEObjectOrProxy(); referencedType = ((JvmType) _eObjectOrProxy); } if (((referencedType instanceof JvmDeclaredType) && (!referencedType.eIsProxy()))) { JvmDeclaredType casted = ((JvmDeclaredType) referencedType); boolean _equals = casted.getQualifiedName().equals(docTypeText); boolean _not = (!_equals); if (_not) { acceptor.acceptTypeImport(casted); } } } } } }
Example 8
Source File: XbaseWithAnnotationsProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void completeXAnnotation_Value(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { if (model instanceof XAnnotation) { JvmType annotationType = ((XAnnotation) model).getAnnotationType(); if (annotationType != null && !annotationType.eIsProxy() && annotationType instanceof JvmAnnotationType) { JvmAnnotationType casted = (JvmAnnotationType) annotationType; List<JvmOperation> operations = Lists.newArrayList(casted.getDeclaredOperations()); if (operations.size() == 1) { JvmOperation singleOperation = operations.get(0); if ("value".equals(singleOperation.getSimpleName())) { // TODO propose qualified enum literals + import super.completeXAnnotation_Value(model, assignment, context, acceptor); if ("java.lang.Class".equals(getRawReturnType(singleOperation))) { // eager proposals for classes if the expected type is a suptype of class // TODO evaluate the bounds of the class completeJavaTypes( context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, true, // force getQualifiedNameValueConverter(), createVisibilityFilter(context), acceptor); } else { proposeDeclaringTypeForStaticInvocation(model, assignment, context, acceptor); } } } } } }
Example 9
Source File: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
private int internalGetPrimitiveKindFromWrapper(ParameterizedTypeReference typeReference) { JvmType type = typeReference.getType(); if (type == null || type.eIsProxy()) { return PRIMITIVE_NONE; } EClass eClass = type.eClass(); if (eClass != TypesPackage.Literals.JVM_GENERIC_TYPE) { if (eClass == TypesPackage.Literals.JVM_TYPE_PARAMETER) { return internalGetPrimitiveKindFromWrapper((JvmTypeParameter)type, null); } return PRIMITIVE_NONE; } return internalGetPrimitiveKindFromWrapper((JvmGenericType)type); }
Example 10
Source File: RawTypeHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public List<JvmType> doVisitParameterizedTypeReference(JvmParameterizedTypeReference reference, Resource resource) { JvmType type = reference.getType(); if (type != null && !type.eIsProxy()) { if (type instanceof JvmTypeParameter) { return getRawTypesFromConstraints(((JvmTypeParameter) type).getConstraints(), resource); } return Collections.singletonList(type); } return Collections.emptyList(); }
Example 11
Source File: ImportedTypesCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void acceptType(JvmType type, JvmType usedType, ITextRegion refRegion) { JvmMember currentContext = getCurrentContext(); if (currentContext == null) { return; } if (type == null || type.eIsProxy()) { throw new IllegalArgumentException(); } if (type instanceof JvmDeclaredType && !isIgnored(type, refRegion)) { getTypeUsages().addTypeUsage((JvmDeclaredType) type, (JvmDeclaredType) usedType, refRegion, currentContext); } }
Example 12
Source File: ConstantExpressionsInterpreter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private void collect(final JvmDeclaredType type, final Set<JvmType> seen, final Map<String, JvmIdentifiableElement> result) { boolean _add = seen.add(type); if (_add) { EList<JvmMember> _members = type.getMembers(); for (final JvmMember member : _members) { if ((member instanceof JvmField)) { if ((((JvmField)member).isFinal() && ((JvmField)member).isStatic())) { final JvmIdentifiableElement existing = result.put(((JvmField)member).getSimpleName(), member); if ((existing != null)) { result.put(existing.getSimpleName(), existing); } } } } EList<JvmTypeReference> _superTypes = type.getSuperTypes(); for (final JvmTypeReference superType : _superTypes) { { JvmType _type = null; if (superType!=null) { _type=superType.getType(); } final JvmType rawSuperType = _type; if (((rawSuperType instanceof JvmDeclaredType) && (!rawSuperType.eIsProxy()))) { this.collect(((JvmDeclaredType) rawSuperType), seen, result); } } } } }
Example 13
Source File: XImportDeclarationImplCustom.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public String getImportedTypeName() { String result = getImportedNamespace(); if (result == null) { if (this.eIsSet(XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE)) { JvmType unresolvedType = (JvmType) this.eGet(XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE, false); if(!unresolvedType.eIsProxy()) return unresolvedType.getIdentifier(); List<INode> list = NodeModelUtils.findNodesForFeature(this, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE); StringBuilder sb = new StringBuilder(); for (INode iNode : list) { sb.append(NodeModelUtils.getTokenText(iNode).replace("^", "")); } result = sb.toString().replace(" ", ""); if (isStatic()) { return trim(result, 1); } return result; } return null; } if (isWildcard()) { return trim(result, 2); } return result; }
Example 14
Source File: ResolvedFeatures.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void computeAllOperationsFromSuperTypes(JvmDeclaredType type, Multimap<String, AbstractResolvedOperation> processedOperations, Set<JvmType> processedTypes) { for (JvmTypeReference superType: type.getSuperTypes()) { JvmType rawSuperType = superType.getType(); if (rawSuperType instanceof JvmDeclaredType && !rawSuperType.eIsProxy() && processedTypes.add(rawSuperType)) { computeAllOperations((JvmDeclaredType) rawSuperType, processedOperations); computeAllOperationsFromSuperTypes((JvmDeclaredType) rawSuperType, processedOperations, processedTypes); } } }
Example 15
Source File: XtendResourceDescription.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
public void registerAllTypes(final JvmType type, final Function1<? super String, ? extends Boolean> acceptor) { if (((type == null) || type.eIsProxy())) { return; } if (((!this.isLocal(type)) && (acceptor.apply(type.getIdentifier())).booleanValue())) { boolean _matched = false; if (type instanceof JvmGenericType) { _matched=true; this.registerAllTypes(((JvmGenericType)type).getDeclaringType(), acceptor); JvmTypeReference _extendedClass = null; if (((JvmGenericType)type)!=null) { _extendedClass=((JvmGenericType)type).getExtendedClass(); } JvmType _type = null; if (_extendedClass!=null) { _type=_extendedClass.getType(); } this.registerAllTypes(_type, acceptor); final Consumer<JvmTypeReference> _function = (JvmTypeReference it) -> { JvmType _type_1 = null; if (it!=null) { _type_1=it.getType(); } this.registerAllTypes(_type_1, acceptor); }; ((JvmGenericType)type).getExtendedInterfaces().forEach(_function); } } }
Example 16
Source File: DeclaratorTypeArgumentCollector.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public Boolean doVisitParameterizedTypeReference(ParameterizedTypeReference reference, LightweightTraversalData data) { JvmType type = reference.getType(); // TODO improve handling of redundant super types where a better path to the supertype exists /* * e.g. MyList extends AbstractList implements List<String> {} * the implements clause seems to be redundant but provides more reliable information */ if (!type.eIsProxy() && data.getVisited().add(type)) { return doVisitParameterizedTypeReference(reference, type, data); } return Boolean.FALSE; }
Example 17
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * Translates a single {@link XAnnotation} to {@link JvmAnnotationReference} that can be added to a {@link JvmAnnotationTarget}. * * @param anno the source annotation * * @return a {@link JvmAnnotationReference} that can be attached to some {@link JvmAnnotationTarget} */ /* @Nullable */ public JvmAnnotationReference getJvmAnnotationReference(/* @Nullable */ XAnnotation anno) { if(anno == null) return null; JvmAnnotationReference reference = typesFactory.createJvmAnnotationReference(); final JvmType annotation = (JvmType) anno.eGet( XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false); if (annotation.eIsProxy()) { JvmAnnotationType copiedProxy = TypesFactory.eINSTANCE.createJvmAnnotationType(); ((InternalEObject)copiedProxy).eSetProxyURI(EcoreUtil.getURI(annotation)); reference.setAnnotation(copiedProxy); } else if (annotation instanceof JvmAnnotationType){ reference.setAnnotation((JvmAnnotationType) annotation); } for (XAnnotationElementValuePair val : anno.getElementValuePairs()) { XExpression valueExpression = val.getValue(); JvmAnnotationValue annotationValue = toJvmAnnotationValue(valueExpression); if (annotationValue != null) { JvmOperation op = (JvmOperation) val.eGet( XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT, false); annotationValue.setOperation(op); reference.getExplicitValues().add(annotationValue); } } if (anno.getValue() != null) { JvmAnnotationValue value = toJvmAnnotationValue(anno.getValue()); if (value != null) { reference.getExplicitValues().add(value); } } associate(anno, reference); return reference; }
Example 18
Source File: ExtensionScopeHelper.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isMatchingFirstParameter(JvmOperation feature) { List<JvmFormalParameter> parameters = feature.getParameters(); JvmFormalParameter firstParameter = parameters.get(0); JvmTypeReference type = firstParameter.getParameterType(); if (type == null) return false; JvmType rawParameterType = type.getType(); if (rawParameterType == null || rawParameterType.eIsProxy()) return false; if (!(rawParameterType instanceof JvmTypeParameter)) { if (rawArgumentType.isResolved()) { // short circuit - limit extension scope entries to real candidates LightweightTypeReference parameterTypeReference = rawArgumentType.getOwner().toPlainTypeReference(rawParameterType); if (parameterTypeReference.isResolved() && !parameterTypeReference.isAssignableFrom(rawArgumentType)) { if (parameterTypeReference.isArray() && !rawArgumentType.isArray() && rawArgumentType.isSubtypeOf(Iterable.class)) { return true; } return false; } if (parameterTypeReference.isArray() && !rawArgumentType.isArray() && !rawArgumentType.isSubtypeOf(Iterable.class)) { return false; } } else if (isArrayTypeMismatch(rawArgumentType, rawParameterType)) { return false; } } return true; }
Example 19
Source File: RawTypeConformanceComputer.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
private int internalGetPrimitiveKind(ParameterizedTypeReference typeReference) { JvmType type = typeReference.getType(); EClass eClass = type.eClass(); if (eClass == TypesPackage.Literals.JVM_PRIMITIVE_TYPE) { if (type.eIsProxy()) return PRIMITIVE_NONE; String name = type.getSimpleName(); switch (name.length()) { case 3: if ("int".equals(name)) { return PRIMITIVE_INT; } break; case 4: if ("long".equals(name)) { return PRIMITIVE_LONG; } else if ("char".equals(name)) { return PRIMITIVE_CHAR; } else if ("byte".equals(name)) { return PRIMITIVE_BYTE; } break; case 5: if ("short".equals(name)) { return PRIMITIVE_SHORT; } else if ("float".equals(name)) { return PRIMITIVE_FLOAT; } break; case 6: if ("double".equals(name)) { return PRIMITIVE_DOUBLE; } break; case 7: if ("boolean".equals(name)) { return PRIMITIVE_BOOLEAN; } break; } } else if (eClass == TypesPackage.Literals.JVM_VOID) { if (type.eIsProxy()) return PRIMITIVE_NONE; return PRIMITIVE_VOID; } return PRIMITIVE_NONE; }
Example 20
Source File: IResolvedFeatures.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public IResolvedFeatures getResolvedFeatures(JvmType type) { if (type instanceof JvmDeclaredType && !type.eIsProxy()) { return RawResolvedFeatures.getResolvedFeatures((JvmDeclaredType) type, services); } return NO_FEATURES; }