Search in sources :

Example 6 with GradleDslFile

use of com.android.tools.idea.gradle.dsl.parser.GradleDslFile 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

GradleDslFile (com.android.tools.idea.gradle.dsl.parser.GradleDslFile)6 Nullable (org.jetbrains.annotations.Nullable)4 ExtDslElement (com.android.tools.idea.gradle.dsl.parser.ext.ExtDslElement)2 File (java.io.File)2 GradlePropertiesModel.parsePropertiesFile (com.android.tools.idea.gradle.dsl.model.GradlePropertiesModel.parsePropertiesFile)1 GradleSettingsModel (com.android.tools.idea.gradle.dsl.model.GradleSettingsModel)1 GradleResolvedVariable (com.android.tools.idea.gradle.dsl.parser.GradleResolvedVariable)1 SubProjectsDslElement (com.android.tools.idea.gradle.dsl.parser.build.SubProjectsDslElement)1 GradleDslElement (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)1 GradleDslExpressionMap (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)1 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Map (java.util.Map)1 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)1