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

The following examples show how to use com.sun.tools.javac.code.Type#ErrorType . 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: 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 2
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 visitErrorType(Type.ErrorType t, P p) {
    return defaultAction(t, p);
}
 
Example 3
Source File: JNIWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public R visitErrorType(Type.ErrorType t, P p) {
    return defaultAction(t, p);
}
 
Example 4
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 4 votes vote down vote up
private JCTree.JCMethodInvocation replaceWithReflection( JCTree.JCMethodInvocation tree )
{
  //## todo: maybe try to avoid reflection if the method is accessible -- at least check if the method and its enclosing nest of classes are all public

  Type type = tree.getMethodSelect().type;
  if( type instanceof Type.ErrorType )
  {
    // No such field/method or wrong params
    return tree;
  }

  TreeMaker make = _tp.getTreeMaker();
  JavacElements javacElems = _tp.getElementUtil();

  JCExpression methodSelect = tree.getMethodSelect();
  if( methodSelect instanceof JCTree.JCFieldAccess )
  {
    JCTree.JCFieldAccess m = (JCTree.JCFieldAccess)methodSelect;
    boolean isStatic = m.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC );
    if( !(m.sym instanceof Symbol.MethodSymbol) )
    {
      return tree;
    }
    Type returnType = ((Symbol.MethodSymbol)m.sym).getReturnType();
    Symbol.MethodSymbol reflectMethodSym = findReflectUtilMethod( tree, returnType, isStatic );

    List<Symbol.VarSymbol> parameters = ((Symbol.MethodSymbol)m.sym).getParameters();
    ArrayList<JCExpression> paramTypes = new ArrayList<>();
    for( Symbol.VarSymbol param: parameters )
    {
      JCExpression classExpr = makeClassExpr( tree, param.type );
      paramTypes.add( classExpr );
    }
    Symtab symTab = _tp.getSymtab();
    JCTree.JCNewArray paramTypesArray = make.NewArray(
      make.Type( symTab.classType ), List.nil(), List.from( paramTypes ) );
    paramTypesArray.type = new Type.ArrayType( symTab.classType, symTab.arrayClass );

    JCTree.JCNewArray argsArray = make.NewArray(
      make.Type( symTab.objectType ), List.nil(), tree.getArguments() );
    argsArray.type = new Type.ArrayType( symTab.objectType, symTab.arrayClass );

    ArrayList<JCExpression> newArgs = new ArrayList<>();
    newArgs.add( isStatic ? makeClassExpr( tree, m.selected.type ) : m.selected ); // receiver or class
    newArgs.add( make.Literal( m.sym.flatName().toString() ) ); // method name
    newArgs.add( paramTypesArray ); // param types
    newArgs.add( argsArray ); // args

    Symbol.ClassSymbol reflectMethodClassSym =
      IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectionRuntimeMethods.class.getName() );

    JCTree.JCMethodInvocation reflectCall =
      make.Apply( List.nil(),
        memberAccess( make, javacElems, ReflectionRuntimeMethods.class.getName() + "." + reflectMethodSym.flatName().toString() ),
        List.from( newArgs ) );
    reflectCall.setPos( tree.pos );
    reflectCall.type = returnType;
    reflectCall.pos = tree.pos;
    JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)reflectCall.getMethodSelect();
    newMethodSelect.sym = reflectMethodSym;
    newMethodSelect.type = reflectMethodSym.type;
    assignTypes( newMethodSelect.selected, reflectMethodClassSym );
    newMethodSelect.pos = tree.pos;
    return reflectCall;
  }
  return tree;
}
 
Example 5
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 4 votes vote down vote up
private JCTree replaceWithReflection( JCTree.JCFieldAccess tree )
{
  TreeMaker make = _tp.getTreeMaker();
  JavacElements javacElems = _tp.getElementUtil();

  boolean isStatic = tree.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC );
  if( tree.sym instanceof Symbol.MethodSymbol )
  {
    return tree;
  }

  Tree parent = _tp.getParent( tree );
  if( parent instanceof JCTree.JCAssign && ((JCTree.JCAssign)parent).lhs == tree ||
      parent instanceof JCTree.JCAssignOp && ((JCTree.JCAssignOp)parent).lhs == tree )
  {
    // handled in visitAssign() or visitAssignOp()
    return tree;
  }

  if( parent instanceof JCTree.JCUnary && ((JCTree.JCUnary)parent).arg == tree )
  {
    Tree.Kind kind = parent.getKind();

    if( kind != Tree.Kind.UNARY_MINUS && kind != Tree.Kind.UNARY_PLUS &&
        kind != Tree.Kind.LOGICAL_COMPLEMENT && kind != Tree.Kind.BITWISE_COMPLEMENT )
    {
      // supporting -, +, !, ~  not supporting --, ++
      _tp.report( (JCTree)parent, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_INCREMENT_OP_NOT_ALLOWED_REFLECTION.get() );
      return tree;
    }
  }

  Type type = tree.sym.type;
  if( type instanceof Type.ErrorType )
  {
    // No such field/method
    return tree;
  }

  Symbol.MethodSymbol reflectMethodSym = findFieldAccessReflectUtilMethod( tree, type, isStatic, false );

  ArrayList<JCExpression> newArgs = new ArrayList<>();
  newArgs.add( isStatic ? makeClassExpr( tree, tree.selected.type ) : tree.selected ); // receiver or class
  newArgs.add( make.Literal( tree.sym.flatName().toString() ) ); // field name

  Symbol.ClassSymbol reflectMethodClassSym =
    IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectionRuntimeMethods.class.getName() );

  JCTree.JCMethodInvocation reflectCall =
    make.Apply( List.nil(),
      memberAccess( make, javacElems, ReflectionRuntimeMethods.class.getName() + "." + reflectMethodSym.flatName().toString() ),
      List.from( newArgs ) );
  reflectCall.setPos( tree.pos );
  reflectCall.type = type;
  JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)reflectCall.getMethodSelect();
  newMethodSelect.sym = reflectMethodSym;
  newMethodSelect.type = reflectMethodSym.type;
  assignTypes( newMethodSelect.selected, reflectMethodClassSym );

  return reflectCall;
}
 
Example 6
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 );
    }
  }
}
 
Example 7
Source File: TreeAnalyzer.java    From meghanada-server with GNU General Public License v3.0 4 votes vote down vote up
private static void analyzeNewClass(
    SourceContext context, JCTree.JCNewClass newClass, int preferredPos, int endPos)
    throws IOException {
  Source src = context.source;
  EndPosTable endPosTable = context.endPosTable;
  boolean isParameter = context.parameter;
  boolean isArgument = context.argument;
  int argumentIndex = context.argumentIndex;

  List<JCTree.JCExpression> argumentExpressions = newClass.getArguments();
  java.util.List<String> arguments = getArgumentsType(context, argumentExpressions);

  context.parameter = isParameter;
  context.argument = isArgument;
  context.setArgumentIndex(argumentIndex);

  JCTree.JCExpression identifier = newClass.getIdentifier();
  String name = identifier.toString();

  int start = identifier.getStartPosition();
  int end = identifier.getEndPosition(endPosTable);
  Range nameRange = Range.create(src, start, end);

  Range range = Range.create(src, preferredPos + 4, endPos);
  MethodCall methodCall = new MethodCall(name, preferredPos, nameRange, range, true);

  Type type = identifier.type;
  getTypeString(src, type)
      .ifPresent(
          fqcn -> {
            methodCall.declaringClass = TreeAnalyzer.markFQCN(src, fqcn);
            methodCall.returnType = fqcn;
            methodCall.argumentIndex = argumentIndex;
            context.setArgumentFQCN(fqcn);
          });

  if (isNull(type) || type instanceof Type.ErrorType) {
    // add className to unknown
    ClassName className = new ClassName(name);
    String simpleName = className.getName();
    if (!src.getImportedClassMap().containsKey(simpleName)
        && !CachedASMReflector.getInstance().getGlobalClassIndex().containsKey(simpleName)) {
      src.addUnknown(simpleName);
    }
  }

  JCTree.JCClassDecl classBody = newClass.getClassBody();
  analyzeParsedTree(context, classBody);

  src.getCurrentScope()
      .ifPresent(
          scope -> {
            if (nonNull(arguments)) {
              methodCall.setArguments(arguments);
            }
            scope.addMethodCall(methodCall);
            addUsageIndex(src, methodCall);
          });
}