Skip to content

Commit 6308a54

Browse files
authored
Merge pull request #8002 from apache/delivery
Sync delivery to release240 for 24-rc5
2 parents 212f4c3 + ffe785c commit 6308a54

File tree

12 files changed

+50
-327
lines changed

12 files changed

+50
-327
lines changed

enterprise/micronaut/src/org/netbeans/modules/micronaut/hints/MicronautConfigErrorProvider.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,9 @@ public void run(ResultIterator it) throws Exception {
109109
scan(text, scanner.scan((ParserResult) result), structure -> {
110110
int start = (int) structure.getPosition();
111111
int end = (int) structure.getEndPosition();
112-
String[] startLines = text.substring(0, start).split("\n");
113-
String[] endLines = text.substring(0, end).split("\n");
114112
diags.add(Diagnostic.Builder.create(() -> start, () -> end, Bundle.ERR_PropertyWithoutValue())
115113
.setSeverity(Diagnostic.Severity.Warning)
116-
.setCode(ERR_CODE_PREFIX + startLines.length + ',' + (startLines[startLines.length - 1].length() + 1) + '-' + endLines.length + ',' + (endLines[endLines.length - 1].length() + 1))
114+
.setCode(ERR_CODE_PREFIX + text.substring(0, start).split("\n").length)
117115
.build());
118116
});
119117
}
@@ -137,7 +135,7 @@ public void run(ResultIterator it) throws Exception {
137135
int end = offset + line.length();
138136
diags.add(Diagnostic.Builder.create(() -> start, () -> end, Bundle.ERR_PropertyWithoutValue())
139137
.setSeverity(Diagnostic.Severity.Warning)
140-
.setCode(ERR_CODE_PREFIX + (i + 1) + ",1-" + (i + 1) + "," + line.length() + 1)
138+
.setCode(ERR_CODE_PREFIX + (i + 1))
141139
.build());
142140
}
143141
}
@@ -200,26 +198,14 @@ public int getIndexVersion() {
200198
}
201199
}
202200

203-
private static final class ErrorConvertorImpl implements ErrorsCache.Convertor2<Diagnostic> {
201+
private static final class ErrorConvertorImpl implements ErrorsCache.Convertor<Diagnostic> {
204202
@Override
205203
public ErrorsCache.ErrorKind getKind(Diagnostic t) {
206204
return t.getSeverity() == Diagnostic.Severity.Error ? ErrorsCache.ErrorKind.ERROR : ErrorsCache.ErrorKind.WARNING;
207205
}
208206
@Override
209207
public int getLineNumber(Diagnostic t) {
210-
String text = t.getCode().substring(ERR_CODE_PREFIX.length());
211-
int idx = text.indexOf(',');
212-
return Integer.parseInt(text.substring(0, idx));
213-
}
214-
@Override
215-
public ErrorsCache.Range getRange(Diagnostic t) {
216-
String text = t.getCode().substring(ERR_CODE_PREFIX.length());
217-
int idx1 = text.indexOf(',');
218-
int idx2 = text.indexOf('-');
219-
int idx3 = text.indexOf(',', idx2);
220-
ErrorsCache.Position start = new ErrorsCache.Position(Integer.parseInt(text.substring(0, idx1)), Integer.parseInt(text.substring(idx1 + 1, idx2)));
221-
ErrorsCache.Position end = new ErrorsCache.Position(Integer.parseInt(text.substring(idx2 + 1, idx3)), Integer.parseInt(text.substring(idx3 + 1, text.length())));
222-
return new ErrorsCache.Range(start, end);
208+
return Integer.parseInt(t.getCode().substring(ERR_CODE_PREFIX.length()));
223209
}
224210
@Override
225211
public String getMessage(Diagnostic t) {

ide/csl.api/src/org/netbeans/modules/csl/core/TLIndexerFactory.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexer;
4545
import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexerFactory;
4646
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache;
47-
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor2;
47+
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor;
4848
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ErrorKind;
4949
import org.netbeans.modules.parsing.spi.indexing.Indexable;
5050
import org.netbeans.spi.tasklist.TaskScanningScope;
@@ -141,7 +141,7 @@ public int getIndexVersion () {
141141
return INDEXER_VERSION;
142142
}
143143

144-
private static final class ErrorConvertorImpl implements Convertor2<SimpleError>{
144+
private static final class ErrorConvertorImpl implements Convertor<SimpleError>{
145145
private final List<Integer> lineStartOffsets;
146146
public ErrorConvertorImpl(List<Integer> lineStartOffsets) {
147147
this.lineStartOffsets = lineStartOffsets;
@@ -178,29 +178,6 @@ public int getLineNumber(SimpleError error) {
178178
return lineNumber;
179179
}
180180
@Override
181-
public ErrorsCache.Range getRange(SimpleError error) {
182-
int originalOffset = error.getStartPosition(); //snapshot offset
183-
int lineNumber = 1;
184-
int colNumber = 1;
185-
if (originalOffset >= 0) {
186-
int idx = Collections.binarySearch(lineStartOffsets, originalOffset);
187-
if (idx < 0) {
188-
// idx == (-(insertion point) - 1) -> (insertion point) == -idx - 1
189-
int ln = -idx - 1;
190-
assert ln >= 1 && ln <= lineStartOffsets.size() :
191-
"idx=" + idx + ", lineNumber=" + ln + ", lineStartOffsets.size()=" + lineStartOffsets.size(); //NOI18N
192-
if (ln >= 1 && ln <= lineStartOffsets.size()) {
193-
lineNumber = ln;
194-
colNumber = originalOffset - lineStartOffsets.get(ln - 1);
195-
}
196-
} else {
197-
lineNumber = idx + 1;
198-
}
199-
}
200-
201-
return new ErrorsCache.Range(new ErrorsCache.Position(lineNumber, colNumber), null);
202-
}
203-
@Override
204181
public String getMessage(SimpleError error) {
205182
return error.getDisplayName();
206183
}

ide/parsing.indexing/apichanges.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,6 @@ is the proper place.
8787
<!-- ACTUAL CHANGES BEGIN HERE: -->
8888

8989
<changes>
90-
<change id="ErrorsCache.getErrors">
91-
<api name="IndexingAPI"/>
92-
<summary>Added method to ErrorsCache to return all errors or warnings for the given file</summary>
93-
<version major="9" minor="37"/>
94-
<date day="6" month="9" year="2024"/>
95-
<author login="dbalek"/>
96-
<compatibility source="compatible" binary="compatible" semantic="compatible" addition="yes"/>
97-
<description>
98-
<p>
99-
Added the <a href="@TOP@/org/netbeans/modules/parsing/spi/indexing/ErrorsCache.html#getErrors-org.openide.filesystems.FileObject-org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ReverseConvertor-">getErrors()</a> method to return errors or warnings for the given file.
100-
</p>
101-
</description>
102-
<class package="org.netbeans.modules.parsing.spi.indexing" name="ErrorsCache"/>
103-
</change>
10490
<change id="ErrorsCache.getAllFilesWithRecord">
10591
<api name="IndexingAPI"/>
10692
<summary>Added method to ErrorsCache to return all files with error or warning</summary>

ide/parsing.indexing/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717
javac.source=1.8
1818
javac.compilerargs=-Xlint -Xlint:-serial
19-
spec.version.base=9.37.0
19+
spec.version.base=9.36.0
2020
is.autoload=true
2121
javadoc.apichanges=${basedir}/apichanges.xml
2222
javadoc.arch=${basedir}/arch.xml

ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
import java.util.Set;
4646
import java.util.logging.Level;
4747
import java.util.logging.Logger;
48-
import java.util.regex.Matcher;
49-
import java.util.regex.Pattern;
5048
import org.netbeans.api.annotations.common.NonNull;
5149
import org.netbeans.api.java.classpath.ClassPath;
5250
import org.netbeans.api.project.FileOwnerQuery;
@@ -55,11 +53,8 @@
5553
import org.netbeans.modules.parsing.impl.indexing.PathRegistry;
5654
import org.netbeans.modules.parsing.impl.indexing.URLCache;
5755
import org.netbeans.modules.parsing.impl.indexing.implspi.CacheFolderProvider;
58-
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache;
5956
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor;
60-
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor2;
6157
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ErrorKind;
62-
import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ReverseConvertor;
6358
import org.netbeans.modules.parsing.spi.indexing.Indexable;
6459
import org.netbeans.spi.tasklist.Task;
6560
import org.openide.filesystems.FileObject;
@@ -82,8 +77,6 @@ public class TaskCache {
8277

8378
private static final Logger LOG = Logger.getLogger(TaskCache.class.getName());
8479

85-
private static final Pattern PATTERN = Pattern.compile("(\\d*),(\\d*)(?:-(\\d*),(\\d*))?");
86-
8780
static {
8881
// LOG.setLevel(Level.FINEST);
8982
}
@@ -110,31 +103,17 @@ private String getTaskType( ErrorKind k ) {
110103
}
111104
return null;
112105
}
113-
114-
private ReverseConvertor<Task> getTaskConvertor(FileObject file) {
115-
return (kind, range, message) -> {
116-
String severity = getTaskType(kind);
117-
if (null != severity) {
118-
return Task.create(file, severity, message, range.getStart().getLine());
119-
}
120-
return null;
121-
};
122-
}
123-
106+
124107
public List<Task> getErrors(FileObject file) {
125-
return getErrors(file, getTaskConvertor(file));
126-
}
127-
128-
public <T> List<T> getErrors(FileObject file, ReverseConvertor<T> convertor) {
129-
List<T> result = new LinkedList<>();
108+
List<Task> result = new LinkedList<Task>();
130109

131-
result.addAll(getErrors(file, convertor, ERR_EXT));
132-
result.addAll(getErrors(file, convertor, WARN_EXT));
110+
result.addAll(getErrors(file, ERR_EXT));
111+
result.addAll(getErrors(file, WARN_EXT));
133112

134113
return result;
135114
}
136115

137-
private <T> List<T> getErrors(FileObject file, ReverseConvertor<T> convertor, String ext) {
116+
private List<Task> getErrors(FileObject file, String ext) {
138117
LOG.log(Level.FINE, "getErrors, file={0}, ext={1}", new Object[] {FileUtil.getFileDisplayName(file), ext}); //NOI18N
139118

140119
try {
@@ -143,16 +122,16 @@ private <T> List<T> getErrors(FileObject file, ReverseConvertor<T> convertor, St
143122
LOG.log(Level.FINE, "getErrors, error file={0}", input == null ? "null" : input.getAbsolutePath()); //NOI18N
144123

145124
if (input == null || !input.canRead())
146-
return Collections.emptyList();
125+
return Collections.<Task>emptyList();
147126

148127
input.getParentFile().mkdirs();
149128

150-
return loadErrors(input, convertor);
129+
return loadErrors(input, file);
151130
} catch (IOException e) {
152131
LOG.log(Level.FINE, null, e);
153132
}
154133

155-
return Collections.emptyList();
134+
return Collections.<Task>emptyList();
156135
}
157136

158137
private <T> boolean dumpErrors(File output, Iterable<? extends T> errors, Convertor<T> convertor, boolean interestedInReturnValue) throws IOException {
@@ -165,15 +144,7 @@ private <T> boolean dumpErrors(File output, Iterable<? extends T> errors, Conver
165144
for (T err : errors) {
166145
pw.print(convertor.getKind(err).name());
167146
pw.print(':'); //NOI18N
168-
if (convertor instanceof Convertor2) {
169-
ErrorsCache.Range range = ((Convertor2<T>) convertor).getRange(err);
170-
pw.print(String.format("%d,%d", range.getStart().getLine(), range.getStart().getColumn()));
171-
if (range.getEnd() != null) {
172-
pw.print(String.format("-%d,%d", range.getEnd().getLine(), range.getEnd().getColumn()));
173-
}
174-
} else {
175-
pw.print(convertor.getLineNumber(err));
176-
}
147+
pw.print(convertor.getLineNumber(err));
177148
pw.print(':'); //NOI18N
178149

179150
String description = convertor.getMessage(err);
@@ -229,7 +200,6 @@ public <T> void dumpErrors(final URL root, final Indexable i, final Iterable<? e
229200
}
230201
});
231202
} catch (IOException ex) {
232-
Exceptions.attachMessage(ex, "can't dump errors for: " + String.valueOf(i));
233203
Exceptions.printStackTrace(ex);
234204
}
235205
}
@@ -285,8 +255,8 @@ private <T> void dumpErrors(TransactionContext c, URL root, Indexable i, Iterabl
285255
c.rootsToRefresh.add(root);
286256
}
287257

288-
private <T> List<T> loadErrors(File input, ReverseConvertor<T> convertor) throws IOException {
289-
List<T> result = new LinkedList<>();
258+
private List<Task> loadErrors(File input, FileObject file) throws IOException {
259+
List<Task> result = new LinkedList<Task>();
290260
BufferedReader pw = new BufferedReader(new InputStreamReader(new FileInputStream(input), StandardCharsets.UTF_8));
291261
String line;
292262

@@ -307,26 +277,18 @@ private <T> List<T> loadErrors(File input, ReverseConvertor<T> convertor) throws
307277
continue;
308278
}
309279

310-
ErrorsCache.Range range;
311-
Matcher matcher = PATTERN.matcher(parts[1]);
312-
if (matcher.matches()) {
313-
ErrorsCache.Position start = new ErrorsCache.Position(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)));
314-
ErrorsCache.Position end = matcher.group(3) != null && matcher.group(4) != null ? new ErrorsCache.Position(Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(4))) : null;
315-
range = new ErrorsCache.Range(start, end);
316-
} else {
317-
int lineNumber = Integer.parseInt(parts[1]);
318-
range = new ErrorsCache.Range(new ErrorsCache.Position(lineNumber, 1), null);
319-
}
320-
280+
int lineNumber = Integer.parseInt(parts[1]);
321281
String message = parts[2];
322282

323-
message = message.replace("\\d", ":") //NOI18N
324-
.replace("\\n", "\n") //NOI18N
325-
.replace("\\\\", "\\"); //NOI18N
283+
message = message.replaceAll("\\\\d", ":"); //NOI18N
284+
message = message.replaceAll("\\\\n", " "); //NOI18N
285+
message = message.replaceAll("\\\\\\\\", "\\\\"); //NOI18N
326286

327-
T item = convertor.get(kind, range, message);
328-
if (null != item) {
329-
result.add(item);
287+
String severity = getTaskType(kind);
288+
289+
if (null != severity) {
290+
Task err = Task.create(file, severity, message, lineNumber);
291+
result.add(err);
330292
}
331293
}
332294

@@ -389,12 +351,12 @@ private List<URL> getAllFilesWithRecord(URL root, boolean onlyErrors) throws IOE
389351
public List<URL> getAllFilesInError(URL root) throws IOException {
390352
return getAllFilesWithRecord(root, true);
391353
}
392-
354+
393355
public boolean isInError(FileObject file, boolean recursive) {
394356
LOG.log(Level.FINE, "file={0}, recursive={1}", new Object[] {file, Boolean.valueOf(recursive)}); //NOI18N
395357

396358
if (file.isData()) {
397-
return !getErrors(file, getTaskConvertor(file), ERR_EXT).isEmpty();
359+
return !getErrors(file, ERR_EXT).isEmpty();
398360
} else {
399361
try {
400362
ClassPath cp = Utilities.getSourceClassPathFor (file);

ide/parsing.indexing/src/org/netbeans/modules/parsing/spi/indexing/ErrorsCache.java

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.net.URL;
2424
import java.util.Collection;
2525
import java.util.Collections;
26-
import java.util.List;
2726
import org.netbeans.modules.parsing.impl.indexing.errors.TaskCache;
2827
import org.openide.filesystems.FileObject;
2928

@@ -75,17 +74,6 @@ public static Collection<? extends URL> getAllFilesWithRecord(URL root) throws I
7574
return Collections.unmodifiableCollection(TaskCache.getDefault().getAllFilesWithRecord(root));
7675
}
7776

78-
/**Return all errors or warnings for the given file
79-
*
80-
* @param file file for which the errors are being retrieved
81-
* @param convertor constructor of {@code T} instances from error description properties
82-
* @return errors or warnings
83-
* @since 9.37
84-
*/
85-
public static <T> List<T> getErrors(FileObject file, ReverseConvertor<T> convertor) throws IOException {
86-
return Collections.unmodifiableList(TaskCache.getDefault().getErrors(file, convertor));
87-
}
88-
8977
/**Getter for properties of the given error description.
9078
*/
9179
public static interface Convertor<T> {
@@ -94,62 +82,6 @@ public static interface Convertor<T> {
9482
public String getMessage(T t);
9583
}
9684

97-
/**Position in a text expressed as 1-based line and character offset.
98-
* @since 9.37
99-
*/
100-
public static final class Position {
101-
private int line;
102-
private int column;
103-
104-
public Position(int line, int column) {
105-
this.line = line;
106-
this.column = column;
107-
}
108-
109-
public int getLine() {
110-
return line;
111-
}
112-
113-
public int getColumn() {
114-
return column;
115-
}
116-
}
117-
118-
/**Range in a text expressed as (1-based) start and end positions.
119-
* @since 9.37
120-
*/
121-
public static final class Range {
122-
private Position start;
123-
private Position end;
124-
125-
public Range(Position start, Position end) {
126-
this.start = start;
127-
this.end = end;
128-
}
129-
130-
public Position getStart() {
131-
return start;
132-
}
133-
134-
public Position getEnd() {
135-
return end;
136-
}
137-
}
138-
139-
/**Getter for properties of the given error description including the range.
140-
* @since 9.37
141-
*/
142-
public static interface Convertor2<T> extends Convertor<T> {
143-
public Range getRange(T t);
144-
}
145-
146-
/**Constructor of error description from the properties.
147-
* @since 9.37
148-
*/
149-
public static interface ReverseConvertor<T> {
150-
public T get(ErrorKind kind, Range range, String message);
151-
}
152-
15385
public static enum ErrorKind {
15486
/**Error, that should be used to show error badge in the projects tab.
15587
*/

0 commit comments

Comments
 (0)