How to use the jsii-reflect.isMethod function in jsii-reflect

To help you get started, we’ve selected a few jsii-reflect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / jsii / packages / jsii-diff / lib / classes-ifaces.ts View on Github external
violator: original,
        message: `was ${origQual}, is now ${updQual}`
      });
    }
  }

  if (original.variadic && !updated.variadic) {
    // Once variadic, can never be made non-variadic anymore (because I could always have been passing N+1 arguments)
    context.mismatches.report({
      ruleKey: 'changed-variadic',
      violator: original,
      message: 'used to be variadic, not variadic anymore.'
    });
  }

  if (reflect.isMethod(original) && reflect.isMethod(updated)) {
    const retAna = isCompatibleReturnType(original.returns, updated.returns);
    if (!retAna.success) {
      context.mismatches.report({
        ruleKey: 'change-return-type',
        violator: original,
        message: `returns ${describeOptionalValueMatchingFailure(original.returns, updated.returns, retAna)}`
      });
    }
  }

  // Check that every original parameter can still be mapped to a parameter in the updated method
  original.parameters.forEach((param, i) => {
    const updatedParam = findParam(updated.parameters, i);
    if (updatedParam === undefined) {
      context.mismatches.report({
        ruleKey: 'removed-argument',
github aws / jsii / packages / jsii-diff / lib / classes-ifaces.ts View on Github external
// JSII assembler has already taken care of inheritance here
    if (original.initializer && updated.initializer) {
      compareMethod(original.initializer, updated.initializer, context);
    }
  }

  if (original.docs.subclassable && !updated.docs.subclassable) {
    context.mismatches.report({
      ruleKey: 'remove-subclassable',
      message: 'has gone from @subclassable to non-@subclassable',
      violator: original,
    });
  }

  for (const [origMethod, updatedElement] of memberPairs(original, original.allMethods, updated, context)) {
    if (reflect.isMethod(origMethod) && reflect.isMethod(updatedElement)) {
      compareMethod(origMethod, updatedElement, context);
    }
  }

  for (const [origProp, updatedElement] of memberPairs(original, original.allProperties, updated, context)) {
    if (reflect.isProperty(origProp) && reflect.isProperty(updatedElement)) {
      compareProperty(origProp, updatedElement, context);
    }
  }

  // You cannot have added abstract members to the class/interface, as they are
  // an added burden on potential implementors.
  //
  // Only for types that are explicitly marked as intended to be subclassed by customers.
  if (subclassableType(original)) {
    noNewAbstractMembers(original, updated, context);
github aws / jsii / packages / jsii-diff / lib / classes-ifaces.ts View on Github external
function compareMethod(
  original: T,
  updated: T,
  context: ComparisonContext) {
  compareStabilities(original, updated, context);

  // Type guards on original are duplicated on updated to help tsc... They are required to be the same type by the declaration.
  if (reflect.isMethod(original) && reflect.isMethod(updated)) {
    if (original.static !== updated.static) {
      const origQual = original.static ? 'static' : 'not static';
      const updQual = updated.static ? 'static' : 'not static';
      context.mismatches.report({
        ruleKey: 'changed-static',
        violator: original,
        message: `was ${origQual}, is now ${updQual}.`
      });
    }

    if (original.async !== updated.async) {
      const origQual = original.async ? 'asynchronous' : 'synchronous';
      const updQual = updated.async ? 'asynchronous' : 'synchronous';
      context.mismatches.report({
        ruleKey: 'changed-async',
        violator: original,