Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hurricup/bugfixes #2892

Merged
merged 5 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,7 +60,7 @@ protected static List<PsiElement> getLinearParents(PsiElement element) {
if (recursionMap.contains(run)) {
break;
}
result.add(0, run);
result.addFirst(run);
recursionMap.add(run);

run = run.getParentComponent();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -545,28 +545,18 @@ private Map<Class<? extends HTMLMasonCompositeElement>, List<HTMLMasonCompositeE

PsiTreeUtil.processElements(HTMLMasonFileImpl.this, element ->
{
if (element instanceof HTMLMasonOnceBlock) {
onceResult.add((HTMLMasonCompositeElement)element);
}
else if (element instanceof HTMLMasonSharedBlock) {
sharedResult.add((HTMLMasonCompositeElement)element);
}
else if (element instanceof HTMLMasonCleanupBlock) {
cleanupResult.add((HTMLMasonCompositeElement)element);
}
else if (element instanceof HTMLMasonInitBlock &&
HTMLMasonFileImpl.this.equals(PsiTreeUtil.getParentOfType(element, HTMLMasonArgsContainer.class))) {
initResult.add((HTMLMasonCompositeElement)element);
}
else if (element instanceof HTMLMasonArgsBlock &&
HTMLMasonFileImpl.this.equals(PsiTreeUtil.getParentOfType(element, HTMLMasonArgsContainer.class))) {
argsResult.add((HTMLMasonCompositeElement)element);
}
else if (element instanceof HTMLMasonMethodDefinition) {
methodsResult.add((HTMLMasonCompositeElement)element);
}
else if (element instanceof HTMLMasonSubcomponentDefitnition) {
subComponentsResult.add((HTMLMasonCompositeElement)element);
switch (element) {
case HTMLMasonOnceBlock block -> onceResult.add(block);
case HTMLMasonSharedBlock block -> sharedResult.add(block);
case HTMLMasonCleanupBlock block -> cleanupResult.add(block);
case HTMLMasonInitBlock block
when HTMLMasonFileImpl.this.equals(PsiTreeUtil.getParentOfType(element, HTMLMasonArgsContainer.class)) -> initResult.add(block);
case HTMLMasonArgsBlock block
when HTMLMasonFileImpl.this.equals(PsiTreeUtil.getParentOfType(element, HTMLMasonArgsContainer.class)) -> argsResult.add(block);
case HTMLMasonMethodDefinition definition -> methodsResult.add(definition);
case HTMLMasonSubcomponentDefitnition defitnition -> subComponentsResult.add(defitnition);
default -> {
}
}

return true;
Expand Down
10 changes: 5 additions & 5 deletions mojo/src/test/java/run/MojoProjectTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,8 +51,8 @@
if (projects.size() != 1) {
fail("Expected an application, got: " + projects);
}
assertInstanceOf(projects.get(0), MojoApp.class);
LOG.info("Got: " + projects.get(0));
assertInstanceOf(projects.getFirst(), MojoApp.class);
LOG.info("Got: " + projects.getFirst());

Check notice

Code scanning / QDJVM

Non-distinguishable logging calls Note test

Similar log messages
}

private @NotNull List<MojoProject> runMojoGenerateActionAndGetProjects(@NotNull MojoGenerateAction action) {
Expand Down Expand Up @@ -86,8 +86,8 @@
if (projects.size() != 1) {
fail("Expected a plugin, got: " + projects);
}
assertInstanceOf(projects.get(0), MojoPlugin.class);
LOG.info("Got: " + projects.get(0));
assertInstanceOf(projects.getFirst(), MojoPlugin.class);
LOG.info("Got: " + projects.getFirst());

Check notice

Code scanning / QDJVM

Non-distinguishable logging calls Note test

Similar log messages
}

private void assertMojoAvailable() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -320,7 +320,7 @@ public void visitElement(@NotNull PsiElement element) {
}
});

return result.isEmpty() ? null : result.get(0);
return result.isEmpty() ? null : result.getFirst();
}

public static String renderPodFile(PodFileImpl file) {
Expand Down Expand Up @@ -375,17 +375,17 @@ else if (elementType != TokenType.WHITE_SPACE && elementType != COMMENT_LINE) {
}
PsiElement run = podSection;

// detecting first section
while (true) {
PsiElement prevSibling = run.getPrevSibling();
//noinspection IfCanBeSwitch
if (prevSibling == null) {
break;
}
if (prevSibling instanceof PodSection && ((PodSection)prevSibling).hasContent()) {
break;
}
if (prevSibling instanceof PodTitledSection) {
podSection = (PodTitledSection)prevSibling;
if (prevSibling instanceof PodTitledSection section) {
podSection = section;
}
run = prevSibling;
}
Expand Down Expand Up @@ -417,7 +417,7 @@ else if (elementType != TokenType.WHITE_SPACE && elementType != COMMENT_LINE) {
if (run instanceof PodLinkTarget) {
String bcLink = ((PodLinkTarget)run).getPodLink();
if (StringUtil.isNotEmpty(bcLink)) {
breadCrumbs.add(0, PodRenderUtil.getHTMLPsiLink(bcLink, ((PodLinkTarget)run).getPodLinkText()));
breadCrumbs.addFirst(PodRenderUtil.getHTMLPsiLink(bcLink, ((PodLinkTarget)run).getPodLinkText()));
}
}
if (run instanceof PsiFile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -223,31 +223,23 @@
*/
@Contract("null->null")
public static @Nullable PsiElement findPodElement(@Nullable PsiElement element) {
if (element == null) {
return null;
}
else if (element instanceof PerlBuiltInSubDefinition) {
String subName = StringUtil.notNullize(((PerlBuiltInSubDefinition)element).getName());
if ("default".equals(subName)) {
return PerlDocUtil.resolveDescriptor(SWITCH_DOC_LINK, element, false);
}
else {
return PerlDocUtil.getPerlFuncDocFromText(element, subName);
return switch (element) {
case null -> null;

Check notice

Code scanning / QDJVM

Duplicate branches in 'switch' Note documentation

Branch in 'switch' is a duplicate of the default branch
case PerlBuiltInSubDefinition definition -> {
String subName = StringUtil.notNullize(definition.getName());
if ("default".equals(subName)) {
yield PerlDocUtil.resolveDescriptor(SWITCH_DOC_LINK, element, false);
}
else {
yield PerlDocUtil.getPerlFuncDocFromText(element, subName);
}
}
}
else if (element instanceof PerlSubElement) {
return findPodElement((PerlSubElement)element);
}
else if (element instanceof PerlFileImpl) {
return findPodElement((PerlFileImpl)element);
}
else if (element instanceof PerlNamespaceDefinitionElement) {
return findPodElement((PerlNamespaceDefinitionElement)element);
}
else if (element instanceof PerlVariable) {
return PerlDocUtil.getPerlVarDoc((PerlVariable)element);
}
return null;
case PerlSubElement subElement -> findPodElement(subElement);
case PerlFileImpl file -> findPodElement(file);
case PerlNamespaceDefinitionElement definitionElement -> findPodElement(definitionElement);
case PerlVariable variable -> PerlDocUtil.getPerlVarDoc(variable);
default -> null;
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -144,13 +144,13 @@ public class PerlCodeGeneratorImpl implements PerlCodeGenerator {
}

if (!superArgs.isEmpty()) {
superArgs.remove(0);
superArgs.removeFirst();
}

if (!arguments.isEmpty() && !arguments.get(0).isEmpty()) {
if (!arguments.isEmpty() && !arguments.getFirst().isEmpty()) {
//noinspection StringConcatenationInsideStringBufferAppend
code.append(
arguments.get(0).toStringShort() + "->SUPER::" + perlSubBase.getSubName() + "(" + StringUtil.join(superArgs, ", ") + ");\n");
arguments.getFirst().toStringShort() + "->SUPER::" + perlSubBase.getSubName() + "(" + StringUtil.join(superArgs, ", ") + ");\n");
}
code.append("}");
return code.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,8 +54,8 @@ public PerlFeaturesTable getFeaturesTable(PerlUseStatementElement useStatement,
if (allOptions != null) {
allOptions.removeAll(getOptions().keySet());

if (!allOptions.isEmpty() && !MOJO_BASE.equals(allOptions.get(0))) {
loadedPackages.add(allOptions.get(0));
if (!allOptions.isEmpty() && !MOJO_BASE.equals(allOptions.getFirst())) {
loadedPackages.add(allOptions.getFirst());
}
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public void changeParentsList(@NotNull PerlUseStatementElement useStatement, @No
else {
allOptions.removeAll(getOptions().keySet());
if (!allOptions.isEmpty()) {
currentList.add(allOptions.get(0));
currentList.add(allOptions.getFirst());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,7 +55,7 @@ public MojoLightDelegatingSubDefinition(@NotNull PerlUseStatementElement useStat
if (it instanceof PerlSubDefinition) {
List<PerlSubArgument> list = new ArrayList<>(((PerlSubDefinition)it).getSubArgumentsList());
if (!list.isEmpty()) {
list.remove(0);
list.removeFirst();
}
argumentsRef.set(list);
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2020 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,7 @@ public class MroProcessor extends PerlPragmaProcessorBase implements PerlMroProv
public @NotNull PerlMroType getMroType(PerlUseStatementElement useStatement) {
List<String> parameters = useStatement.getImportParameters();

if (parameters != null && !parameters.isEmpty() && "c3".equals(parameters.get(0))) {
if (parameters != null && !parameters.isEmpty() && "c3".equals(parameters.getFirst())) {
return PerlMroType.C3;
}
return PerlMroType.DFS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,30 @@ public class PerlFileTypeService implements Disposable {
private static final Logger LOG = Logger.getInstance(PerlFileTypeService.class);

private final NotNullLazyValue<LightDirectoryIndex<Function<VirtualFile, FileType>>> myDirectoryIndexProvider =
NotNullLazyValue.createValue(() -> {
return new LightDirectoryIndex<>(
this,
virtualFile -> null,
directoryIndex -> ReadAction.run(() -> {
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
if (project.isDisposed()) {
continue;
}
for (PerlFileTypeProvider fileTypeProvider : PerlFileTypeProvider.EP_NAME.getExtensionList()) {
fileTypeProvider.addRoots(project, (root, function) -> {
if (!root.isValid()) {
LOG.warn("Attempt to create a descriptor for invalid file for " + root);
return;
}
if (!root.isDirectory()) {
LOG.warn("Attempt to create root for non-directory: " + root);
return;
}
directoryIndex.putInfo(root, function);
});
}
NotNullLazyValue.createValue(() -> new LightDirectoryIndex<>(
this,
virtualFile -> null,
directoryIndex -> ReadAction.run(() -> {
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
if (project.isDisposed()) {
continue;
}
})
);
});
for (PerlFileTypeProvider fileTypeProvider : PerlFileTypeProvider.EP_NAME.getExtensionList()) {
fileTypeProvider.addRoots(project, (root, function) -> {
if (!root.isValid()) {
LOG.warn("Attempt to create a descriptor for invalid file for " + root);
return;
}
if (!root.isDirectory()) {
LOG.warn("Attempt to create root for non-directory: " + root);
return;
}
directoryIndex.putInfo(root, function);
});
}
}
})
));

public PerlFileTypeService() {
PerlFileTypeProvider.EP_NAME.addChangeListener(this::reset, this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -87,7 +87,7 @@ else if (StringUtil.contains(name, "/")) {
else {
pathChunks.add(name);
}
name = pathChunks.remove(pathChunks.size() - 1);
name = pathChunks.removeLast();

for (String pathChunk : pathChunks) {
if (StringUtil.isNotEmpty(pathChunk)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +57,7 @@ protected boolean isEnabled(@NotNull List<VirtualFile> files, @NotNull Module mo
if (files.isEmpty() || !PerlProjectManager.isPerlEnabled(module)) {
return false;
}
return !myType.equals(PerlModuleExtension.getInstance(module).getRootType(files.get(0)));
return !myType.equals(PerlModuleExtension.getInstance(module).getRootType(files.getFirst()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +57,7 @@ public void update(@NotNull AnActionEvent e) {
}

if (virtualFiles.size() == 1) {
PerlSourceRootType type = perlModuleExtension.getRootType(virtualFiles.get(0));
PerlSourceRootType type = perlModuleExtension.getRootType(virtualFiles.getFirst());
if (type == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 Alexandr Evstigneev
* Copyright 2015-2024 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -635,7 +635,7 @@ private void processIfUnlessCompound(@NotNull PerlIfUnlessCompound o, boolean co
List<PsiPerlConditionalBlock> conditionBlocks = o.getConditionalBlockList();

// if/unless branch
PsiPerlConditionalBlock mainBranch = conditionBlocks.isEmpty() ? null : conditionBlocks.remove(0);
PsiPerlConditionalBlock mainBranch = conditionBlocks.isEmpty() ? null : conditionBlocks.removeFirst();
processConditionalBranch(mainBranch, conditionValue, o);

// elsif branches
Expand Down
Loading
Loading