use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-plugins by JetBrains.
the class GrCucumberExtension method getGlue.
@Nullable
private String getGlue(PsiElement stepDefinition) {
if (stepDefinition != null && stepDefinition instanceof GrMethodCall) {
GroovyFile groovyFile = (GroovyFile) stepDefinition.getContainingFile();
VirtualFile vfile = groovyFile.getVirtualFile();
if (vfile != null) {
VirtualFile parentDir = vfile.getParent();
return PathUtil.getLocalPath(parentDir);
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project android by JetBrains.
the class GradleFilePsiMerger method mergeGradleFiles.
/**
* Merges the given source build.gradle content into the given destination build.gradle content,
* and resolves and dynamic Gradle dependencies into specific versions. If a support library
* filter is provided, the support libraries will be limited to match that filter. This is
* typically set to the compileSdkVersion, such that you don't end up mixing and matching
* compileSdkVersions and support libraries from different versions, which is not supported.
*/
public static String mergeGradleFiles(@NotNull String source, @NotNull String dest, @Nullable Project project, @Nullable final String supportLibVersionFilter) {
source = source.replace("\r", "");
dest = dest.replace("\r", "");
final Project project2;
boolean projectNeedsCleanup = false;
if (project != null && !project.isDefault()) {
project2 = project;
} else {
project2 = ((ProjectManagerImpl) ProjectManager.getInstance()).newProject("MergingOnly", "", false, true);
assert project2 != null;
((StartupManagerImpl) StartupManager.getInstance(project2)).runStartupActivities();
projectNeedsCleanup = true;
}
final GroovyFile templateBuildFile = (GroovyFile) PsiFileFactory.getInstance(project2).createFileFromText(SdkConstants.FN_BUILD_GRADLE, GroovyFileType.GROOVY_FILE_TYPE, source);
final GroovyFile existingBuildFile = (GroovyFile) PsiFileFactory.getInstance(project2).createFileFromText(SdkConstants.FN_BUILD_GRADLE, GroovyFileType.GROOVY_FILE_TYPE, dest);
String result = (new WriteCommandAction<String>(project2, "Merge Gradle Files", existingBuildFile) {
@Override
protected void run(@NotNull Result<String> result) throws Throwable {
mergePsi(templateBuildFile, existingBuildFile, project2, supportLibVersionFilter);
PsiElement formatted = CodeStyleManager.getInstance(project2).reformat(existingBuildFile);
result.setResult(formatted.getText());
}
}).execute().getResultObject();
if (projectNeedsCleanup) {
ApplicationManager.getApplication().runWriteAction(() -> {
Disposer.dispose(project2);
});
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class BaseScriptAnnotationChecker method checkApplicability.
@Override
public boolean checkApplicability(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
if (GroovyCommonClassNames.GROOVY_TRANSFORM_BASE_SCRIPT.equals(annotation.getQualifiedName())) {
PsiFile file = annotation.getContainingFile();
if (file instanceof GroovyFile && !(((GroovyFile) file).isScript())) {
holder.createErrorAnnotation(annotation, GroovyBundle.message("base.script.annotation.is.allowed.only.inside.scripts"));
return true;
}
PsiElement pparent = annotation.getParent().getParent();
if (pparent instanceof GrVariableDeclaration) {
GrTypeElement typeElement = ((GrVariableDeclaration) pparent).getTypeElementGroovy();
PsiType type = typeElement != null ? typeElement.getType() : null;
if (!InheritanceUtil.isInheritor(type, GroovyCommonClassNames.GROOVY_LANG_SCRIPT)) {
String typeText = type != null ? type.getCanonicalText() : CommonClassNames.JAVA_LANG_OBJECT;
holder.createErrorAnnotation(annotation, GroovyBundle.message("declared.type.0.have.to.extend.script", typeText));
return true;
}
}
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GroovyFileIconProvider method getIcon.
@Nullable
@Override
public Icon getIcon(@NotNull VirtualFile virtualFile, @Iconable.IconFlags int flags, @Nullable Project project) {
if (project == null || virtualFile.getFileType() != GroovyFileType.GROOVY_FILE_TYPE)
return null;
final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (!(psiFile instanceof GroovyFile))
return null;
final GroovyFile file = (GroovyFile) psiFile;
final Icon icon;
if (file.isScript()) {
icon = GroovyScriptTypeDetector.getIcon(file);
} else if (GrFileIndexUtil.isGroovySourceFile(file)) {
final GrTypeDefinition[] typeDefinitions = file.getTypeDefinitions();
icon = typeDefinitions.length > 0 ? typeDefinitions[0].getIcon(flags) : JetgroovyIcons.Groovy.GroovyFile;
} else {
icon = JetgroovyIcons.Groovy.Groovy_outsideSources;
}
return ElementBase.createLayeredIcon(psiFile, icon, ElementBase.transformFlags(psiFile, flags));
}
use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.
the class GrPackageInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitFile(@NotNull GroovyFileBase file) {
if (!(file instanceof GroovyFile))
return;
if (!myCheckScripts && file.isScript())
return;
String expectedPackage = ExpectedPackageNameProviderKt.inferExpectedPackageName((GroovyFile) file);
String actual = file.getPackageName();
if (!expectedPackage.equals(actual)) {
PsiElement toHighlight = getElementToHighlight((GroovyFile) file);
if (toHighlight == null)
return;
registerError(toHighlight, "Package name mismatch. Actual: '" + actual + "', expected: '" + expectedPackage + "'", new LocalQuickFix[] { new ChangePackageQuickFix(expectedPackage), GroovyQuickFixFactory.getInstance().createGrMoveToDirFix(actual) }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
}
};
}
Aggregations