use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GroovyCompletionData method hasReturnValue.
private static boolean hasReturnValue(PsiElement context) {
GrControlFlowOwner flowOwner = ControlFlowUtils.findControlFlowOwner(context);
if (flowOwner instanceof GrClosableBlock)
return true;
if (flowOwner instanceof GroovyFile)
return true;
if (flowOwner == null)
return true;
PsiElement parent = flowOwner.getParent();
if (parent instanceof GrMethod) {
return !PsiType.VOID.equals(((GrMethod) parent).getReturnType());
} else if (parent instanceof GrClassInitializer) {
return false;
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GantMemberContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
if (aClass != null && ClassUtil.getSuperClassesWithCache(aClass).containsKey("groovy.util.AntBuilder")) {
processAntTasks(processor, place, state);
return;
}
if (!(place instanceof GrReferenceExpression) || ((GrReferenceExpression) place).isQualified()) {
return;
}
GrClosableBlock closure = PsiTreeUtil.getContextOfType(place, GrClosableBlock.class, true);
boolean antTasksProcessed = false;
while (closure != null) {
final PsiElement parent = closure.getParent();
if (parent instanceof GrMethodCall) {
final PsiMethod method = ((GrMethodCall) parent).resolveMethod();
if (method instanceof AntBuilderMethod) {
antTasksProcessed = true;
if (!processAntTasks(processor, place, state)) {
return;
}
if (!((AntBuilderMethod) method).processNestedElements(processor)) {
return;
}
break;
}
}
closure = PsiTreeUtil.getContextOfType(closure, GrClosableBlock.class, true);
}
// ------- gant-specific
PsiFile file = place.getContainingFile();
if (file == null || !GroovyScriptUtil.isSpecificScriptFile(file, GantScriptType.INSTANCE)) {
return;
}
if (aClass instanceof GroovyScriptClass) {
for (GrArgumentLabel label : GantUtils.getScriptTargets((GroovyFile) file)) {
final String targetName = label.getName();
if (targetName != null) {
final PsiNamedElement variable = new LightVariableBuilder(targetName, GroovyCommonClassNames.GROOVY_LANG_CLOSURE, label).setBaseIcon(JetgroovyIcons.Groovy.Gant_target);
if (!ResolveUtil.processElement(processor, variable, state)) {
return;
}
}
}
}
if (!antTasksProcessed) {
processAntTasks(processor, place, state);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class ConvertParameterToMapEntryIntention method generateSignature.
@Nullable
private static GrClosureSignature generateSignature(GrParametersOwner owner, GrReferenceExpression refExpr) {
if (owner instanceof PsiMethod) {
final GroovyResolveResult resolveResult = refExpr.advancedResolve();
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
return GrClosureSignatureUtil.createSignature((PsiMethod) owner, substitutor);
} else if (owner instanceof GrClosableBlock) {
return GrClosureSignatureUtil.createSignature((GrClosableBlock) owner);
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class GeeseUtil method calculateRBraceAlignment.
static void calculateRBraceAlignment(PsiElement rBrace, AlignmentProvider alignments) {
int leadingBraceCount = 0;
PsiElement next;
if (!isClosureContainLF(rBrace))
return;
for (next = PsiUtil.getPreviousNonWhitespaceToken(rBrace); isClosureRBrace(next) && isClosureContainLF(next); next = PsiUtil.getPreviousNonWhitespaceToken(next)) {
leadingBraceCount++;
}
PsiElement cur = rBrace;
for (next = getNextNonWhitespaceToken(cur); isClosureRBrace(next); next = getNextNonWhitespaceToken(cur)) {
cur = next;
}
for (; leadingBraceCount > 0; leadingBraceCount--) {
cur = PsiUtil.getPreviousNonWhitespaceToken(cur);
}
PsiElement parent = cur.getParent();
LOG.assertTrue(parent instanceof GrClosableBlock);
//search for start of the line
cur = parent;
if (cur.getParent() instanceof GrMethodCall) {
GrMethodCall call = (GrMethodCall) cur.getParent();
GrExpression invoked = call.getInvokedExpression();
if (invoked instanceof GrReferenceExpression && ((GrReferenceExpression) invoked).getReferenceNameElement() != null) {
cur = ((GrReferenceExpression) invoked).getReferenceNameElement();
} else {
cur = call;
}
}
cur = PsiTreeUtil.getDeepestFirst(cur);
while (!PsiUtil.isNewLine(next = PsiTreeUtil.prevLeaf(cur, true))) {
if (next == null)
break;
if (next.getNode().getElementType() == TokenType.WHITE_SPACE && PsiTreeUtil.prevLeaf(next) == null) {
//if cur is first word in the text, whitespace could be before it
break;
}
cur = next;
}
int startOffset = cur.getTextRange().getStartOffset();
int endOffset = rBrace.getTextRange().getStartOffset();
if (rBrace.getContainingFile().getText().substring(startOffset, endOffset).indexOf('\n') < 0) {
return;
}
while (true) {
final PsiElement p = cur.getParent();
if (p != null && p.getTextOffset() == cur.getTextOffset()) {
cur = p;
} else {
break;
}
}
alignments.addPair(rBrace, cur, true);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock in project intellij-community by JetBrains.
the class ImportMavenRepositoriesTask method performTask.
private void performTask() {
if (myProject.isDisposed())
return;
if (ApplicationManager.getApplication().isUnitTestMode())
return;
final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
final List<PsiFile> psiFileList = ContainerUtil.newArrayList();
final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
for (Module module : moduleManager.getModules()) {
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
continue;
final String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (modulePath == null)
continue;
String buildScript = FileUtil.findFileInProvidedPath(modulePath, GradleConstants.DEFAULT_SCRIPT_NAME);
if (StringUtil.isEmpty(buildScript))
continue;
VirtualFile virtualFile = localFileSystem.refreshAndFindFileByPath(buildScript);
if (virtualFile == null)
continue;
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
if (psiFile == null)
continue;
psiFileList.add(psiFile);
}
final PsiFile[] psiFiles = ArrayUtil.toObjectArray(psiFileList, PsiFile.class);
final Set<MavenRemoteRepository> mavenRemoteRepositories = new ReadAction<Set<MavenRemoteRepository>>() {
@Override
protected void run(@NotNull Result<Set<MavenRemoteRepository>> result) throws Throwable {
Set<MavenRemoteRepository> myRemoteRepositories = ContainerUtil.newHashSet();
for (PsiFile psiFile : psiFiles) {
List<GrClosableBlock> repositoriesBlocks = ContainerUtil.newArrayList();
repositoriesBlocks.addAll(findClosableBlocks(psiFile, "repositories"));
for (GrClosableBlock closableBlock : findClosableBlocks(psiFile, "buildscript", "subprojects", "allprojects", "project", "configure")) {
repositoriesBlocks.addAll(findClosableBlocks(closableBlock, "repositories"));
}
for (GrClosableBlock repositoriesBlock : repositoriesBlocks) {
myRemoteRepositories.addAll(findMavenRemoteRepositories(repositoriesBlock));
}
}
result.setResult(myRemoteRepositories);
}
}.execute().getResultObject();
if (mavenRemoteRepositories == null || mavenRemoteRepositories.isEmpty())
return;
// register imported maven repository URLs but do not force to download the index
// the index can be downloaded and/or updated later using Maven Configuration UI (Settings -> Build, Execution, Deployment -> Build tools -> Maven -> Repositories)
MavenRepositoriesHolder.getInstance(myProject).update(mavenRemoteRepositories);
MavenProjectIndicesManager.getInstance(myProject).scheduleUpdateIndicesList(indexes -> {
if (myProject.isDisposed())
return;
final List<String> repositoriesWithEmptyIndex = ContainerUtil.mapNotNull(indexes, index -> index.getUpdateTimestamp() == -1 && MavenRepositoriesHolder.getInstance(myProject).contains(index.getRepositoryPathOrUrl()) ? index.getRepositoryPathOrUrl() : null);
if (!repositoriesWithEmptyIndex.isEmpty()) {
final NotificationData notificationData = new NotificationData(GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.title"), "\n<br>" + GradleBundle.message("gradle.integrations.maven.notification.not_updated_repository.text", StringUtil.join(repositoriesWithEmptyIndex, "<br>")), NotificationCategory.WARNING, NotificationSource.PROJECT_SYNC);
notificationData.setBalloonNotification(true);
notificationData.setBalloonGroup(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP);
notificationData.setListener("#open", new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
ShowSettingsUtil.getInstance().showSettingsDialog(myProject, MavenRepositoriesConfigurable.class);
}
});
notificationData.setListener("#disable", new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
final int result = Messages.showYesNoDialog(myProject, "Notification will be disabled for all projects.\n\n" + "Settings | Appearance & Behavior | Notifications | " + UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP + "\ncan be used to configure the notification.", "Unindexed Maven Repositories Gradle Detection", "Disable Notification", CommonBundle.getCancelButtonText(), Messages.getWarningIcon());
if (result == Messages.YES) {
NotificationsConfigurationImpl.getInstanceImpl().changeSettings(UNINDEXED_MAVEN_REPOSITORIES_NOTIFICATION_GROUP, NotificationDisplayType.NONE, false, false);
notification.hideBalloon();
}
}
});
ExternalSystemNotificationManager.getInstance(myProject).showNotification(GradleConstants.SYSTEM_ID, notificationData);
}
});
}
Aggregations