/** Returns true if the given element can be referenced from other code in its own package. */ static boolean isElementAccessibleFromOwnPackage(Element element) { return isElementAccessibleFrom( element, MoreElements.getPackage(element).getQualifiedName().toString()); }
/** * Returns {@code true} if injecting an instance of {@code binding} from {@code callingPackage} * requires the use of an injection method. */ static boolean requiresInjectionMethod( ProvisionBinding binding, ImmutableList<Expression> arguments, CompilerOptions compilerOptions, String callingPackage, DaggerTypes types) { ExecutableElement method = MoreElements.asExecutable(binding.bindingElement().get()); return !binding.injectionSites().isEmpty() || binding.shouldCheckForNull(compilerOptions) || !isElementAccessibleFrom(method, callingPackage) || !areParametersAssignable(method, arguments, types) // This check should be removable once we drop support for -source 7 || method.getParameters().stream() .map(VariableElement::asType) .anyMatch(type -> !isRawTypeAccessible(type, callingPackage)); }
/** * Returns a code block that creates a new module instance, either by invoking the nullary * constructor if it's accessible from {@code requestingClass} or else by invoking the * constructor's generated proxy method. */ static CodeBlock newModuleInstance( TypeElement moduleElement, ClassName requestingClass, DaggerElements elements) { ModuleKind.checkIsModule(moduleElement); String packageName = requestingClass.packageName(); return nonPublicNullaryConstructor(moduleElement, elements) .filter(constructor -> !isElementAccessibleFrom(constructor, packageName)) .map( constructor -> CodeBlock.of("$T.newInstance()", constructorProxyTypeName(moduleElement))) .orElse(CodeBlock.of("new $T()", moduleElement)); } }