Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.annotations.UnstableReactNativeAPI;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.annotations.ReactPropGroup;
import com.facebook.react.uimanager.annotations.ReactPropertyHolder;
Expand Down Expand Up @@ -93,13 +94,16 @@ public class ReactPropertyProcessor extends ProcessorBase {

private static final TypeName PROPERTY_MAP_TYPE =
ParameterizedTypeName.get(Map.class, String.class, String.class);
public static final String VIEW_MANAGER_INTERFACE =
"com.facebook.react.uimanager.ViewManagerWithGeneratedInterface";

private final Map<ClassName, ClassInfo> mClasses;

@SuppressFieldNotInitialized private Filer mFiler;
@SuppressFieldNotInitialized private Messager mMessager;
@SuppressFieldNotInitialized private Elements mElements;
@SuppressFieldNotInitialized private Types mTypes;
@SuppressFieldNotInitialized private TypeMirror mViewManagerWithGeneratedInterface = null;

static {
DEFAULT_TYPES = new HashMap<>();
Expand Down Expand Up @@ -144,6 +148,17 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
mTypes = processingEnv.getTypeUtils();
}

private TypeMirror getViewManagerWithGeneratedInterface() {
if (mViewManagerWithGeneratedInterface == null) {
TypeElement typeElement = mElements.getTypeElement(VIEW_MANAGER_INTERFACE);
if (typeElement == null || typeElement.asType() == null) {
throw new IllegalStateException("Could not find " + VIEW_MANAGER_INTERFACE);
}
mViewManagerWithGeneratedInterface = typeElement.asType();
}
return mViewManagerWithGeneratedInterface;
}

@Override
public boolean processImpl(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// Clear properties from previous rounds
Expand All @@ -154,7 +169,10 @@ public boolean processImpl(Set<? extends TypeElement> annotations, RoundEnvironm
try {
TypeElement classType = (TypeElement) element;
ClassName className = ClassName.get(classType);
mClasses.put(className, parseClass(className, classType));
ClassInfo classInfo = parseClass(className, classType);
if (classInfo != null) {
mClasses.put(className, classInfo);
}
} catch (Exception e) {
error(element, e.getMessage());
}
Expand Down Expand Up @@ -192,9 +210,16 @@ private static boolean isShadowNodeType(TypeName typeName) {
return typeName.equals(SHADOW_NODE_IMPL_TYPE);
}

private ClassInfo parseClass(ClassName className, TypeElement typeElement) {
private @Nullable ClassInfo parseClass(ClassName className, TypeElement typeElement) {
TypeName targetType = getTargetType(typeElement.asType());
TypeName viewType = isShadowNodeType(targetType) ? null : targetType;
boolean implementsViewManagerWithGeneratedInterface =
mTypes.isAssignable(typeElement.asType(), getViewManagerWithGeneratedInterface());

if (ReactBuildConfig.UNSTABLE_ENABLE_MINIFY_LEGACY_ARCHITECTURE
&& implementsViewManagerWithGeneratedInterface) {
return null;
}

ClassInfo classInfo = new ClassInfo(className, typeElement, viewType);
findProperties(classInfo, typeElement);
Expand Down