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

The following examples show how to use com.sun.tools.javac.code.Type#ClassType . 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: StructuralTypeEraser.java    From manifold with Apache License 2.0 6 votes vote down vote up
@Override
public Type visitClassType( Type.ClassType t, Void s )
{
  boolean erased = false;
  Type erasure = _types.erasure( t );
  Type base = visitType( erasure, s );
  if( base != erasure )
  {
    erased = true;
  }
  ArrayList<Type> params = new ArrayList<>();
  for( Type arg : t.allparams() )
  {
    Type param = visit( arg );
    params.add( param );
    if( param != arg )
    {
      erased = true;
    }
  }
  if( erased )
  {
    return new Type.ClassType( t.getEnclosingType(), List.from( params ), base.tsym );
  }
  return t;
}
 
Example 2
Source File: JavacBinder.java    From manifold with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitClassType( Type.ClassType t, Type pt )
{
  if( _types.isSameType( t, pt ) )
  {
    return null;
  }

  List<Type> pt_params = pt.getTypeArguments();

  List<Type> t_params = t.getTypeArguments();
  for( int i = 0; i < t_params.size() && i < pt_params.size(); i++ )
  {
    fetchTypeVars( t_params.get( i ), pt_params.get( i ), _map );
  }

  return null;
}
 
Example 3
Source File: BaseProcessor.java    From WMRouter with Apache License 2.0 5 votes vote down vote up
/**
 * 创建Interceptors。格式:<code>, new Interceptor1(), new Interceptor2()</code>
 */
public CodeBlock buildInterceptors(List<? extends TypeMirror> interceptors) {
    CodeBlock.Builder b = CodeBlock.builder();
    if (interceptors != null && interceptors.size() > 0) {
        for (TypeMirror type : interceptors) {
            if (type instanceof Type.ClassType) {
                Symbol.TypeSymbol e = ((Type.ClassType) type).asElement();
                if (e instanceof Symbol.ClassSymbol && isInterceptor(e)) {
                    b.add(", new $T()", e);
                }
            }
        }
    }
    return b.build();
}
 
Example 4
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void eraseGenericStructuralVarargs( JCTree.JCMethodInvocation tree )
{
  if( tree.varargsElement instanceof Type.ClassType && TypeUtil.isStructuralInterface( _tp, tree.varargsElement.tsym ) )
  {
    tree.varargsElement = _tp.getSymtab().objectType;
  }
}
 
Example 5
Source File: ManAttr_8.java    From manifold with Apache License 2.0 5 votes vote down vote up
private boolean _shouldCheckSuperType( Type type, boolean checkSuper )
{
  return
    type instanceof Type.ClassType &&
    type != Type.noType &&
    !(type instanceof Type.ErrorType) &&
    !type.toString().equals( Object.class.getTypeName() ) &&
    (!checkSuper || _shouldCheckSuperType( ((Symbol.ClassSymbol)type.tsym).getSuperclass(), false ));
}
 
Example 6
Source File: JNIWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Type visitClassType(Type.ClassType t, StringBuilder s) {
    setDeclaredType(t, s);
    return null;
}
 
Example 7
Source File: JNIWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public R visitClassType(Type.ClassType t, P p) {
    return defaultAction(t, p);
}
 
Example 8
Source File: JNIWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type visitClassType(Type.ClassType t, StringBuilder s) {
    setDeclaredType(t, s);
    return null;
}
 
Example 9
Source File: JNIWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public R visitClassType(Type.ClassType t, P p) {
    return defaultAction(t, p);
}
 
Example 10
Source File: PackageGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
Type getTypeByName(String typeName, List<Type> tparams) {
    return new Type.ClassType(
               Type.noType,
               tparams,
               new Symbol.ClassSymbol(0, names.fromString(typeName), null));
}
 
Example 11
Source File: RxJavaMissingAutodisposeErrorChecker.java    From RIBs with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matches(MethodInvocationTree tree, VisitorState state) {

  boolean matchFound = false;
  try {
    final MemberSelectTree memberTree = (MemberSelectTree) tree.getMethodSelect();
    if (!memberTree.getIdentifier().contentEquals(SUBSCRIBE)) {
      return false;
    }

    for (MethodMatchers.MethodNameMatcher nameMatcher : SUBSCRIBE_MATCHERS) {
      if (!nameMatcher.matches(tree, state)) {
        continue;
      } else {
        matchFound = true;
        break;
      }
    }
    if (!matchFound) {
      return false;
    }

    ClassTree enclosingClass =
        ASTHelpers.findEnclosingNode(state.getPath(), ClassTree.class);
    Type.ClassType enclosingClassType = ASTHelpers.getType(enclosingClass);
    Type routerType = state.getTypeFromString("com.uber.rib.core.Router");
    Type presenterType = state.getTypeFromString("com.uber.rib.core.Presenter");
    Type interactorType = state.getTypeFromString("com.uber.rib.core.Interactor");
    Type workerType = state.getTypeFromString("com.uber.rib.core.Worker");

    if (!ASTHelpers.isSubtype(enclosingClassType, routerType, state)
        && !ASTHelpers.isSubtype(enclosingClassType, presenterType, state)
        && !ASTHelpers.isSubtype(enclosingClassType, interactorType, state)
        && !ASTHelpers.isSubtype(enclosingClassType, workerType, state)) {
      return false;
    }

    return !TO_CALL_MATCHER.matches(memberTree.getExpression(), state);
  } catch (ClassCastException e) {
    return false;
  }
}
 
Example 12
Source File: SrcClassUtil.java    From manifold with Apache License 2.0 4 votes vote down vote up
private String typeNoAnnotations( Type type )
{
  if( isJava8() )
  {
    return type.toString();
  }

  StringBuilder sb = new StringBuilder();
  if( type instanceof Type.ClassType )
  {
    if( type.getEnclosingType().hasTag( CLASS ) &&
        ReflectUtil.field( type.tsym.owner, "kind" ).get() == ReflectUtil.field( "com.sun.tools.javac.code.Kinds$Kind", "TYP" ).getStatic() )
    {
      sb.append( typeNoAnnotations( type.getEnclosingType() ) );
      sb.append( "." );
      sb.append( ReflectUtil.method( type, "className", Symbol.class, boolean.class ).invoke( type.tsym, false ) );
    }
    else
    {
      sb.append( ReflectUtil.method( type, "className", Symbol.class, boolean.class ).invoke( type.tsym, true ) );
    }

    List<Type> typeArgs = type.getTypeArguments();
    if( typeArgs.nonEmpty() )
    {
      sb.append( '<' );
      for( int i = 0; i < typeArgs.size(); i++ )
      {
        if( i > 0 )
        {
          sb.append( ", " );
        }
        Type typeArg = typeArgs.get( i );
        sb.append( typeNoAnnotations( typeArg ) );
      }
      sb.append( ">" );
    }
  }
  else if( type instanceof Type.ArrayType )
  {
    sb.append( typeNoAnnotations( ((Type.ArrayType)type).getComponentType() ) ).append( "[]" );
  }
  else if( type instanceof Type.WildcardType )
  {
    Type.WildcardType wildcardType = (Type.WildcardType)type;
    BoundKind kind = wildcardType.kind;
    sb.append( kind.toString() );
    if( kind != BoundKind.UNBOUND )
    {
      sb.append( typeNoAnnotations( wildcardType.type ) );
    }
  }
  else
  {
    sb.append( type.toString() );
  }
  return sb.toString();
}
 
Example 13
Source File: ManAttr_8.java    From manifold with Apache License 2.0 4 votes vote down vote up
/**
 * Handles @Jailbreak
 */
@Override
public void visitApply( JCTree.JCMethodInvocation tree )
{
  if( !(tree.meth instanceof JCTree.JCFieldAccess) )
  {
    super.visitApply( tree );
    patchMethodType( tree );
    return;
  }

  if( JAILBREAK_PRIVATE_FROM_SUPERS )
  {
    _manLog.pushSuspendIssues( tree ); // since method-calls can be nested, we need a tree of stacks TreeNode(JCTree.JCFieldAccess, Stack<JCDiagnostic>>)
  }

  JCTree.JCFieldAccess fieldAccess = (JCTree.JCFieldAccess)tree.meth;
  try
  {
    super.visitApply( tree );
    patchMethodType( tree );

    if( JAILBREAK_PRIVATE_FROM_SUPERS )
    {
      if( fieldAccess.type instanceof Type.ErrorType )
      {
        if( shouldCheckSuperType( fieldAccess.selected.type ) && _manLog.isJailbreakSelect( fieldAccess ) )
        {
          // set qualifier type to supertype to handle private methods
          Type.ClassType oldType = (Type.ClassType)fieldAccess.selected.type;
          fieldAccess.selected.type = ((Symbol.ClassSymbol)oldType.tsym).getSuperclass();
          ((JCTree.JCIdent)fieldAccess.selected).sym.type = fieldAccess.selected.type;
          fieldAccess.type = null;
          fieldAccess.sym = null;
          tree.type = null;

          // retry with supertype
          visitApply( tree );

          // restore original type
          fieldAccess.selected.type = oldType;
          ((JCTree.JCIdent)fieldAccess.selected).sym.type = fieldAccess.selected.type;
        }
      }
      else
      {
        // apply any issues logged for the found method (only the top of the suspend stack)
        _manLog.recordRecentSuspendedIssuesAndRemoveOthers( tree );
      }
    }
  }
  finally
  {
    if( JAILBREAK_PRIVATE_FROM_SUPERS )
    {
      _manLog.popSuspendIssues( tree );
    }
  }
}