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

wip: fix failing test cases ~118 left #2301

Merged
merged 1 commit into from
May 15, 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
Expand Up @@ -909,9 +909,7 @@ private void areaAWarning(Token token) {
private void areaBWarning(ParserRuleContext ctx) {
final int start = ctx.getStart().getTokenIndex();
final int stop = ctx.getStop().getTokenIndex();

areaBWarning(
start < stop ? tokenStream.getTokens(start, stop) : ImmutableList.of(ctx.getStart()));
areaBWarning(start < stop ? tokenStream.getTokens(start, stop) : ImmutableList.of(ctx.getStart()));
}

private void areaBWarning(@NonNull List<Token> tokenList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
import static org.eclipse.lsp.cobol.core.visitor.VisitorHelper.*;

import com.google.common.collect.ImmutableList;

import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -296,12 +298,12 @@ public List<Node> visitXmlParseStatement(XmlParseStatementContext ctx) {
.orElse(null);

ProcedureName procName = parseProcedureName(Optional.ofNullable(ctx.xmlProcessinProcedure())
.map(XmlProcessinProcedureContext::procedureName)
.orElse(null));
.map(XmlProcessinProcedureContext::procedureName)
.orElse(null));

ProcedureName thru = parseProcedureName(Optional.ofNullable(ctx.through())
.map(ThroughContext::procedureName)
.orElse(null));
.map(ThroughContext::procedureName)
.orElse(null));

return addTreeNode(
ctx,
Expand All @@ -315,7 +317,7 @@ public List<Node> visitXmlParseStatement(XmlParseStatementContext ctx) {
xmlNationalContext,
procName,
thru)
);
);
}

@Override
Expand All @@ -331,10 +333,10 @@ public List<Node> visitNotOnExceptionClause(CobolParser.NotOnExceptionClauseCont
@Override
public List<Node> visitUseStatement(CobolParser.UseStatementContext ctx) {
return ctx.useDebugClause() != null
?
addTreeNode(ctx, l -> new UseForDebuggingNode(l, null))
:
addTreeNode(ctx, UseNode::new);
?
addTreeNode(ctx, l -> new UseForDebuggingNode(l, null))
:
addTreeNode(ctx, UseNode::new);
}

/**
Expand Down Expand Up @@ -430,7 +432,7 @@ public List<Node> visitXmlGenerate(XmlGenerateContext ctx) {
identifier6,
identifier7,
identifier8
));
));

}

Expand Down Expand Up @@ -757,8 +759,8 @@ public List<Node> visitPerformInlineStatement(PerformInlineStatementContext ctx)
public List<Node> visitPerformProcedureStatement(PerformProcedureStatementContext ctx) {
final ProcedureName targetName = parseProcedureName(ctx.procedureName());
final ProcedureName thruName = parseProcedureName(Optional.ofNullable(ctx.through())
.map(ThroughContext::procedureName)
.orElse(null));
.map(ThroughContext::procedureName)
.orElse(null));
return addTreeNode(ctx, locality -> new PerformNode(locality, targetName, thruName));
}

Expand Down Expand Up @@ -1055,8 +1057,8 @@ public List<Node> visitProcedureDivisionBody(ProcedureDivisionBodyContext ctx) {

List<Node> children = visitChildren(ctx);
return retrieveLocality(context)
.map(constructNode(ProcedureDivisionBodyNode::new, children))
.orElse(children);
.map(constructNode(ProcedureDivisionBodyNode::new, children))
.orElse(children);
}

@Override
Expand Down Expand Up @@ -1161,17 +1163,17 @@ public List<Node> visitSortStatement(CobolParser.SortStatementContext ctx) {
String key;
if (ctx.sortOnKeyClause() != null) {
ascending = ctx.sortOnKeyClause().stream()
.map(s -> s.ASCENDING() != null)
.filter(b -> b)
.findAny()
.orElse(false);
.map(s -> s.ASCENDING() != null)
.filter(b -> b)
.findAny()
.orElse(false);

key = ctx.sortOnKeyClause().stream()
.map(SortOnKeyClauseContext::KEY)
.filter(Objects::nonNull)
.map(ParseTree::getText)
.findFirst()
.orElse("");
.map(SortOnKeyClauseContext::KEY)
.filter(Objects::nonNull)
.map(ParseTree::getText)
.findFirst()
.orElse("");
} else {
ascending = false;
key = "";
Expand All @@ -1186,17 +1188,17 @@ public List<Node> visitMergeStatement(CobolParser.MergeStatementContext ctx) {
String key;
if (ctx.mergeOnKeyClause() != null) {
ascending = ctx.mergeOnKeyClause().stream()
.map(s -> s.ASCENDING() != null)
.filter(b -> b)
.findAny()
.orElse(false);
.map(s -> s.ASCENDING() != null)
.filter(b -> b)
.findAny()
.orElse(false);

key = ctx.mergeOnKeyClause().stream()
.map(MergeOnKeyClauseContext::KEY)
.filter(Objects::nonNull)
.map(ParseTree::getText)
.findFirst()
.orElse("");
.map(MergeOnKeyClauseContext::KEY)
.filter(Objects::nonNull)
.map(ParseTree::getText)
.findFirst()
.orElse("");
} else {
ascending = false;
key = "";
Expand All @@ -1209,8 +1211,8 @@ public List<Node> visitMergeStatement(CobolParser.MergeStatementContext ctx) {
public List<Node> visitInputProcedurePhrase(CobolParser.InputProcedurePhraseContext ctx) {
final ProcedureName procName = parseProcedureName(ctx.procedureName());
final ProcedureName thru = parseProcedureName(Optional.ofNullable(ctx.through())
.map(ThroughContext::procedureName)
.orElse(null));
.map(ThroughContext::procedureName)
.orElse(null));

Locality locality = retrieveLocality(ctx).orElse(null);
InputNode node = new InputNode(locality);
Expand All @@ -1225,8 +1227,8 @@ public List<Node> visitInputProcedurePhrase(CobolParser.InputProcedurePhraseCont
public List<Node> visitOutputProcedurePhrase(CobolParser.OutputProcedurePhraseContext ctx) {
final ProcedureName procName = parseProcedureName(ctx.procedureName());
final ProcedureName thru = parseProcedureName(Optional.ofNullable(ctx.through())
.map(ThroughContext::procedureName)
.orElse(null));
.map(ThroughContext::procedureName)
.orElse(null));

Locality locality = retrieveLocality(ctx).orElse(null);
OutputNode node = new OutputNode(locality);
Expand All @@ -1237,7 +1239,8 @@ public List<Node> visitOutputProcedurePhrase(CobolParser.OutputProcedurePhraseCo
return ImmutableList.of(node);
}

@Override public List<Node> visitAlterStatement(CobolParser.AlterStatementContext ctx) {
@Override
public List<Node> visitAlterStatement(CobolParser.AlterStatementContext ctx) {
if (ctx.alterProceedTo() != null && ctx.alterProceedTo().size() > 0) {
CobolParser.AlterProceedToContext alter = ctx.alterProceedTo().get(0);
if (alter.procedureName() != null && alter.procedureName().size() == 2) {
Expand All @@ -1246,14 +1249,14 @@ public List<Node> visitOutputProcedurePhrase(CobolParser.OutputProcedurePhraseCo

String name = Optional.ofNullable(from.paragraphName()).map(RuleContext::getText).orElse(null);
String inSection = Optional.ofNullable(from.inSection())
.map(InSectionContext::sectionName)
.map(RuleContext::getText).orElse(null);
.map(InSectionContext::sectionName)
.map(RuleContext::getText).orElse(null);
ProcedureName alterFrom = new ProcedureName(name, inSection);

name = Optional.ofNullable(to.paragraphName()).map(RuleContext::getText).orElse(null);
inSection = Optional.ofNullable(to.inSection())
.map(InSectionContext::sectionName)
.map(RuleContext::getText).orElse(null);
.map(InSectionContext::sectionName)
.map(RuleContext::getText).orElse(null);
ProcedureName alterTo = new ProcedureName(name, inSection);

Locality locality = retrieveLocality(ctx).orElse(null);
Expand Down Expand Up @@ -1356,8 +1359,7 @@ protected void areaBWarning(ParserRuleContext ctx) {
final int start = ctx.getStart().getTokenIndex();
final int stop = ctx.getStop().getTokenIndex();

areaBWarning(
start < stop ? tokenStream.getTokens(start, stop) : ImmutableList.of(ctx.getStart()));
areaBWarning(start < stop ? tokenStream.getTokens(start, stop) : ImmutableList.of(ctx.getStart()));
}

private void areaBWarning(@NonNull List<Token> tokenList) {
Expand All @@ -1379,11 +1381,11 @@ private Predicate<Locality> startsInAreaA(Token token) {
int charPosition = it.getRange().getStart().getCharacter();
int areaBStartIndex =
programLayout.getSequenceLength()
+ programLayout.getIndicatorLength()
+ programLayout.getAreaALength();
+ programLayout.getIndicatorLength()
+ programLayout.getAreaALength();
return charPosition > programLayout.getSequenceLength()
&& charPosition < areaBStartIndex
&& token.getChannel() != HIDDEN;
&& charPosition < areaBStartIndex
&& token.getChannel() != HIDDEN;
};
}

Expand Down
Loading
Loading