Java Code Examples for com.sun.tools.javac.code.Type#IntersectionClassType

The following examples show how to use com.sun.tools.javac.code.Type#IntersectionClassType . 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: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitTypeCast(JCTypeCast tree) {
    tree.clazz = translate(tree.clazz, null);
    Type originalTarget = tree.type;
    tree.type = erasure(tree.type);
    JCExpression newExpression = translate(tree.expr, tree.type);
    if (newExpression != tree.expr) {
        JCTypeCast typeCast = newExpression.hasTag(Tag.TYPECAST)
            ? (JCTypeCast) newExpression
            : null;
        tree.expr = typeCast != null && types.isSameType(typeCast.type, originalTarget, true)
            ? typeCast.expr
            : newExpression;
    }
    if (originalTarget.isIntersection()) {
        Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget;
        for (Type c : ict.getExplicitComponents()) {
            Type ec = erasure(c);
            if (!types.isSameType(ec, tree.type)) {
                tree.expr = coerce(tree.expr, ec);
            }
        }
    }
    result = tree;
}
 
Example 2
Source File: ManTypes.java    From manifold with Apache License 2.0 5 votes vote down vote up
private boolean hasSelfType( Type type )
{
  for( Attribute.TypeCompound anno: type.getAnnotationMirrors() )
  {
    if( anno.type.toString().equals( SELF_TYPE_NAME ) )
    {
      return true;
    }
  }

  if( type instanceof Type.ArrayType )
  {
    return hasSelfType( ((Type.ArrayType)type).getComponentType() );
  }

  for( Type typeParam: type.getTypeArguments() )
  {
    if( hasSelfType( typeParam ) )
    {
      return true;
    }
  }

  if( type instanceof Type.IntersectionClassType )
  {
    for( Type compType: ((Type.IntersectionClassType)type).getComponents() )
    {
      if( hasSelfType( compType ) )
      {
        return true;
      }
    }
  }

  return false;
}