Java Code Examples for com.sun.tools.javac.code.Types#isSameType()

The following examples show how to use com.sun.tools.javac.code.Types#isSameType() . 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: ClassWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static boolean isSameType(Type t1, Type t2, Types types) {
    if (t1 == null) { return t2 == null; }
    if (t2 == null) { return false; }

    if (isInt(t1) && isInt(t2)) { return true; }

    if (t1.hasTag(UNINITIALIZED_THIS)) {
        return t2.hasTag(UNINITIALIZED_THIS);
    } else if (t1.hasTag(UNINITIALIZED_OBJECT)) {
        if (t2.hasTag(UNINITIALIZED_OBJECT)) {
            return ((UninitializedType)t1).offset == ((UninitializedType)t2).offset;
        } else {
            return false;
        }
    } else if (t2.hasTag(UNINITIALIZED_THIS) || t2.hasTag(UNINITIALIZED_OBJECT)) {
        return false;
    }

    return types.isSameType(t1, t2);
}
 
Example 2
Source File: NullAway.java    From NullAway with MIT License 6 votes vote down vote up
/**
 * find the closest ancestor method in a superclass or superinterface that method overrides
 *
 * @param method the subclass method
 * @param types the types data structure from javac
 * @return closest overridden ancestor method, or <code>null</code> if method does not override
 *     anything
 */
@Nullable
private Symbol.MethodSymbol getClosestOverriddenMethod(Symbol.MethodSymbol method, Types types) {
  // taken from Error Prone MethodOverrides check
  Symbol.ClassSymbol owner = method.enclClass();
  for (Type s : types.closure(owner.type)) {
    if (types.isSameType(s, owner.type)) {
      continue;
    }
    for (Symbol m : s.tsym.members().getSymbolsByName(method.name)) {
      if (!(m instanceof Symbol.MethodSymbol)) {
        continue;
      }
      Symbol.MethodSymbol msym = (Symbol.MethodSymbol) m;
      if (msym.isStatic()) {
        continue;
      }
      if (method.overrides(msym, owner, types, /*checkReturn*/ false)) {
        return msym;
      }
    }
  }
  return null;
}
 
Example 3
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
boolean apply(Type op1, Type op2, Warner warn, Types types) {
    return types.isSameType(op1, op2);
}
 
Example 4
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 4 votes vote down vote up
private Symbol.MethodSymbol findExtMethod( JCTree.JCMethodInvocation tree )
{
  Symbol sym = null;
  if( tree.meth instanceof JCTree.JCFieldAccess )
  {
    sym = ((JCTree.JCFieldAccess)tree.meth).sym;
  }
  else if( tree.meth instanceof JCTree.JCIdent )
  {
    sym = ((JCTree.JCIdent)tree.meth).sym;
  }

  if( sym == null || !sym.hasAnnotations() )
  {
    return null;
  }

  for( Attribute.Compound annotation: sym.getAnnotationMirrors() )
  {
    if( annotation.type.toString().equals( ExtensionMethod.class.getName() ) )
    {
      String extensionClass = (String)annotation.values.get( 0 ).snd.getValue();
      boolean isStatic = (boolean)annotation.values.get( 1 ).snd.getValue();
      BasicJavacTask javacTask = (BasicJavacTask)_tp.getJavacTask(); //JavacHook.instance() != null ? (JavacTaskImpl)JavacHook.instance().getJavacTask_PlainFileMgr() : ClassSymbols.instance( _sp.getModule() ).getJavacTask_PlainFileMgr();
      Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( _sp.getModule() ).getClassSymbol( javacTask, _tp, extensionClass );
      if( classSymbol == null )
      {
        // In module mode if a package in another module is not exported, classes in the package
        // will not be accessible to other modules, hence the null classSymbol
        continue;
      }

      Symbol.ClassSymbol extClassSym = classSymbol.getFirst();
      if( extClassSym == null )
      {
        // This can happen during bootstrapping with Dark Java classes from Manifold itself
        // So we short-circuit that here (ManClassFinder_9 or any other darkj class used during bootstrapping doesn't really need to use extensions)
        return null;
      }
      Types types = Types.instance( javacTask.getContext() );
      outer:
      for( Symbol elem: IDynamicJdk.instance().getMembers( extClassSym ) )
      {
        if( elem instanceof Symbol.MethodSymbol && elem.flatName().toString().equals( sym.name.toString() ) )
        {
          Symbol.MethodSymbol extMethodSym = (Symbol.MethodSymbol)elem;
          List<Symbol.VarSymbol> extParams = extMethodSym.getParameters();
          List<Symbol.VarSymbol> calledParams = ((Symbol.MethodSymbol)sym).getParameters();
          int thisOffset = isStatic ? 0 : 1;
          if( extParams.size() - thisOffset != calledParams.size() )
          {
            continue;
          }
          for( int i = thisOffset; i < extParams.size(); i++ )
          {
            Symbol.VarSymbol extParam = extParams.get( i );
            Symbol.VarSymbol calledParam = calledParams.get( i - thisOffset );
            if( !types.isSameType( types.erasure( extParam.type ), types.erasure( calledParam.type ) ) )
            {
              continue outer;
            }
          }
          return extMethodSym;
        }
      }
    }
  }
  return null;
}