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

The following examples show how to use com.sun.tools.javac.code.Type.ClassType#asElement() . 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: JavaEnvironment.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private Optional<MethodSymbol> getOverrideInType(ClassType type, MethodSymbol method) {
  ClassSymbol classSymbol = (ClassSymbol) type.asElement();
  return getDeclaredMethods(type).stream()
      .map(MethodDeclarationPair::getDeclarationMethodSymbol)
      .filter(m -> m.overrides(method, classSymbol, internalTypes, false))
      .findFirst();
}
 
Example 2
Source File: HandleDelegate.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void addMethodBindings(List<MethodSig> signatures, ClassType ct, JavacTypes types, Set<String> banList) throws DelegateRecursion {
	TypeSymbol tsym = ct.asElement();
	if (tsym == null) return;
	
	for (Symbol member : tsym.getEnclosedElements()) {
		for (Compound am : member.getAnnotationMirrors()) {
			String name = null;
			try {
				name = am.type.tsym.flatName().toString();
			} catch (Exception ignore) {}
			
			if ("lombok.Delegate".equals(name) || "lombok.experimental.Delegate".equals(name)) {
				throw new DelegateRecursion(ct.tsym.name.toString(), member.name.toString());
			}
		}
		if (member.getKind() != ElementKind.METHOD) continue;
		if (member.isStatic()) continue;
		if (member.isConstructor()) continue;
		ExecutableElement exElem = (ExecutableElement)member;
		if (!exElem.getModifiers().contains(Modifier.PUBLIC)) continue;
		ExecutableType methodType = (ExecutableType) types.asMemberOf(ct, member);
		String sig = printSig(methodType, member.name, types);
		if (!banList.add(sig)) continue; //If add returns false, it was already in there
		boolean isDeprecated = (member.flags() & DEPRECATED) != 0;
		signatures.add(new MethodSig(member.name, methodType, isDeprecated, exElem));
	}
	
	if (ct.supertype_field instanceof ClassType) addMethodBindings(signatures, (ClassType) ct.supertype_field, types, banList);
	if (ct.interfaces_field != null) for (Type iface : ct.interfaces_field) {
		if (iface instanceof ClassType) addMethodBindings(signatures, (ClassType) iface, types, banList);
	}
}
 
Example 3
Source File: HandleExtensionMethod.java    From EasyMPermission with MIT License 5 votes vote down vote up
public Extension getExtension(final JavacNode typeNode, final ClassType extensionMethodProviderType) {
	List<MethodSymbol> extensionMethods = new ArrayList<MethodSymbol>();
	TypeSymbol tsym = extensionMethodProviderType.asElement();
	if (tsym != null) for (Symbol member : tsym.getEnclosedElements()) {
		if (member.getKind() != ElementKind.METHOD) continue;
		MethodSymbol method = (MethodSymbol) member;
		if ((method.flags() & (STATIC | PUBLIC)) == 0) continue;
		if (method.params().isEmpty()) continue;
		extensionMethods.add(method);
	}
	return new Extension(extensionMethods, tsym);
}