Tabnine Logo
ClassNode.isUsingGenerics
Code IndexAdd Tabnine to your IDE (free)

How to use
isUsingGenerics
method
in
org.codehaus.groovy.ast.ClassNode

Best Java code snippets using org.codehaus.groovy.ast.ClassNode.isUsingGenerics (Showing top 20 results out of 315)

origin: org.codehaus.groovy/groovy

@Override
public boolean isUsingGenerics() {
  lazyInitSupers();
  return super.isUsingGenerics();
}
origin: org.codehaus.groovy/groovy

private static boolean usesGenericsInClassSignature(ClassNode node) {
  if (!node.isUsingGenerics()) return false;
  if (hasGenerics(node)) return true;
  ClassNode sclass = node.getUnresolvedSuperClass(false);
  if (sclass.isUsingGenerics()) return true;
  ClassNode[] interfaces = node.getInterfaces();
  if (interfaces != null) {
    for (int i = 0; i < interfaces.length; i++) {
      if (interfaces[i].isUsingGenerics()) return true;
    }
  }
  return false;
}
origin: org.codehaus.groovy/groovy

private static ClassNode getComponentTypeForList(ClassNode fType) {
  if (fType.isUsingGenerics() && fType.getGenericsTypes().length == 1) {
    return fType.getGenericsTypes()[0].getType();
  } else {
    return ClassHelper.OBJECT_TYPE;
  }
}
origin: org.codehaus.groovy/groovy

private static ClassNode adjustForTargetType(final ClassNode targetType, final ClassNode resultType) {
  if (targetType.isUsingGenerics() && missesGenericsTypes(resultType)) {
    // unchecked assignment within ternary/elvis
    // examples:
    // List<A> list = existingAs ?: []
    // in that case, the inferred type of the RHS is the type of the RHS
    // "completed" with generics type information available in the LHS
    return GenericsUtils.parameterizeType(targetType, resultType.getPlainNodeReference());
  }
  return resultType;
}
origin: org.codehaus.groovy/groovy

/**
 * resolves a Field or Property node generics by using the current class and
 * the declaring class to extract the right meaning of the generics symbols
 *
 * @param an   a FieldNode or PropertyNode
 * @param type the origin type
 * @return the new ClassNode with corrected generics
 */
private ClassNode getGenericsResolvedTypeOfFieldOrProperty(AnnotatedNode an, ClassNode type) {
  if (!type.isUsingGenerics()) return type;
  Map<GenericsTypeName, GenericsType> connections = new HashMap<GenericsTypeName, GenericsType>();
  //TODO: inner classes mean a different this-type. This is ignored here!
  extractGenericsConnections(connections, typeCheckingContext.getEnclosingClassNode(), an.getDeclaringClass());
  type = applyGenericsContext(connections, type);
  return type;
}
origin: org.codehaus.groovy/groovy

/**
 * Iterates over each generics bound of this generics specification, and checks
 * that the generics defined by the bound are compatible with the generics specified
 * by the type.
 * @param classNode the classnode the bounds should be compared with
 * @return true if generics from bounds are compatible
 */
private boolean checkGenerics(final ClassNode classNode) {
  if (upperBounds!=null) {
    for (ClassNode upperBound : upperBounds) {
      if (!compareGenericsWithBound(classNode, upperBound)) return false;
    }
  }
  if (lowerBound!=null) {
    if (!lowerBound.redirect().isUsingGenerics()) {
      if (!compareGenericsWithBound(classNode, lowerBound)) return false;
    }
  }
  return true;
}
origin: org.codehaus.groovy/groovy

/**
 * Returns true if a class node makes use of generic types. If the class node represents an
 * array type, then checks if the component type is using generics.
 *
 * @param cn a class node for which to check if it is using generics
 * @return true if the type (or component type) is using generics
 */
public static boolean isUsingGenericsOrIsArrayUsingGenerics(ClassNode cn) {
  if (cn.isArray()) {
    return isUsingGenericsOrIsArrayUsingGenerics(cn.getComponentType());
  }
  return (cn.isUsingGenerics() && cn.getGenericsTypes() != null);
}
origin: org.codehaus.groovy/groovy

private static void extractSuperClassGenerics(ClassNode[] usage, ClassNode[] declaration, Map<String, ClassNode> spec) {
  if (usage == null || declaration == null || declaration.length == 0) return;
  // both have generics
  for (int i = 0; i < usage.length; i++) {
    ClassNode ui = usage[i];
    ClassNode di = declaration[i];
    if (di.isGenericsPlaceHolder()) {
      spec.put(di.getGenericsTypes()[0].getName(), di);
    } else if (di.isUsingGenerics()) {
      extractSuperClassGenerics(ui.getGenericsTypes(), di.getGenericsTypes(), spec);
    }
  }
}
origin: org.codehaus.groovy/groovy

/**
 * Returns true if the class node represents a the class node for the Class class
 * and if the parametrized type is a neither a placeholder or a wildcard. For example,
 * the class node Class&lt;Foo&gt; where Foo is a class would return true, but the class
 * node for Class&lt;?&gt; would return false.
 *
 * @param classNode a class node to be tested
 * @return true if it is the class node for Class and its generic type is a real class
 */
public static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode) {
  GenericsType[] genericsTypes = classNode.getGenericsTypes();
  return CLASS_Type.equals(classNode)
      && classNode.isUsingGenerics()
      && genericsTypes != null
      && !genericsTypes[0].isPlaceholder()
      && !genericsTypes[0].isWildcard();
}
origin: org.codehaus.groovy/groovy

public static ClassNode nonGeneric(ClassNode type) {
  if (type.isUsingGenerics()) {
    final ClassNode nonGen = ClassHelper.makeWithoutCaching(type.getName());
    nonGen.setRedirect(type);
    nonGen.setGenericsTypes(null);
    nonGen.setUsingGenerics(false);
    return nonGen;
  }
  if (type.isArray() && type.getComponentType().isUsingGenerics()) {
    return type.getComponentType().getPlainNodeReference().makeArray();
  }
  return type;
}
origin: org.codehaus.groovy/groovy

protected void inferDiamondType(final ConstructorCallExpression cce, final ClassNode lType) {
  // check if constructor call expression makes use of the diamond operator
  ClassNode node = cce.getType();
  if (node.isUsingGenerics() && node.getGenericsTypes() != null && node.getGenericsTypes().length == 0) {
    ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
    if (argumentListExpression.getExpressions().isEmpty()) {
      adjustGenerics(lType, node);
    } else {
      ClassNode type = getType(argumentListExpression.getExpression(0));
      if (type.isUsingGenerics()) {
        adjustGenerics(type, node);
      }
    }
    // store inferred type on CCE
    storeType(cce, node);
  }
}
origin: org.codehaus.groovy/groovy

public ClassNode parameterizedType(ClassNode baseType, ClassNode... genericsTypeArguments) {
  ClassNode result = baseType.getPlainNodeReference();
  if (result.isUsingGenerics()) {
    GenericsType[] gts = new GenericsType[genericsTypeArguments.length];
    int expectedLength = result.getGenericsTypes().length;
    if (expectedLength!=genericsTypeArguments.length) {
      throw new GroovyBugError("Expected number of generic type arguments for "+baseType.toString(false)+" is "+expectedLength
      + " but you gave "+genericsTypeArguments.length);
    }
    for (int i = 0; i < gts.length; i++) {
      gts[i] = new GenericsType(genericsTypeArguments[i]);
    }
    result.setGenericsTypes(gts);
  }
  return result;
}
origin: org.codehaus.groovy/groovy

private void checkGenericsUsage(ASTNode ref, ClassNode node) {
  if (node.isArray()) {
    checkGenericsUsage(ref, node.getComponentType());
  } else if (!node.isRedirectNode() && node.isUsingGenerics()) {
    addError(   
        "A transform used a generics containing ClassNode "+ node + " " +
        "for "+getRefDescriptor(ref) + 
        "directly. You are not supposed to do this. " +
        "Please create a new ClassNode referring to the old ClassNode " +
        "and use the new ClassNode instead of the old one. Otherwise " +
        "the compiler will create wrong descriptors and a potential " +
        "NullPointerException in TypeResolver in the OpenJDK. If this is " +
        "not your own doing, please report this bug to the writer of the " +
        "transform.",
        ref);
  }
}
origin: org.codehaus.groovy/groovy

private static void extractGenericsConnections(Map<GenericsTypeName, GenericsType> connections, ClassNode[] usage, ClassNode[] declaration) {
  if (usage == null || declaration == null || declaration.length == 0) return;
  // both have generics
  for (int i = 0; i < usage.length; i++) {
    ClassNode ui = usage[i];
    ClassNode di = declaration[i];
    if (di.isGenericsPlaceHolder()) {
      GenericsType gt = new GenericsType(di);
      gt.setPlaceholder(di.isGenericsPlaceHolder());
      connections.put(new GenericsTypeName(di.getGenericsTypes()[0].getName()), gt);
    } else if (di.isUsingGenerics()) {
      extractGenericsConnections(connections, ui.getGenericsTypes(), di.getGenericsTypes());
    }
  }
}
origin: org.codehaus.groovy/groovy

private void checkTypeGenerics(ClassNode leftExpressionType, ClassNode wrappedRHS, Expression rightExpression) {
  // last, check generic type information to ensure that inferred types are compatible
  if (!leftExpressionType.isUsingGenerics()) return;
  // List<Foo> l = new List() is an example for incomplete generics type info
  // we assume arity related errors are already handled here.
  if (hasRHSIncompleteGenericTypeInfo(wrappedRHS)) return;
  GenericsType gt = GenericsUtils.buildWildcardType(leftExpressionType);
  if (UNKNOWN_PARAMETER_TYPE.equals(wrappedRHS) ||
      gt.isCompatibleWith(wrappedRHS) ||
      isNullConstant(rightExpression)) return;
  addStaticTypeError("Incompatible generic argument types. Cannot assign "
      + wrappedRHS.toString(false)
      + " to: " + leftExpressionType.toString(false), rightExpression);
}
origin: org.codehaus.groovy/groovy

private Map<GenericsTypeName, GenericsType> resolvePlaceHoldersFromDeclaration(ClassNode receiver, ClassNode declaration, MethodNode method, boolean isStaticTarget) {
  Map<GenericsTypeName, GenericsType> resolvedPlaceholders;
  if (isStaticTarget && CLASS_Type.equals(receiver) &&
      receiver.isUsingGenerics() &&
      receiver.getGenericsTypes().length > 0 &&
      !OBJECT_TYPE.equals(receiver.getGenericsTypes()[0].getType())) {
    return resolvePlaceHoldersFromDeclaration(receiver.getGenericsTypes()[0].getType(), declaration, method, isStaticTarget);
  } else {
    resolvedPlaceholders = extractPlaceHolders(method, receiver, declaration);
  }
  return resolvedPlaceholders;
}
origin: org.codehaus.groovy/groovy

/**
 * @param node the node to be tested
 * @return true if the node is using generics types and one of those types is a gstring or string/gstring lub
 */
public static boolean isParameterizedWithGStringOrGStringString(ClassNode node) {
  if (node.isArray()) return isParameterizedWithGStringOrGStringString(node.getComponentType());
  if (node.isUsingGenerics()) {
    GenericsType[] genericsTypes = node.getGenericsTypes();
    if (genericsTypes != null) {
      for (GenericsType genericsType : genericsTypes) {
        if (isGStringOrGStringStringLUB(genericsType.getType())) return true;
      }
    }
  }
  return node.getSuperClass() != null && isParameterizedWithGStringOrGStringString(node.getUnresolvedSuperClass());
}
origin: org.codehaus.groovy/groovy

/**
 * @param node the node to be tested
 * @return true if the node is using generics types and one of those types is a string
 */
public static boolean isParameterizedWithString(ClassNode node) {
  if (node.isArray()) return isParameterizedWithString(node.getComponentType());
  if (node.isUsingGenerics()) {
    GenericsType[] genericsTypes = node.getGenericsTypes();
    if (genericsTypes != null) {
      for (GenericsType genericsType : genericsTypes) {
        if (STRING_TYPE.equals(genericsType.getType())) return true;
      }
    }
  }
  return node.getSuperClass() != null && isParameterizedWithString(node.getUnresolvedSuperClass());
}
origin: org.codehaus.groovy/groovy

protected ClassNode makeType(AST typeNode) {
  ClassNode answer = ClassHelper.DYNAMIC_TYPE;
  AST node = typeNode.getFirstChild();
  if (node != null) {
    if (isType(INDEX_OP, node) || isType(ARRAY_DECLARATOR, node)) {
      answer = makeType(node).makeArray();
    } else {
      checkTypeArgs(node, false);
      answer = ClassHelper.make(qualifiedName(node));
      if (answer.isUsingGenerics()) {
        ClassNode newAnswer = ClassHelper.makeWithoutCaching(answer.getName());
        newAnswer.setRedirect(answer);
        answer = newAnswer;
      }
    }
    configureAST(answer, node);
  }
  return answer;
}
origin: groovy/groovy-core

protected void visitGenerics(ClassNode node) {
  if (node.isUsingGenerics()) {
    GenericsType[] generics = node.getGenericsTypes();
    if(generics == null) return;
    for (GenericsType genericType : generics) {
      visitNode(genericType);
      visitType(genericType.getType());
      if (genericType.getLowerBound() != null) {
        visitType(genericType.getLowerBound());
      }
      visitTypes(genericType.getUpperBounds());
    }
  }
}
 
org.codehaus.groovy.astClassNodeisUsingGenerics

Popular methods of ClassNode

  • getName
  • getMethods
    This methods creates a list of all methods with this name of the current class and of all super clas
  • <init>
    Constructor used by makeArray() if no real class is available
  • getSuperClass
  • equals
  • addMethod
  • getAnnotations
  • addField
  • getFields
    Returns a list containing FieldNode objects for each field in the class represented by this ClassNod
  • getPlainNodeReference
  • getField
    Finds a field matching the given name in this class or a parent class.
  • getMethod
    Finds a method matching the given name and parameters in this class or any parent class.
  • getField,
  • getMethod,
  • isInterface,
  • getNameWithoutPackage,
  • isScript,
  • getDeclaredMethod,
  • getGenericsTypes,
  • getDeclaredConstructors,
  • getModifiers,
  • getTypeClass

Popular in Java

  • Running tasks concurrently on multiple threads
  • scheduleAtFixedRate (Timer)
  • compareTo (BigDecimal)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now