Java Code Examples for com.sun.tools.javac.tree.JCTree#JCAnnotatedType

The following examples show how to use com.sun.tools.javac.tree.JCTree#JCAnnotatedType . 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: ExtensionTransformer.java    From manifold with Apache License 2.0 6 votes vote down vote up
public void visitVarDef( JCTree.JCVariableDecl tree )
{
  super.visitVarDef( tree );

  if( _tp.isGenerate() && !shouldProcessForGeneration() )
  {
    // Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
    return;
  }

  JCExpression vartype = tree.vartype;
  if( vartype instanceof JCTree.JCAnnotatedType )
  {
    if( ((JCTree.JCAnnotatedType)tree.vartype).getAnnotations().stream()
      .anyMatch( anno -> Jailbreak.class.getTypeName().equals( anno.attribute.type.toString() ) ) )
    {
      // if the type itself is inaccessible and annotated with @Jailbreak, it will be erased to Object
      tree.type = ((JCTree.JCAnnotatedType)tree.vartype).underlyingType.type;
      tree.sym.type = _tp.getSymtab().objectType;
    }
  }
}
 
Example 2
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private static boolean isJailbreakReceiver( JCTree.JCNewClass newExpr )
{
  JCExpression classExpr = newExpr.clazz;
  if( classExpr instanceof JCTree.JCAnnotatedType )
  {
    return ((JCTree.JCAnnotatedType)classExpr).annotations.stream()
      .anyMatch( e -> Jailbreak.class.getTypeName().equals( e.attribute.type.toString() ) );
  }
  return false;
}
 
Example 3
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void verifySelfOnThis( JCTree annotated, JCTree.JCAnnotation selfAnno )
{
  String fqn;
  if( annotated instanceof JCTree.JCAnnotatedType )
  {
    fqn = ((JCTree.JCAnnotatedType)annotated).getUnderlyingType().type.tsym.getQualifiedName().toString();
  }
  else if( annotated instanceof JCTree.JCMethodDecl )
  {
    fqn = ((JCTree.JCMethodDecl)annotated).getReturnType().type.tsym.getQualifiedName().toString();
  }
  else
  {
    //## todo: shouldn't happen
    return;
  }

  try
  {
    JCTree.JCClassDecl enclosingClass = _tp.getClassDecl( annotated );
    if( !isDeclaringClassOrExtension( annotated, fqn, enclosingClass ) && !fqn.equals( "Array" ) )
    {
      _tp.report( selfAnno, Diagnostic.Kind.ERROR,
        ExtIssueMsg.MSG_SELF_NOT_ON_CORRECT_TYPE.get( fqn, enclosingClass.sym.getQualifiedName() ) );
    }
  }
  catch( Throwable ignore )
  {
  }
}
 
Example 4
Source File: ManResolve.java    From manifold with Apache License 2.0 5 votes vote down vote up
private boolean isJailbreakOnType()
{
  JCTree.JCAnnotatedType annotatedType = ((ManAttr)_attr).peekAnnotatedType();
  if( annotatedType != null )
  {
    return annotatedType.toString().contains( "@Jailbreak" );
  }
  return false;
}
 
Example 5
Source File: ManAttr_8.java    From manifold with Apache License 2.0 5 votes vote down vote up
/**
 * Facilitates @Jailbreak. ManResolve#isAccessible() needs to know the JCAnnotatedType in context.
 */
@Override
public void visitAnnotatedType( JCTree.JCAnnotatedType tree )
{
  _annotatedTypes.push( tree );
  try
  {
    super.visitAnnotatedType( tree );
  }
  finally
  {
    _annotatedTypes.pop();
  }
}
 
Example 6
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 4 votes vote down vote up
private JCTree replaceWithReflection( JCTree.JCNewClass tree )
{
  if( tree.constructor == null )
  {
    return tree;
  }

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

  Type type = ((JCTree.JCAnnotatedType)tree.clazz).underlyingType.type;

  if( tree.constructor instanceof Symbol.ClassSymbol )
  {
    //assert tree.constructor.kind == com.sun.tools.javac.code.Kinds.ERR;
    return tree;
  }

  List<Symbol.VarSymbol> parameters = ((Symbol.MethodSymbol)tree.constructor).getParameters();
  ArrayList<JCExpression> paramTypes = new ArrayList<>();
  for( Symbol.VarSymbol param: parameters )
  {
    paramTypes.add( makeClassExpr( tree, param.type ) );
  }
  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( makeClassExpr( tree, type ) ); // the class
  newArgs.add( paramTypesArray ); // param types
  newArgs.add( argsArray ); // args


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

  Symbol.MethodSymbol reflectMethodSym = findReflectUtilConstructor( tree );
  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 7
Source File: ManAttr_8.java    From manifold with Apache License 2.0 4 votes vote down vote up
public JCTree.JCAnnotatedType peekAnnotatedType()
{
  return _annotatedTypes.isEmpty() ? null : _annotatedTypes.peek();
}
 
Example 8
Source File: ManAttr.java    From manifold with Apache License 2.0 votes vote down vote up
JCTree.JCAnnotatedType peekAnnotatedType();