Skip to content

Commit

Permalink
Merge pull request #3359 from 1c-syntax/fix/method-description-annota…
Browse files Browse the repository at this point in the history
…tions

Исправление поиска начала метода при наличии аннотаций
  • Loading branch information
nixel2007 authored Nov 4, 2024
2 parents 810c04a + 63afb24 commit 29128ba
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,20 @@ public ParseTree visitFunction(BSLParser.FunctionContext ctx) {
return ctx;
}

if (!declaration.annotation().isEmpty()) {
startNode = declaration.annotation().get(0).AMPERSAND();
}

MethodSymbol methodSymbol = createMethodSymbol(
startNode,
stopNode,
declaration.FUNCTION_KEYWORD().getSymbol(),
declaration.subName().getStart(),
declaration.paramList(),
true,
declaration.EXPORT_KEYWORD() != null,
getCompilerDirective(declaration.compilerDirective()),
getAnnotations(declaration.annotation()));
createAnnotations(declaration.annotation()));

methods.add(methodSymbol);

Expand All @@ -119,15 +124,20 @@ public ParseTree visitProcedure(BSLParser.ProcedureContext ctx) {
return ctx;
}

if (!declaration.annotation().isEmpty()) {
startNode = declaration.annotation().get(0).AMPERSAND();
}

MethodSymbol methodSymbol = createMethodSymbol(
startNode,
stopNode,
declaration.PROCEDURE_KEYWORD().getSymbol(),
declaration.subName().getStart(),
declaration.paramList(),
false,
declaration.EXPORT_KEYWORD() != null,
getCompilerDirective(declaration.compilerDirective()),
getAnnotations(declaration.annotation())
createAnnotations(declaration.annotation())
);

methods.add(methodSymbol);
Expand Down Expand Up @@ -182,14 +192,16 @@ private static Optional<CompilerDirectiveKind> getCompilerDirective(
private MethodSymbol createMethodSymbol(
TerminalNode startNode,
TerminalNode stopNode,
Token startOfMethod,
Token subName,
BSLParser.ParamListContext paramList,
boolean function,
boolean export,
Optional<CompilerDirectiveKind> compilerDirective,
List<Annotation> annotations
) {
Optional<MethodDescription> description = createDescription(startNode.getSymbol());
Optional<MethodDescription> description = createDescription(startOfMethod)
.or(() -> createDescription(startNode.getSymbol()));
boolean deprecated = description
.map(MethodDescription::isDeprecated)
.orElse(false);
Expand Down Expand Up @@ -236,7 +248,7 @@ private static List<ParameterDefinition> createParameters(
.range(getParameterRange(param))
.description(getParameterDescription(parameterName, description))
.build();
}).collect(Collectors.toList());
}).toList();
}

private static ParameterDefinition.DefaultValue getDefaultValue(BSLParser.ParamContext param) {
Expand Down Expand Up @@ -310,10 +322,10 @@ private static Optional<ParameterDescription> getParameterDescription(

}

private static List<Annotation> getAnnotations(List<? extends BSLParser.AnnotationContext> annotationContext) {
return annotationContext.stream()
private static List<Annotation> createAnnotations(List<? extends BSLParser.AnnotationContext> annotationContexts) {
return annotationContexts.stream()
.map(MethodSymbolComputer::createAnnotation)
.collect(Collectors.toList());
.toList();
}

private static Annotation createAnnotation(BSLParser.AnnotationContext annotation) {
Expand All @@ -334,7 +346,7 @@ private static List<AnnotationParameterDefinition> getAnnotationParameter(

return annotationParamsContext.annotationParam().stream()
.map(MethodSymbolComputer::getAnnotationParam)
.collect(Collectors.toList());
.toList();
}

private static AnnotationParameterDefinition getAnnotationParam(BSLParser.AnnotationParamContext o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -44,18 +43,30 @@ void prepare() {
var documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/MethodDescription.bsl");
var methods = documentContext.getSymbolTree().getMethods();

assertThat(methods.size()).isEqualTo(14);
assertThat(methods).hasSize(16);

methodsWithDescription = methods.stream()
.map(MethodSymbol::getDescription)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
.toList();

assertThat(methodsWithDescription.size()).isEqualTo(13);
assertThat(methodsWithDescription.size()).isEqualTo(15);
}
}

@Test
void testMethodWithAnnotationBeforeDescription() {
var method = methodsWithDescription.get(14);
assertThat(method.getDescription()).isEqualTo("// Описание процедуры");
}

@Test
void testMethodWithAnnotation() {
var method = methodsWithDescription.get(13);
assertThat(method.getDescription()).isEqualTo("// Описание процедуры");
}

@Test
void testMethod13() {
var method = methodsWithDescription.get(12);
Expand Down Expand Up @@ -431,4 +442,4 @@ void testMethod1() {
assertThat(method.getReturnedValue()).isEmpty();
assertThat(method.getLink()).isEmpty();
}
}
}
10 changes: 10 additions & 0 deletions src/test/resources/context/symbol/MethodDescription.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,13 @@
//
Функция BUG_1495(Ссылки, Знач Реквизиты, ВыбратьРазрешенные = Ложь) Экспорт
КонецФункции

// Описание процедуры
&Аннотация("Параметр")
Процедура ПроцедураСАннотацией()
КонецПроцедуры

&Аннотация("Параметр")
// Описание процедуры
Процедура ПроцедураСАннотациейПередОписанием()
КонецПроцедуры

0 comments on commit 29128ba

Please sign in to comment.