protected void addDispatchError(JvmGenericType type, Iterable<JvmOperation> operations, String message, String modifier, String ISSUE_ID) { for (JvmOperation jvmOperation : operations) if (jvmOperation.getDeclaringType() == type) addDispatchError(jvmOperation, message, modifier, ISSUE_ID); }
private void markCapacityFunctions(PyAppendable it) { final Map<JvmOperation, String> mapping = this.useCapacityMapping; this.useCapacityMapping = new HashMap<>(); final ImportManager imports = it.getImportManager(); for (final Entry<JvmOperation, String> entry : mapping.entrySet()) { final JvmOperation operation = entry.getKey(); final JvmDeclaredType type = operation.getDeclaringType(); imports.addImportFor(type); it.declareVariable(operation, entry.getValue()); } }
protected boolean isGetClass(JvmIdentifiableElement feature) { if (feature instanceof JvmOperation && feature.getSimpleName().equals("getClass")) { JvmOperation getClassOperation = (JvmOperation) feature; if (getClassOperation.getParameters().isEmpty() && "java.lang.Object".equals(getClassOperation.getDeclaringType().getIdentifier())) { return true; } } return false; }
/** * @return the {@link Method} corresponding to the given {@link JvmOperation} or <code>null</code>. */ public Method getMethod(JvmOperation operation) { Class<?> declaringType = getRawType(operation.getDeclaringType()); if (declaringType == null) return null; Class<?>[] paramTypes = getParamTypes(operation); try { return declaringType.getDeclaredMethod(operation.getSimpleName(), paramTypes); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }
/** * @return the {@link Method} corresponding to the given {@link JvmOperation} or <code>null</code>. */ public Method getMethod(JvmOperation operation) { Class<?> declaringType = getRawType(operation.getDeclaringType()); if (declaringType == null) return null; Class<?>[] paramTypes = getParamTypes(operation); try { return declaringType.getDeclaredMethod(operation.getSimpleName(), paramTypes); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage(), e); } return null; }
private boolean isValidFunction(JvmOperation op) { // TODO we need context here - the op has to be visible if (op.isAbstract()) { if (Object.class.getName().equals(op.getDeclaringType().getIdentifier())) return false; final String name = op.getSimpleName(); if (name.equals("toString") && op.getParameters().isEmpty()) return false; if (name.equals("equals") && op.getParameters().size() == 1) return false; if (name.equals("hashCode") && op.getParameters().isEmpty()) return false; return true; } return false; }
/** * Return the local cases that contribute to the given dispatch operation (in no particular order, but usually as defined in the file). */ public List<JvmOperation> getLocalDispatchCases(JvmOperation dispatcherOperation) { DispatchSignature dispatchSignature = new DispatchSignature(dispatcherOperation.getSimpleName(), dispatcherOperation.getParameters().size()); JvmDeclaredType type = dispatcherOperation.getDeclaringType(); return getLocalDispatchCases(type, dispatchSignature); }
private boolean isPotentialJavaOperation(XAbstractFeatureCall featureCall) { if (featureCall.isOperation()) { return true; } if (featureCall.eClass() == XbasePackage.Literals.XMEMBER_FEATURE_CALL && featureCall.isStatic() && featureCall.isExtension() && featureCall.getActualArguments().size() == 2) { JvmIdentifiableElement feature = featureCall.getFeature(); if (feature.eClass() == TypesPackage.Literals.JVM_OPERATION) { JvmDeclaredType declarator = ((JvmOperation) feature).getDeclaringType(); if (IntegerExtensions.class.getName().equals(declarator.getIdentifier()) || LongExtensions.class.getName().equals(declarator.getIdentifier())) { String simpleName = feature.getSimpleName(); if (simpleName.startsWith("bitwise") || simpleName.startsWith("shift")) { return true; } } } } return false; }
/** * @noreference This method is not intended to be referenced by clients. */ protected void prepareComputation() { LightweightTypeReference expectedType = getExpectation().getExpectedType(); if (expectedType == null) { throw new IllegalStateException(); } JvmType type = expectedType.getType(); if (type == null) { throw new IllegalStateException(); } else if (type instanceof JvmTypeParameter) { type = operation.getDeclaringType(); } expectedClosureType = initKnownClosureType(type, operation); deferredBindTypeArgument(expectedType, expectedClosureType, BoundTypeArgumentSource.INFERRED_CONSTRAINT); }
protected LightweightTypeReference getReceiverType(XAbstractFeatureCall featureCall, IResolvedTypes resolvedTypes, ITypeReferenceOwner owner) { XExpression receiver = featureCall.getActualReceiver(); if (receiver == null) { // static feature call JvmOperation operation = (JvmOperation) featureCall.getFeature(); JvmDeclaredType declaringType = operation.getDeclaringType(); return owner.newParameterizedTypeReference(declaringType); } return resolvedTypes.getActualType(receiver); } }
public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> getFunctionTypeParameterMapping( LightweightTypeReference functionType, JvmOperation operation, ActualTypeArgumentCollector typeArgumentCollector, ITypeReferenceOwner owner) { /* * The mapping is populated by means of the function type to declarator mapping, though a method * * m(Zonk zonk) { .. } * * with * * interface Foo<X> { * void bar(X x); * } * interface Zonk extends Foo<CharSequence> {} * * infers the parameter type CharSequence for the lamba param */ LightweightTypeReference lightweightTypeReference = owner.toLightweightTypeReference(operation.getDeclaringType()); typeArgumentCollector.populateTypeParameterMapping(lightweightTypeReference, functionType); Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> typeParameterMapping = typeArgumentCollector.rawGetTypeParameterMapping(); return typeParameterMapping; }
protected boolean isConflictingDefaultImplementation(AbstractResolvedOperation overriding, AbstractResolvedOperation overridden) { JvmOperation ridingDecl = overriding.getDeclaration(); JvmOperation riddenDecl = overridden.getDeclaration(); if (isInterface(ridingDecl.getDeclaringType()) && isInterface(riddenDecl.getDeclaringType()) && (!ridingDecl.isAbstract() || !riddenDecl.isAbstract())) { LightweightTypeReference ridingTypeRef = overriding.getResolvedDeclarator(); LightweightTypeReference riddenTypeRef = overridden.getResolvedDeclarator(); return !riddenTypeRef.isAssignableFrom(ridingTypeRef); } return false; }
/** * Returns <code>null</code> if the given operation declares it's own return type or if it does not override * another operation. */ /* @Nullable */ @SuppressWarnings("unused") protected LightweightTypeReference getReturnTypeOfOverriddenOperation(JvmOperation operation, ResolvedTypes resolvedTypes, IFeatureScopeSession session) { if (operation.getVisibility() == JvmVisibility.PRIVATE) return null; if (InferredTypeIndicator.isInferred(operation.getReturnType())) { LightweightTypeReference declaringType = resolvedTypes.getActualType(operation.getDeclaringType()); if (declaringType == null) { throw new IllegalStateException("Cannot determine declaring type of operation: " + operation); } LightweightTypeReference result = overrideHelper.getReturnTypeOfOverriddenOperation(operation, declaringType); return result; } return null; }
/** * Return all the cases that are associated with the given dispatch operation. */ public List<JvmOperation> getAllDispatchCases(JvmOperation dispatcherOperation) { DispatchSignature dispatchSignature = new DispatchSignature(dispatcherOperation.getSimpleName(), dispatcherOperation.getParameters().size()); JvmDeclaredType type = dispatcherOperation.getDeclaringType(); ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, type); ContextualVisibilityHelper contextualVisibilityHelper = new ContextualVisibilityHelper(visibilityHelper, owner.newParameterizedTypeReference(type)); return getAllDispatchMethods(dispatchSignature, type, contextualVisibilityHelper); }
public JvmOperation getDispatcherOperation(JvmOperation dispatchCase) { EObject sourceElement = associations.getPrimarySourceElement(dispatchCase); if (sourceElement instanceof XtendFunction) { XtendFunction function = (XtendFunction) sourceElement; if (function.isDispatch()) { Iterable<JvmOperation> operations = filter(associations.getJvmElements(sourceElement), JvmOperation.class); for(JvmOperation operation: operations) { if (Strings.equal(operation.getSimpleName(), function.getName())) { return operation; } } } } else { DispatchSignature signature = new DispatchSignature(dispatchCase.getSimpleName().substring(1), dispatchCase.getParameters().size()); JvmOperation result = getDispatcherOperation(dispatchCase.getDeclaringType(), signature); return result; } return null; }
@Override public IResolvedOperation getAsBottom() { JvmOperation operation = getDeclaration(); JvmDeclaredType declaringType = operation.getDeclaringType(); List<LightweightTypeReference> superTypes = getContextType().getAllSuperTypes(); for(LightweightTypeReference superType: superTypes) { if (superType.getType() == declaringType) { return new BottomResolvedOperation(operation, superType, getBottom().getOverrideTester()); } } throw new IllegalStateException(String.format("Could not find declaring type of method %s in hierarchy of %s", operation.getIdentifier(), getContextType().getIdentifier())); }
private InferredPrototype getInferredPrototype(JvmOperation operation) { final XtendFunction fct = this.associations.getXtendFunction(operation); if (fct != null) { return getInferredPrototype(fct); } final QualifiedActionName actionKey = this.actionPrototypes.createQualifiedActionName( operation.getDeclaringType(), operation.getSimpleName()); // Compute the different action prototypes associated to the action to create. return this.actionPrototypes.createPrototypeFromJvmModel( actionKey, operation.isVarArgs(), operation.getParameters()); }
@Override protected void checkAssignment(XExpression expression, EStructuralFeature feature, boolean simpleAssignment) { if (simpleAssignment && expression instanceof XAbstractFeatureCall) { final JvmIdentifiableElement assignmentFeature = ((XAbstractFeatureCall) expression).getFeature(); if (assignmentFeature instanceof JvmField) { final JvmField field = (JvmField) assignmentFeature; if (!field.isFinal()) { return; } final JvmIdentifiableElement container = getLogicalContainerProvider().getNearestLogicalContainer(expression); if (container != null && container instanceof JvmOperation) { final JvmOperation operation = (JvmOperation) container; if (operation.isStatic() && field.getDeclaringType() == operation.getDeclaringType() && Utils.STATIC_CONSTRUCTOR_NAME.equals(operation.getSimpleName())) { return; } } } } super.checkAssignment(expression, feature, simpleAssignment); }
public JvmOperation findOverriddenOperation(JvmOperation operation) { if (operation.getVisibility() == JvmVisibility.PRIVATE) { return null; } ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, operation.eResource().getResourceSet()); LightweightTypeReference declaringType = owner.toLightweightTypeReference(operation.getDeclaringType()); TypeParameterSubstitutor<?> substitutor = createSubstitutor(owner, declaringType); return findOverriddenOperation(operation, declaringType, substitutor, owner, new ContextualVisibilityHelper(visibilityHelper, declaringType)); }
protected void appendOperationVisibility(final ITreeAppendable b, JvmOperation operation) { b.newLine(); JvmDeclaredType declaringType = operation.getDeclaringType(); GeneratorConfig config = b.getGeneratorConfig(); if (config != null && config.getJavaSourceVersion().isAtLeast(JAVA6) || declaringType instanceof JvmGenericType && !((JvmGenericType) declaringType).isInterface()) { b.append("@").append(Override.class).newLine(); } switch(operation.getVisibility()) { case DEFAULT: break; case PUBLIC: b.append("public "); return; case PROTECTED: b.append("protected "); return; case PRIVATE: b.append("private "); return; } }