Java Code Examples for com.sun.tools.javac.code.Symbol#TypeSymbol

The following examples show how to use com.sun.tools.javac.code.Symbol#TypeSymbol . 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: 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 2
Source File: Annotate.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public AnnotationContext(Env<AttrContext> env,
                         Map<Symbol.TypeSymbol, ListBuffer<T>> annotated,
                         Map<T, JCDiagnostic.DiagnosticPosition> pos,
                         boolean isTypeCompound) {
    Assert.checkNonNull(env);
    Assert.checkNonNull(annotated);
    Assert.checkNonNull(pos);

    this.env = env;
    this.annotated = annotated;
    this.pos = pos;
    this.isTypeCompound = isTypeCompound;
}
 
Example 3
Source File: ElementUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a binary name of a type.
 * @param element for which the binary name should be returned
 * @return the binary name, see Java Language Specification 13.1
 * @throws IllegalArgumentException when the element is not a javac element
 */
public static String getBinaryName (TypeElement element) throws IllegalArgumentException {
    if (element instanceof Symbol.TypeSymbol) {
        return ((Symbol.TypeSymbol)element).flatName().toString();
    }
    else {
        throw new IllegalArgumentException ();
    } 
}
 
Example 4
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void verifyExtensionInterfaces( JCTree.JCClassDecl tree )
{
  if( !hasAnnotation( tree.getModifiers().getAnnotations(), Extension.class ) )
  {
    return;
  }

  outer:
  for( JCExpression iface: tree.getImplementsClause() )
  {
    final Symbol.TypeSymbol ifaceSym = iface.type.tsym;
    if( ifaceSym == _tp.getSymtab().objectType.tsym )
    {
      continue;
    }

    for( Attribute.Compound anno: ifaceSym.getAnnotationMirrors() )
    {
      if( anno.type.toString().equals( Structural.class.getName() ) )
      {
        continue outer;
      }
    }
    // extension interfaces must be structural
    _tp.report( iface, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_ONLY_STRUCTURAL_INTERFACE_ALLOWED_HERE.get( iface.toString() ) );
  }
}
 
Example 5
Source File: ManResolve.java    From manifold with Apache License 2.0 5 votes vote down vote up
/**
 * Allow augmented classes to access modules as if defined in both the extended class' module and
 * the extension class' module.
 */
@Override
public boolean isAccessible( Env<AttrContext> env, Symbol.TypeSymbol typeSymbol, boolean checkInner )
{
  boolean accessible = super.isAccessible( env, typeSymbol, checkInner );
  if( accessible )
  {
    return true;
  }

  if( isJailbreakOnType() )
  {
    // handle the case where the class itself is inaccessible:
    //
    // // the *type* must be @Jailbreak as well as the constructor
    // com.foo.@Jailbreak PrivateClass privateThing = new com.foo.@Jailbreak PrivateClass();
    // privateThing.privateMethod();
    // ...
    return true;
  }

  if( JavacPlugin.IS_JAVA_8 )
  {
    return false;
  }


  // Java 9 +

  JavaFileObject sourceFile = env.toplevel.getSourceFile();
  if( sourceFile instanceof GeneratedJavaStubFileObject )
  {
    // Allow augmented classes to access modules as if defined in both the extended class' module and
    // the extension class' module.
    accessible = true;
  }

  return accessible;
}
 
Example 6
Source File: ManTypes.java    From manifold with Apache License 2.0 5 votes vote down vote up
/**
 * Override to keep track of when/if implemetation() is in scope, if ManTypes#memberType() should not try to
 * substitute the qualifier type for @Self because the qualifier is not really a call site, rather it is the
 * declaring class of the method being checked for override etc.  Thus we need to let the normal signature flow
 * through.
 */
@Override
public Symbol.MethodSymbol implementation( Symbol.MethodSymbol ms, Symbol.TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter )
{
  _overrideCount++;
  try
  {
    return super.implementation( ms, origin, checkResult, implFilter );
  }
  finally
  {
    _overrideCount--;
  }
}
 
Example 7
Source File: TypeUtil.java    From manifold with Apache License 2.0 4 votes vote down vote up
public static boolean isAssignableFromErased( Context ctx, Symbol.ClassSymbol to, Symbol.TypeSymbol from )
{
  Types types = Types.instance( ctx );
  return types.isAssignable( types.erasure( to.asType() ), types.erasure( from.asType() ) );
}