Search in sources :

Example 1 with GradleSettingsModel

use of com.android.tools.idea.gradle.dsl.model.GradleSettingsModel in project android by JetBrains.

the class GradleDslExpression method resolveProjectReference.

@Nullable
private static GradleDslFile resolveProjectReference(GradleDslElement startElement, @NotNull String projectReference) {
    GradleDslFile dslFile = startElement.getDslFile();
    if ("project".equals(projectReference)) {
        return dslFile;
    }
    if ("parent".equals(projectReference)) {
        return dslFile.getParentModuleDslFile();
    }
    if ("rootProject".equals(projectReference)) {
        while (dslFile != null && !filesEqual(dslFile.getDirectoryPath(), virtualToIoFile(dslFile.getProject().getBaseDir()))) {
            dslFile = dslFile.getParentModuleDslFile();
        }
        return dslFile;
    }
    String standardProjectKey = getStandardProjectKey(projectReference);
    if (standardProjectKey != null) {
        // project(':project:path')
        String modulePath = standardProjectKey.substring(standardProjectKey.indexOf("'") + 1, standardProjectKey.lastIndexOf("'"));
        GradleSettingsModel model = GradleSettingsModel.get(dslFile.getProject());
        if (model == null) {
            return null;
        }
        File moduleDirectory = model.moduleDirectory(modulePath);
        if (moduleDirectory == null) {
            return null;
        }
        while (dslFile != null && !filesEqual(dslFile.getDirectoryPath(), virtualToIoFile(dslFile.getProject().getBaseDir()))) {
            dslFile = dslFile.getParentModuleDslFile();
        }
        if (dslFile == null) {
            return null;
        }
        // root module dsl File.
        return findDslFile(dslFile, moduleDirectory);
    }
    return null;
}
Also used : GradleSettingsModel(com.android.tools.idea.gradle.dsl.model.GradleSettingsModel) GradleDslFile(com.android.tools.idea.gradle.dsl.parser.GradleDslFile) File(java.io.File) GradleDslFile(com.android.tools.idea.gradle.dsl.parser.GradleDslFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GradleSettingsModel (com.android.tools.idea.gradle.dsl.model.GradleSettingsModel)1 GradleDslFile (com.android.tools.idea.gradle.dsl.parser.GradleDslFile)1 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)1 File (java.io.File)1 Nullable (org.jetbrains.annotations.Nullable)1