Пример #1
0
 /** @return the ClassNode of the super class of this type */
 public ClassNode getSuperClass() {
   if (!lazyInitDone && !isResolved()) {
     throw new GroovyBugError(
         "ClassNode#getSuperClass for " + getName() + " called before class resolving");
   }
   ClassNode sn = redirect().getUnresolvedSuperClass();
   if (sn != null) sn = sn.redirect();
   return sn;
 }
Пример #2
0
 /**
  * Sets this instance as proxy for the given ClassNode.
  *
  * @param cn the class to redirect to. If set to null the redirect will be removed
  */
 public void setRedirect(ClassNode cn) {
   if (isPrimaryNode)
     throw new GroovyBugError(
         "tried to set a redirect for a primary ClassNode ("
             + getName()
             + "->"
             + cn.getName()
             + ").");
   if (cn != null) cn = cn.redirect();
   if (cn == this) return;
   redirect = cn;
 }
  private static boolean isDirectAccessAllowed(
      FieldNode a, ClassNode receiver, boolean isSamePackage) {
    ClassNode declaringClass = a.getDeclaringClass().redirect();
    ClassNode receiverType = receiver.redirect();

    // first, direct access from within the class or inner class nodes
    if (declaringClass.equals(receiverType)) return true;
    if (receiverType instanceof InnerClassNode) {
      while (receiverType != null && receiverType instanceof InnerClassNode) {
        if (declaringClass.equals(receiverType)) return true;
        receiverType = receiverType.getOuterClass();
      }
    }

    // no getter
    return a.isPublic() || (a.isProtected() && isSamePackage);
  }
 @SuppressWarnings("unchecked")
 private boolean makeGetPrivateFieldWithBridgeMethod(
     final Expression receiver,
     final ClassNode receiverType,
     final String fieldName,
     final boolean safe,
     final boolean implicitThis) {
   FieldNode field = receiverType.getField(fieldName);
   ClassNode classNode = controller.getClassNode();
   if (field != null
       && Modifier.isPrivate(field.getModifiers())
       && (StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(receiverType, classNode)
           || StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(classNode, receiverType))
       && !receiverType.equals(classNode)) {
     Map<String, MethodNode> accessors =
         (Map<String, MethodNode>)
             receiverType
                 .redirect()
                 .getNodeMetaData(StaticCompilationMetadataKeys.PRIVATE_FIELDS_ACCESSORS);
     if (accessors != null) {
       MethodNode methodNode = accessors.get(fieldName);
       if (methodNode != null) {
         MethodCallExpression mce =
             new MethodCallExpression(
                 receiver,
                 methodNode.getName(),
                 new ArgumentListExpression(
                     field.isStatic() ? new ConstantExpression(null) : receiver));
         mce.setMethodTarget(methodNode);
         mce.setSafe(safe);
         mce.setImplicitThis(implicitThis);
         mce.visit(controller.getAcg());
         return true;
       }
     }
   }
   return false;
 }
Пример #5
0
 /*
  * Constructor used by makeArray() if no real class is available
  */
 private ClassNode(ClassNode componentType) {
   this(componentType.getName() + "[]", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
   this.componentType = componentType.redirect();
   isPrimaryNode = false;
 }
Пример #6
0
 /** Returns the ClassNode this ClassNode is redirecting to. */
 public ClassNode redirect() {
   if (redirect == null) return this;
   return redirect.redirect();
 }