org.jetbrains.android.facet.AndroidFacet Java Examples

The following examples show how to use org.jetbrains.android.facet.AndroidFacet. 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: BlazeAndroidRunConfigurationRunner.java    From intellij with Apache License 2.0 7 votes vote down vote up
private static String canDebug(
    DeviceFutures deviceFutures, AndroidFacet facet, String moduleName) {
  // If we are debugging on a device, then the app needs to be debuggable
  for (ListenableFuture<IDevice> future : deviceFutures.get()) {
    if (!future.isDone()) {
      // this is an emulator, and we assume that all emulators are debuggable
      continue;
    }
    IDevice device = Futures.getUnchecked(future);
    if (!LaunchUtils.canDebugAppOnDevice(facet, device)) {
      return AndroidBundle.message(
          "android.cannot.debug.noDebugPermissions", moduleName, device.getName());
    }
  }
  return null;
}
 
Example #2
Source File: PackageNameUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String getRawPackageNameFromIndex(AndroidFacet facet) {
  VirtualFile primaryManifest = SourceProviderManager.getInstance(facet).getMainManifestFile();
  if (primaryManifest == null) {
    return null;
  }
  Project project = facet.getModule().getProject();
  try {
    AndroidManifestRawText manifestRawText =
        DumbService.getInstance(project)
            .runReadActionInSmartMode(
                () -> AndroidManifestIndex.getDataForManifestFile(project, primaryManifest));
    return manifestRawText == null ? null : manifestRawText.getPackageName();
  } catch (IndexNotReadyException e) {
    // TODO(142681129): runReadActionInSmartMode doesn't work if we already have read access.
    //  We need to refactor the callers of AndroidManifestUtils#getPackage to require a *smart*
    //  read action, at which point we can remove this try-catch.
    return null;
  }
}
 
Example #3
Source File: BlazeNativeAndroidDebugger.java    From intellij with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
@Override
@Nullable
public Module findModuleForProcess(Project project, String packageName) {
  for (Module module : ModuleManager.getInstance(project).getModules()) {
    if (AndroidFacet.getInstance(module) == null) {
      continue; // A module must have an attached AndroidFacet to have a package name.
    }

    BlazeModuleSystem moduleSystem = BlazeModuleSystem.getInstance(module);
    String modulePackageName = ReadAction.compute(() -> moduleSystem.getPackageName());
    if (modulePackageName != null && modulePackageName.equals(packageName)) {
      return module;
    }
  }
  return null;
}
 
Example #4
Source File: AndroidFacetModuleCustomizer.java    From intellij with Apache License 2.0 6 votes vote down vote up
public static void createAndroidFacet(Module module, boolean isApp) {
  AndroidFacet facet = AndroidFacet.getInstance(module);
  if (facet != null) {
    configureFacet(facet, isApp);
  } else {
    // Module does not have Android facet. Create one and add it.
    FacetManager facetManager = FacetManager.getInstance(module);
    ModifiableFacetModel model = facetManager.createModifiableModel();
    try {
      facet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
      model.addFacet(facet);
      configureFacet(facet, isApp);
    } finally {
      model.commit();
    }
  }
}
 
Example #5
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateAndroidModuleLibraryDependencies(Module flutterModule) {
  for (final Module module : ModuleManager.getInstance(getProject()).getModules()) {
    if (module != flutterModule) {
      if (null != FacetManager.getInstance(module).findFacet(AndroidFacet.ID, "Android")) {
        Object circularModules = CircularModuleDependenciesDetector.addingDependencyFormsCircularity(module, flutterModule);
        if (circularModules == null) {
          ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
          if (!rootManager.isDependsOn(flutterModule)) {
            JavaProjectModelModifier[] modifiers = JavaProjectModelModifier.EP_NAME.getExtensions(getProject());
            for (JavaProjectModelModifier modifier : modifiers) {
              if (modifier instanceof IdeaProjectModelModifier) {
                modifier.addModuleDependency(module, flutterModule, DependencyScope.COMPILE, false);
              }
            }
          }
        }
      }
    }
  }
}
 
Example #6
Source File: BlazeAndroidSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public boolean validate(
    Project project, BlazeContext context, BlazeProjectData blazeProjectData) {
  if (!isAndroidWorkspace(blazeProjectData.getWorkspaceLanguageSettings())) {
    return true;
  }

  boolean valid = true;
  for (Module module : ModuleManager.getInstance(project).getModules()) {
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (BlazeAndroidSyncPluginCompat.facetHasAndroidModel(facet)) {
      IssueOutput.error("Android model missing for module: " + module.getName()).submit(context);
      valid = false;
    }
  }
  return valid;
}
 
Example #7
Source File: BlazeAndroidRunConfigurationValidationUtil.java    From intellij with Apache License 2.0 6 votes vote down vote up
public static void validateExecution(
    @Nullable Module module,
    @Nullable AndroidFacet facet,
    @Nullable ProjectViewSet projectViewSet)
    throws ExecutionException {
  List<ValidationError> errors = Lists.newArrayList();
  errors.addAll(validateModule(module));
  if (module != null) {
    errors.addAll(validateFacet(facet, module));
  }
  if (projectViewSet == null) {
    errors.add(ValidationError.fatal("Could not load project view. Please resync project"));
  }

  if (errors.isEmpty()) {
    return;
  }
  ValidationError topError = Ordering.natural().max(errors);
  if (topError.isFatal()) {
    throw new ExecutionException(topError.getMessage());
  }
}
 
Example #8
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateAndroidModuleLibraryDependencies(Module flutterModule) {
  for (final Module module : ModuleManager.getInstance(getProject()).getModules()) {
    if (module != flutterModule) {
      if (null != FacetManager.getInstance(module).findFacet(AndroidFacet.ID, "Android")) {
        Object circularModules = CircularModuleDependenciesDetector.addingDependencyFormsCircularity(module, flutterModule);
        if (circularModules == null) {
          ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
          if (!rootManager.isDependsOn(flutterModule)) {
            JavaProjectModelModifier[] modifiers = JavaProjectModelModifier.EP_NAME.getExtensions(getProject());
            for (JavaProjectModelModifier modifier : modifiers) {
              if (modifier instanceof IdeaProjectModelModifier) {
                modifier.addModuleDependency(module, flutterModule, DependencyScope.COMPILE, false);
              }
            }
          }
        }
      }
    }
  }
}
 
Example #9
Source File: BlazeAndroidBinaryRunConfigurationHandler.java    From intellij with Apache License 2.0 6 votes vote down vote up
private BlazeAndroidRunContext createRunContext(
    Project project,
    AndroidFacet facet,
    ExecutionEnvironment env,
    ImmutableList<String> blazeFlags,
    ImmutableList<String> exeFlags) {
  switch (configState.getLaunchMethod()) {
    case NON_BLAZE:
      if (!maybeShowMobileInstallOptIn(project, configuration)) {
        return new BlazeAndroidBinaryNormalBuildRunContext(
            project, facet, configuration, env, configState, getLabel(), blazeFlags);
      }
      // fall through
    case MOBILE_INSTALL_V2:
      // Standardize on a single mobile-install launch method
      configState.setLaunchMethod(AndroidBinaryLaunchMethod.MOBILE_INSTALL);
      // fall through
    case MOBILE_INSTALL:
      return new BlazeAndroidBinaryMobileInstallRunContext(
          project, facet, configuration, env, configState, getLabel(), blazeFlags, exeFlags);
  }
  throw new AssertionError();
}
 
Example #10
Source File: BlazeNewResourceCreationHandler.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public CreateResourceFileDialogBase createNewResourceFileDialog(
    AndroidFacet facet,
    Collection<CreateTypedResourceFileAction> actions,
    @Nullable ResourceFolderType folderType,
    @Nullable String filename,
    @Nullable String rootElement,
    @Nullable FolderConfiguration folderConfiguration,
    boolean chooseFileName,
    boolean chooseModule,
    @Nullable PsiDirectory resDirectory,
    @Nullable DataContext dataContext,
    CreateResourceFileDialogBase.ValidatorFactory validatorFactory) {
  return new BlazeCreateResourceFileDialog(
      facet,
      actions,
      folderType,
      filename,
      rootElement,
      folderConfiguration,
      chooseFileName,
      chooseModule,
      resDirectory,
      dataContext,
      validatorFactory);
}
 
Example #11
Source File: BlazeAndroidBinaryNormalBuildRunContextBase.java    From intellij with Apache License 2.0 6 votes vote down vote up
BlazeAndroidBinaryNormalBuildRunContextBase(
    Project project,
    AndroidFacet facet,
    RunConfiguration runConfiguration,
    ExecutionEnvironment env,
    BlazeAndroidBinaryRunConfigurationState configState,
    Label label,
    ImmutableList<String> blazeFlags) {
  this.project = project;
  this.facet = facet;
  this.runConfiguration = runConfiguration;
  this.env = env;
  this.configState = configState;
  this.consoleProvider = new BlazeAndroidBinaryConsoleProvider(project);
  this.buildStep = new BlazeApkBuildStepNormalBuild(project, label, blazeFlags);
  this.apkProvider = new BlazeApkProvider(project, buildStep);
  this.applicationIdProvider = new BlazeAndroidBinaryApplicationIdProvider(buildStep);
}
 
Example #12
Source File: BlazeAndroidBinaryMobileInstallRunContextBase.java    From intellij with Apache License 2.0 6 votes vote down vote up
public BlazeAndroidBinaryMobileInstallRunContextBase(
    Project project,
    AndroidFacet facet,
    RunConfiguration runConfiguration,
    ExecutionEnvironment env,
    BlazeAndroidBinaryRunConfigurationState configState,
    Label label,
    ImmutableList<String> blazeFlags,
    ImmutableList<String> exeFlags) {
  this.project = project;
  this.facet = facet;
  this.runConfiguration = runConfiguration;
  this.env = env;
  this.configState = configState;
  this.consoleProvider = new BlazeAndroidBinaryConsoleProvider(project);
  this.buildStep = new BlazeApkBuildStepMobileInstall(project, label, blazeFlags, exeFlags);
  this.applicationIdProvider = new BlazeAndroidBinaryApplicationIdProvider(buildStep);
}
 
Example #13
Source File: DeviceChooserDialog.java    From ADB-Duang with MIT License 6 votes vote down vote up
public DeviceChooserDialog(@NotNull final AndroidFacet facet) {
    super(facet.getModule().getProject(), true);
    setTitle(AndroidBundle.message("choose.device.dialog.title"));

    myProject = facet.getModule().getProject();
    final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);

    getOKAction().setEnabled(false);

    myDeviceChooser = new MyDeviceChooser(false, getOKAction(), facet, facet.getConfiguration().getAndroidTarget(), null);
    Disposer.register(myDisposable, myDeviceChooser);
    myDeviceChooser.addListener(new DeviceChooserListener() {
        @Override
        public void selectedDevicesChanged() {
            updateOkButton();
        }
    });
    myDeviceChooserWrapper.add(myDeviceChooser.getPanel());
    final String[] selectedSerials = getSelectedSerialsFromPreferences(properties);
    myDeviceChooser.init(selectedSerials);
    init();
    updateEnabled();
}
 
Example #14
Source File: BlazeNativeAndroidDebugger.java    From intellij with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
@Override
@Nullable
public Module findModuleForProcess(Project project, String packageName) {
  for (Module module : ModuleManager.getInstance(project).getModules()) {
    if (AndroidFacet.getInstance(module) == null) {
      continue; // A module must have an attached AndroidFacet to have a package name.
    }

    BlazeModuleSystem moduleSystem = BlazeModuleSystem.getInstance(module);
    String modulePackageName = ReadAction.compute(() -> moduleSystem.getPackageName());
    if (modulePackageName != null && modulePackageName.equals(packageName)) {
      return module;
    }
  }
  return null;
}
 
Example #15
Source File: FolivoraDomExtender.java    From Folivora with Apache License 2.0 6 votes vote down vote up
@Override
public void registerExtensions(@Nonnull AndroidDomElement element,
                               @Nonnull final DomExtensionsRegistrar registrar) {
  final AndroidFacet facet = AndroidFacet.getInstance(element);

  if (facet == null) {
    return;
  }

  AttributeProcessingUtil.AttributeProcessor callback = (xmlName, attrDef, parentStyleableName)
    -> {
    Set<?> formats = attrDef.getFormats();
    Class valueClass = formats.size() == 1 ? getValueClass(formats.iterator().next()) : String
      .class;
    registrar.registerAttributeChildExtension(xmlName, GenericAttributeValue.class);
    return registrar.registerGenericAttributeValueChildExtension(xmlName, valueClass);
  };

  try {
    FolivoraAttrProcessing.registerFolivoraAttributes(facet, element, callback);
  } catch (Exception ignore) {}
}
 
Example #16
Source File: BlazeProjectSystem.java    From intellij with Apache License 2.0 6 votes vote down vote up
@NotNull
// #api41 @Override
public Collection<AndroidFacet> getAndroidFacetsWithPackageName(
    @NotNull Project project, @NotNull String packageName, @NotNull GlobalSearchScope scope) {
  List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
  return facets.stream()
      .filter(facet -> hasPackageName(facet, packageName))
      .filter(
          facet -> {
            VirtualFile file = SourceProviderManager.getInstance(facet).getMainManifestFile();
            if (file == null) {
              return false;
            } else {
              return scope.contains(file);
            }
          })
      .collect(Collectors.toList());
}
 
Example #17
Source File: FolivoraAttrProcessing.java    From Folivora with Apache License 2.0 6 votes vote down vote up
private static void registerAttributes(/*NotNull*/ AndroidFacet facet,
  /*NotNull*/ DomElement element,
  /*NotNull*/ String styleableName,
  /*NotNull*/ AttributeProcessingUtil.AttributeProcessor callback) {

  ResourceManager manager = AndroidFacetCompat.getAppResourceManager(facet);
  if (manager == null) {
    return;
  }

  AttributeDefinitions attrDefs = manager.getAttributeDefinitions();
  if (attrDefs == null) {
    return;
  }

  String namespace = getNamespaceUriByResourcePackage(facet, null);
  StyleableDefinition styleable = attrDefs.getStyleableByName(styleableName);
  if (styleable != null) {
    registerStyleableAttributes(element, styleable, namespace, callback);
  }
  // It's a good idea to add a warning when styleable not found, to make sure that code doesn't
  // try to use attributes that don't exist. However, current AndroidDomExtender code relies on
  // a lot of "heuristics" that fail quite a lot (like adding a bunch of suffixes to short
  // class names)
  // TODO: add a warning when rest of the code of AndroidDomExtender is cleaned up
}
 
Example #18
Source File: BlazeProjectSystem.java    From intellij with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
public SourceProvidersFactory getSourceProvidersFactory() {
  return new SourceProvidersFactory() {
    @Nullable
    @Override
    public SourceProviders createSourceProvidersFor(@NotNull AndroidFacet facet) {
      BlazeAndroidModel model = ((BlazeAndroidModel) AndroidModel.get(facet));
      if (model != null) {
        NamedIdeaSourceProvider mainSourceProvider =
            createIdeaSourceProviderFromModelSourceProvider(model.getDefaultSourceProvider());
        return new SourceProvidersImpl(
            mainSourceProvider,
            ImmutableList.of(mainSourceProvider),
            ImmutableList.of(mainSourceProvider),
            ImmutableList.of(mainSourceProvider),
            ImmutableList.of(mainSourceProvider),
            ImmutableList.of(mainSourceProvider));
      } else {
        return createSourceProvidersForLegacyModule(facet);
      }
    }
  };
}
 
Example #19
Source File: BlazeSampleDataDirectoryProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public PathString getSampleDataDirectory() {
  // If this isn't a resource module then it doesn't have any layouts
  // that we could open in the layout editor anyway, so there's no
  // reason for a sample data directory.
  if (!isResourceModule) {
    return null;
  }

  AndroidFacet facet = AndroidFacet.getInstance(module);
  VirtualFile mainContentRoot = facet != null ? AndroidRootUtil.getMainContentRoot(facet) : null;
  if (mainContentRoot == null) {
    return null;
  }

  // The main content root of a resource module is its res folder.
  // Instead, we'll use the res folder's parent directory so that the
  // sample data directory and the res folder sit parallel to one another.
  VirtualFile parentDir = getSampleDataDirectoryHomeForResFolder(mainContentRoot);
  if (parentDir == null) {
    return null;
  }

  return toPathString(parentDir).resolve(FD_SAMPLE_DATA);
}
 
Example #20
Source File: BlazeAndroidTestRunConfigurationHandler.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * We collect errors rather than throwing to avoid missing fatal errors by exiting early for a
 * warning. We use a separate method for the collection so the compiler prevents us from
 * accidentally throwing.
 */
private List<ValidationError> validate() {
  List<ValidationError> errors = Lists.newArrayList();
  Module module = getModule();
  errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateModule(module));
  AndroidFacet facet = null;
  if (module != null) {
    facet = AndroidFacet.getInstance(module);
    errors.addAll(BlazeAndroidRunConfigurationValidationUtil.validateFacet(facet, module));
  }
  errors.addAll(configState.validate(facet));
  return errors;
}
 
Example #21
Source File: BlazeLightResourceClassService.java    From intellij with Apache License 2.0 5 votes vote down vote up
public void addRClass(String resourceJavaPackage, Module module) {
  AndroidFacet androidFacet = AndroidFacet.getInstance(module);
  if (androidFacet == null) {
    return; // Do not register R class if android facet is not present.
  }
  BlazeRClass rClass = new BlazeRClass(psiManager, androidFacet, resourceJavaPackage);
  rClassMap.put(getQualifiedRClassName(resourceJavaPackage), rClass);
  rClassByModuleMap.put(module, rClass);
  if (createStubResourcePackages.getValue()) {
    addStubPackages(resourceJavaPackage);
  }
}
 
Example #22
Source File: BlazeAndroidRunConfigurationDeployTargetManager.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
DeployTarget getDeployTarget(
    Executor executor, ExecutionEnvironment env, AndroidFacet facet, int runConfigId)
    throws ExecutionException {
  DeployTargetProvider currentTargetProvider = getCurrentDeployTargetProvider();
  Project project = env.getProject();

  DeployTarget deployTarget;

  if (currentTargetProvider.requiresRuntimePrompt(project)) {
    deployTarget =
        currentTargetProvider.showPrompt(
            executor,
            env,
            facet,
            getDeviceCount(),
            isAndroidTest,
            deployTargetStates,
            runConfigId,
            (device) -> LaunchCompatibility.YES);
    if (deployTarget == null) {
      return null;
    }
  } else {
    deployTarget = currentTargetProvider.getDeployTarget(env.getProject());
  }

  return deployTarget;
}
 
Example #23
Source File: BlazeAndroidRunConfigurationCommonState.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * We collect errors rather than throwing to avoid missing fatal errors by exiting early for a
 * warning.
 */
public List<ValidationError> validate(@Nullable AndroidFacet facet) {
  List<ValidationError> errors = Lists.newArrayList();
  // If facet is null, we can't validate the managers, but that's fine because
  // BlazeAndroidRunConfigurationValidationUtil.validateFacet will give a fatal error.
  if (facet == null) {
    return errors;
  }

  errors.addAll(deployTargetManager.validate(facet));
  errors.addAll(debuggerManager.validate(facet));
  Project project = facet.getModule().getProject();
  BlazeProjectData blazeProjectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (blazeProjectData == null) {
    errors.add(ValidationError.fatal("Project data missing. Please sync your project."));
    return errors;
  }

  if (isNativeDebuggingEnabled()
      && !blazeProjectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.C)) {
    errors.add(
        ValidationError.fatal(
            "Native debugging requires C language support.",
            () ->
                AdditionalLanguagesHelper.enableLanguageSupport(
                    project, ImmutableList.of(LanguageClass.C))));
  }

  return errors;
}
 
Example #24
Source File: AdbWifiConnect.java    From ADBWIFI with Apache License 2.0 5 votes vote down vote up
private static DeviceResult getDevice(Project project) {
    List<AndroidFacet> facets = getApplicationFacets(project);
    if (!facets.isEmpty()) {
        AndroidFacet facet = facets.get(0);
        String packageName = AdbUtil.computePackageName(facet);
        AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(project);
        if (bridge == null) {
            error("No platform configured");
            return null;
        }
        int count = 0;
        while (!bridge.isConnected() || !bridge.hasInitialDeviceList()) {
            try {
                Thread.sleep(100);
                count++;
            } catch (InterruptedException e) {
                // pass
            }

            // let's not wait > 10 sec.
            if (count > 100) {
                error("Timeout getting device list!");
                return null;
            }
        }

        IDevice[] devices = bridge.getDevices();
        if (devices.length == 1) {
            return new DeviceResult(devices, facet, packageName);
        } else if (devices.length > 1) {
            return askUserForDevice(facet, packageName);
        } else {
            return null;
        }

    }
    error("No devices found");
    return null;
}
 
Example #25
Source File: AdbWifiConnect.java    From ADBWIFI with Apache License 2.0 5 votes vote down vote up
private static DeviceResult askUserForDevice(AndroidFacet facet, String packageName) {
    final DeviceChooserDialog chooser = new DeviceChooserDialog(facet);
    chooser.show();

    if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return null;
    }

    IDevice[] selectedDevices = chooser.getSelectedDevices();
    if (selectedDevices.length == 0) {
        return null;
    }

    return new DeviceResult(selectedDevices, facet, packageName);
}
 
Example #26
Source File: BlazeAndroidRunConfigurationValidationUtil.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static List<ValidationError> validateFacet(@Nullable AndroidFacet facet, Module module) {
  List<ValidationError> errors = Lists.newArrayList();
  if (facet == null) {
    errors.add(ValidationError.fatal(AndroidBundle.message("no.facet.error", module.getName())));
    return errors;
  }
  if (AndroidPlatformCompat.getAndroidPlatform(facet) == null) {
    errors.add(ValidationError.fatal(AndroidBundle.message("select.platform.error")));
  }
  return errors;
}
 
Example #27
Source File: BlazeAndroidProjectStructureSyncerCompat.java    From intellij with Apache License 2.0 5 votes vote down vote up
static void updateAndroidFacetWithSourceAndModel(
    AndroidFacet facet, SourceProvider sourceProvider, BlazeAndroidModel androidModel) {
  facet.getProperties().RES_FOLDERS_RELATIVE_PATH =
      sourceProvider.getResDirectories().stream()
          .map(it -> pathToUrl(it.getAbsolutePath()))
          .collect(
              Collectors.joining(
                  AndroidFacetProperties.PATH_LIST_SEPARATOR_IN_FACET_CONFIGURATION));
  facet.getProperties().TEST_RES_FOLDERS_RELATIVE_PATH = "";
  AndroidModel.set(facet, androidModel);
}
 
Example #28
Source File: AndroidFacetModuleCustomizer.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static void removeAndroidFacet(Module module) {
  AndroidFacet facet = AndroidFacet.getInstance(module);
  if (facet != null) {
    ModifiableFacetModel facetModel = FacetManager.getInstance(module).createModifiableModel();
    facetModel.removeFacet(facet);
    facetModel.commit();
  }
}
 
Example #29
Source File: BlazeProjectSystem.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static boolean hasPackageName(AndroidFacet facet, String packageName) {
  String nameFromFacet = getPackageName(facet);
  if (nameFromFacet == null) {
    return false;
  }
  return nameFromFacet.equals(packageName);
}
 
Example #30
Source File: BlazeLightResourceClassService.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private BlazeRClass getRClassForWorkspace(String qualifiedName, GlobalSearchScope scope) {
  if (!workspaceResourcesFeature.isEnabled() || !workspaceRClassNames.contains(qualifiedName)) {
    return null;
  }

  BlazeRClass rClass = workspaceRClasses.get(qualifiedName);
  if (rClass != null) {
    if (scope.isSearchInModuleContent(rClass.getModule())) {
      return rClass;
    } else {
      return null;
    }
  }

  Module workspaceModule =
      ModuleManager.getInstance(project).findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
  if (workspaceModule == null || !scope.isSearchInModuleContent(workspaceModule)) {
    return null;
  }

  // Remove the .R suffix
  String packageName = qualifiedName.substring(0, qualifiedName.length() - 2);
  AndroidFacet workspaceFacet = AndroidFacet.getInstance(workspaceModule);
  if (workspaceFacet == null) {
    return null;
  }

  rClass = new BlazeRClass(psiManager, workspaceFacet, packageName);
  workspaceRClasses.put(qualifiedName, rClass);
  allRClasses.add(rClass);
  return rClass;
}