Skip to content

Commit 7ac2033

Browse files
committed
fix issue, identity with position
1 parent e10cba9 commit 7ac2033

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2013-2024 The JavaParser Team.
3+
*
4+
* This file is part of JavaParser.
5+
*
6+
* JavaParser can be used either under the terms of
7+
* a) the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
* b) the terms of the Apache License
11+
*
12+
* You should have received a copy of both licenses in LICENCE.LGPL and
13+
* LICENCE.APACHE. Please refer to those files for details.
14+
*
15+
* JavaParser is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Lesser General Public License for more details.
19+
*/
20+
21+
package com.github.javaparser;
22+
23+
import com.github.javaparser.ast.CompilationUnit;
24+
import org.junit.jupiter.api.Assertions;
25+
import org.junit.jupiter.api.Test;
26+
27+
import java.io.IOException;
28+
import java.nio.file.Paths;
29+
30+
public class JKIssue {
31+
@Test()
32+
void test() throws IOException {
33+
ParserConfiguration cfg = new ParserConfiguration();
34+
cfg.setProcessJml(true);
35+
JavaParser parser = new JavaParser(cfg);
36+
CompilationUnit cu = parser.parse(Paths.get("src/test/test_sourcecode/JKIssueDoubleContract.java"))
37+
.getResult().get();
38+
39+
var methods = cu.getPrimaryType().get().getMethods();
40+
for (var method : methods) {
41+
Assertions.assertEquals(1, method.getContracts().get().size());
42+
}
43+
}
44+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Created by jklamroth on 12/18/18.
3+
*/
4+
public class JKIssueDoubleContract {
5+
6+
//@ ensures \result == 56;
7+
private int test() {
8+
}
9+
10+
11+
//@ ensures \result == 56;
12+
private int test1() {
13+
}
14+
}

javaparser-core/src/main/java/com/github/javaparser/jml/JmlProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.github.javaparser.ast.visitor.Visitable;
2424
import org.jetbrains.annotations.Nullable;
2525
import java.util.*;
26+
import java.util.stream.IntStream;
2627

2728
/**
2829
* Here happens the JML magic. This post-processor consumes {@link JmlDoc}
@@ -143,7 +144,9 @@ public JmlDocDeclaration visit(JmlDocDeclaration n, Void arg) {
143144
setJmlTags(t);
144145
TypeDeclaration<?> parent = (TypeDeclaration<?>) n.getParentNode().get();
145146
NodeList<BodyDeclaration<?>> members = parent.getMembers();
146-
int pos = members.indexOf(n);
147+
int pos = IntStream.range(0, members.size())
148+
.filter(i -> members.get(i) == n)
149+
.findFirst().orElse(-1);
147150
assert pos >= 0;
148151
if (pos + 1 >= members.size()) {
149152
//JML Documentation is last element, therefore it can only refer to upper element.

0 commit comments

Comments
 (0)