diff --git a/enterprise/micronaut/src/org/netbeans/modules/micronaut/hints/MicronautConfigErrorProvider.java b/enterprise/micronaut/src/org/netbeans/modules/micronaut/hints/MicronautConfigErrorProvider.java index 5b870934bcfd..afefe780eecf 100644 --- a/enterprise/micronaut/src/org/netbeans/modules/micronaut/hints/MicronautConfigErrorProvider.java +++ b/enterprise/micronaut/src/org/netbeans/modules/micronaut/hints/MicronautConfigErrorProvider.java @@ -109,11 +109,9 @@ public void run(ResultIterator it) throws Exception { scan(text, scanner.scan((ParserResult) result), structure -> { int start = (int) structure.getPosition(); int end = (int) structure.getEndPosition(); - String[] startLines = text.substring(0, start).split("\n"); - String[] endLines = text.substring(0, end).split("\n"); diags.add(Diagnostic.Builder.create(() -> start, () -> end, Bundle.ERR_PropertyWithoutValue()) .setSeverity(Diagnostic.Severity.Warning) - .setCode(ERR_CODE_PREFIX + startLines.length + ',' + (startLines[startLines.length - 1].length() + 1) + '-' + endLines.length + ',' + (endLines[endLines.length - 1].length() + 1)) + .setCode(ERR_CODE_PREFIX + text.substring(0, start).split("\n").length) .build()); }); } @@ -137,7 +135,7 @@ public void run(ResultIterator it) throws Exception { int end = offset + line.length(); diags.add(Diagnostic.Builder.create(() -> start, () -> end, Bundle.ERR_PropertyWithoutValue()) .setSeverity(Diagnostic.Severity.Warning) - .setCode(ERR_CODE_PREFIX + (i + 1) + ",1-" + (i + 1) + "," + line.length() + 1) + .setCode(ERR_CODE_PREFIX + (i + 1)) .build()); } } @@ -200,26 +198,14 @@ public int getIndexVersion() { } } - private static final class ErrorConvertorImpl implements ErrorsCache.Convertor2 { + private static final class ErrorConvertorImpl implements ErrorsCache.Convertor { @Override public ErrorsCache.ErrorKind getKind(Diagnostic t) { return t.getSeverity() == Diagnostic.Severity.Error ? ErrorsCache.ErrorKind.ERROR : ErrorsCache.ErrorKind.WARNING; } @Override public int getLineNumber(Diagnostic t) { - String text = t.getCode().substring(ERR_CODE_PREFIX.length()); - int idx = text.indexOf(','); - return Integer.parseInt(text.substring(0, idx)); - } - @Override - public ErrorsCache.Range getRange(Diagnostic t) { - String text = t.getCode().substring(ERR_CODE_PREFIX.length()); - int idx1 = text.indexOf(','); - int idx2 = text.indexOf('-'); - int idx3 = text.indexOf(',', idx2); - ErrorsCache.Position start = new ErrorsCache.Position(Integer.parseInt(text.substring(0, idx1)), Integer.parseInt(text.substring(idx1 + 1, idx2))); - ErrorsCache.Position end = new ErrorsCache.Position(Integer.parseInt(text.substring(idx2 + 1, idx3)), Integer.parseInt(text.substring(idx3 + 1, text.length()))); - return new ErrorsCache.Range(start, end); + return Integer.parseInt(t.getCode().substring(ERR_CODE_PREFIX.length())); } @Override public String getMessage(Diagnostic t) { diff --git a/ide/csl.api/src/org/netbeans/modules/csl/core/TLIndexerFactory.java b/ide/csl.api/src/org/netbeans/modules/csl/core/TLIndexerFactory.java index 07514c764dc4..6d730ea65106 100644 --- a/ide/csl.api/src/org/netbeans/modules/csl/core/TLIndexerFactory.java +++ b/ide/csl.api/src/org/netbeans/modules/csl/core/TLIndexerFactory.java @@ -44,7 +44,7 @@ import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexer; import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexerFactory; import org.netbeans.modules.parsing.spi.indexing.ErrorsCache; -import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor2; +import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor; import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ErrorKind; import org.netbeans.modules.parsing.spi.indexing.Indexable; import org.netbeans.spi.tasklist.TaskScanningScope; @@ -141,7 +141,7 @@ public int getIndexVersion () { return INDEXER_VERSION; } - private static final class ErrorConvertorImpl implements Convertor2{ + private static final class ErrorConvertorImpl implements Convertor{ private final List lineStartOffsets; public ErrorConvertorImpl(List lineStartOffsets) { this.lineStartOffsets = lineStartOffsets; @@ -178,29 +178,6 @@ public int getLineNumber(SimpleError error) { return lineNumber; } @Override - public ErrorsCache.Range getRange(SimpleError error) { - int originalOffset = error.getStartPosition(); //snapshot offset - int lineNumber = 1; - int colNumber = 1; - if (originalOffset >= 0) { - int idx = Collections.binarySearch(lineStartOffsets, originalOffset); - if (idx < 0) { - // idx == (-(insertion point) - 1) -> (insertion point) == -idx - 1 - int ln = -idx - 1; - assert ln >= 1 && ln <= lineStartOffsets.size() : - "idx=" + idx + ", lineNumber=" + ln + ", lineStartOffsets.size()=" + lineStartOffsets.size(); //NOI18N - if (ln >= 1 && ln <= lineStartOffsets.size()) { - lineNumber = ln; - colNumber = originalOffset - lineStartOffsets.get(ln - 1); - } - } else { - lineNumber = idx + 1; - } - } - - return new ErrorsCache.Range(new ErrorsCache.Position(lineNumber, colNumber), null); - } - @Override public String getMessage(SimpleError error) { return error.getDisplayName(); } diff --git a/ide/parsing.indexing/apichanges.xml b/ide/parsing.indexing/apichanges.xml index 5360a56b85b3..41ed48df3ce5 100644 --- a/ide/parsing.indexing/apichanges.xml +++ b/ide/parsing.indexing/apichanges.xml @@ -87,20 +87,6 @@ is the proper place. - - - Added method to ErrorsCache to return all errors or warnings for the given file - - - - - -

- Added the getErrors() method to return errors or warnings for the given file. -

-
- -
Added method to ErrorsCache to return all files with error or warning diff --git a/ide/parsing.indexing/nbproject/project.properties b/ide/parsing.indexing/nbproject/project.properties index 7b0db0ba928e..00955b41faa0 100644 --- a/ide/parsing.indexing/nbproject/project.properties +++ b/ide/parsing.indexing/nbproject/project.properties @@ -16,7 +16,7 @@ # under the License. javac.source=1.8 javac.compilerargs=-Xlint -Xlint:-serial -spec.version.base=9.37.0 +spec.version.base=9.36.0 is.autoload=true javadoc.apichanges=${basedir}/apichanges.xml javadoc.arch=${basedir}/arch.xml diff --git a/ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java b/ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java index 90442b05c2bc..3a239519e325 100644 --- a/ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java +++ b/ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/errors/TaskCache.java @@ -45,8 +45,6 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.project.FileOwnerQuery; @@ -55,11 +53,8 @@ import org.netbeans.modules.parsing.impl.indexing.PathRegistry; import org.netbeans.modules.parsing.impl.indexing.URLCache; import org.netbeans.modules.parsing.impl.indexing.implspi.CacheFolderProvider; -import org.netbeans.modules.parsing.spi.indexing.ErrorsCache; import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor; -import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor2; import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ErrorKind; -import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ReverseConvertor; import org.netbeans.modules.parsing.spi.indexing.Indexable; import org.netbeans.spi.tasklist.Task; import org.openide.filesystems.FileObject; @@ -82,8 +77,6 @@ public class TaskCache { private static final Logger LOG = Logger.getLogger(TaskCache.class.getName()); - private static final Pattern PATTERN = Pattern.compile("(\\d*),(\\d*)(?:-(\\d*),(\\d*))?"); - static { // LOG.setLevel(Level.FINEST); } @@ -110,31 +103,17 @@ private String getTaskType( ErrorKind k ) { } return null; } - - private ReverseConvertor getTaskConvertor(FileObject file) { - return (kind, range, message) -> { - String severity = getTaskType(kind); - if (null != severity) { - return Task.create(file, severity, message, range.getStart().getLine()); - } - return null; - }; - } - + public List getErrors(FileObject file) { - return getErrors(file, getTaskConvertor(file)); - } - - public List getErrors(FileObject file, ReverseConvertor convertor) { - List result = new LinkedList<>(); + List result = new LinkedList(); - result.addAll(getErrors(file, convertor, ERR_EXT)); - result.addAll(getErrors(file, convertor, WARN_EXT)); + result.addAll(getErrors(file, ERR_EXT)); + result.addAll(getErrors(file, WARN_EXT)); return result; } - private List getErrors(FileObject file, ReverseConvertor convertor, String ext) { + private List getErrors(FileObject file, String ext) { LOG.log(Level.FINE, "getErrors, file={0}, ext={1}", new Object[] {FileUtil.getFileDisplayName(file), ext}); //NOI18N try { @@ -143,16 +122,16 @@ private List getErrors(FileObject file, ReverseConvertor convertor, St LOG.log(Level.FINE, "getErrors, error file={0}", input == null ? "null" : input.getAbsolutePath()); //NOI18N if (input == null || !input.canRead()) - return Collections.emptyList(); + return Collections.emptyList(); input.getParentFile().mkdirs(); - return loadErrors(input, convertor); + return loadErrors(input, file); } catch (IOException e) { LOG.log(Level.FINE, null, e); } - return Collections.emptyList(); + return Collections.emptyList(); } private boolean dumpErrors(File output, Iterable errors, Convertor convertor, boolean interestedInReturnValue) throws IOException { @@ -165,15 +144,7 @@ private boolean dumpErrors(File output, Iterable errors, Conver for (T err : errors) { pw.print(convertor.getKind(err).name()); pw.print(':'); //NOI18N - if (convertor instanceof Convertor2) { - ErrorsCache.Range range = ((Convertor2) convertor).getRange(err); - pw.print(String.format("%d,%d", range.getStart().getLine(), range.getStart().getColumn())); - if (range.getEnd() != null) { - pw.print(String.format("-%d,%d", range.getEnd().getLine(), range.getEnd().getColumn())); - } - } else { - pw.print(convertor.getLineNumber(err)); - } + pw.print(convertor.getLineNumber(err)); pw.print(':'); //NOI18N String description = convertor.getMessage(err); @@ -229,7 +200,6 @@ public void dumpErrors(final URL root, final Indexable i, final Iterable void dumpErrors(TransactionContext c, URL root, Indexable i, Iterabl c.rootsToRefresh.add(root); } - private List loadErrors(File input, ReverseConvertor convertor) throws IOException { - List result = new LinkedList<>(); + private List loadErrors(File input, FileObject file) throws IOException { + List result = new LinkedList(); BufferedReader pw = new BufferedReader(new InputStreamReader(new FileInputStream(input), StandardCharsets.UTF_8)); String line; @@ -307,26 +277,18 @@ private List loadErrors(File input, ReverseConvertor convertor) throws continue; } - ErrorsCache.Range range; - Matcher matcher = PATTERN.matcher(parts[1]); - if (matcher.matches()) { - ErrorsCache.Position start = new ErrorsCache.Position(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); - 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; - range = new ErrorsCache.Range(start, end); - } else { - int lineNumber = Integer.parseInt(parts[1]); - range = new ErrorsCache.Range(new ErrorsCache.Position(lineNumber, 1), null); - } - + int lineNumber = Integer.parseInt(parts[1]); String message = parts[2]; - message = message.replace("\\d", ":") //NOI18N - .replace("\\n", "\n") //NOI18N - .replace("\\\\", "\\"); //NOI18N + message = message.replaceAll("\\\\d", ":"); //NOI18N + message = message.replaceAll("\\\\n", " "); //NOI18N + message = message.replaceAll("\\\\\\\\", "\\\\"); //NOI18N - T item = convertor.get(kind, range, message); - if (null != item) { - result.add(item); + String severity = getTaskType(kind); + + if (null != severity) { + Task err = Task.create(file, severity, message, lineNumber); + result.add(err); } } @@ -389,12 +351,12 @@ private List getAllFilesWithRecord(URL root, boolean onlyErrors) throws IOE public List getAllFilesInError(URL root) throws IOException { return getAllFilesWithRecord(root, true); } - + public boolean isInError(FileObject file, boolean recursive) { LOG.log(Level.FINE, "file={0}, recursive={1}", new Object[] {file, Boolean.valueOf(recursive)}); //NOI18N if (file.isData()) { - return !getErrors(file, getTaskConvertor(file), ERR_EXT).isEmpty(); + return !getErrors(file, ERR_EXT).isEmpty(); } else { try { ClassPath cp = Utilities.getSourceClassPathFor (file); diff --git a/ide/parsing.indexing/src/org/netbeans/modules/parsing/spi/indexing/ErrorsCache.java b/ide/parsing.indexing/src/org/netbeans/modules/parsing/spi/indexing/ErrorsCache.java index a6c896ef7605..b0730a588b84 100644 --- a/ide/parsing.indexing/src/org/netbeans/modules/parsing/spi/indexing/ErrorsCache.java +++ b/ide/parsing.indexing/src/org/netbeans/modules/parsing/spi/indexing/ErrorsCache.java @@ -23,7 +23,6 @@ import java.net.URL; import java.util.Collection; import java.util.Collections; -import java.util.List; import org.netbeans.modules.parsing.impl.indexing.errors.TaskCache; import org.openide.filesystems.FileObject; @@ -75,17 +74,6 @@ public static Collection getAllFilesWithRecord(URL root) throws I return Collections.unmodifiableCollection(TaskCache.getDefault().getAllFilesWithRecord(root)); } - /**Return all errors or warnings for the given file - * - * @param file file for which the errors are being retrieved - * @param convertor constructor of {@code T} instances from error description properties - * @return errors or warnings - * @since 9.37 - */ - public static List getErrors(FileObject file, ReverseConvertor convertor) throws IOException { - return Collections.unmodifiableList(TaskCache.getDefault().getErrors(file, convertor)); - } - /**Getter for properties of the given error description. */ public static interface Convertor { @@ -94,62 +82,6 @@ public static interface Convertor { public String getMessage(T t); } - /**Position in a text expressed as 1-based line and character offset. - * @since 9.37 - */ - public static final class Position { - private int line; - private int column; - - public Position(int line, int column) { - this.line = line; - this.column = column; - } - - public int getLine() { - return line; - } - - public int getColumn() { - return column; - } - } - - /**Range in a text expressed as (1-based) start and end positions. - * @since 9.37 - */ - public static final class Range { - private Position start; - private Position end; - - public Range(Position start, Position end) { - this.start = start; - this.end = end; - } - - public Position getStart() { - return start; - } - - public Position getEnd() { - return end; - } - } - - /**Getter for properties of the given error description including the range. - * @since 9.37 - */ - public static interface Convertor2 extends Convertor { - public Range getRange(T t); - } - - /**Constructor of error description from the properties. - * @since 9.37 - */ - public static interface ReverseConvertor { - public T get(ErrorKind kind, Range range, String message); - } - public static enum ErrorKind { /**Error, that should be used to show error badge in the projects tab. */ diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ErrorsNotifier.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ErrorsNotifier.java index 398c4ef8abc1..c79de141f6e4 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ErrorsNotifier.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ErrorsNotifier.java @@ -18,29 +18,22 @@ */ package org.netbeans.modules.java.lsp.server.protocol; -import java.io.IOException; -import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.WeakHashMap; import java.util.concurrent.Future; -import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.DiagnosticSeverity; -import org.eclipse.lsp4j.Position; -import org.eclipse.lsp4j.Range; +import java.util.stream.Collectors; +import org.netbeans.api.lsp.Diagnostic; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.modules.java.lsp.server.LspServerState; -import org.netbeans.modules.java.lsp.server.URITranslator; import org.netbeans.modules.parsing.spi.indexing.ErrorsCache; -import org.openide.filesystems.FileObject; import org.openide.filesystems.URLMapper; import org.openide.util.Exceptions; +import org.openide.util.lookup.Lookups; /** * @@ -49,7 +42,6 @@ public final class ErrorsNotifier { private final Map> servers = new WeakHashMap<>(); - private final Map> lastFilesWithErrors = new HashMap<>(); public void connect(LspServerState server, Future future) { synchronized (servers) { @@ -71,52 +63,19 @@ public void notifyErrors(URL root) { servers.keySet().removeAll(toRemove); } try { - Collection last = lastFilesWithErrors.getOrDefault(root, Collections.emptyList()); Collection filesWithErrors = ErrorsCache.getAllFilesWithRecord(root); - if (filesWithErrors.isEmpty()) { - lastFilesWithErrors.remove(root); - } else { - lastFilesWithErrors.put(root, new ArrayList<>(filesWithErrors)); - last.removeAll(filesWithErrors); - } - if (!filesWithErrors.isEmpty() || !last.isEmpty()) { + if (!filesWithErrors.isEmpty()) { Project project = FileOwnerQuery.getOwner(root.toURI()); - boolean inOpenedProject = false; for (LspServerState server : toProcess) { for (Project p : server.openedProjects().getNow(new Project[0])) { if (p == project) { - inOpenedProject = true; - for (URL fileWithError : filesWithErrors) { - FileObject fo = URLMapper.findFileObject(fileWithError); - if (fo != null) { - List diags = ErrorsCache.getErrors(fo, (kind, range, message) -> { - Position start = new Position(range.getStart().getLine() - 1, range.getStart().getColumn() - 1); - Position end = range.getEnd() != null ? new Position(range.getEnd().getLine() - 1, range.getEnd().getColumn() - 1) : start; - Diagnostic d = new Diagnostic(new Range(start, end), message); - d.setSeverity(kind == ErrorsCache.ErrorKind.WARNING ? DiagnosticSeverity.Warning : DiagnosticSeverity.Error); - return d; - }); - if (!diags.isEmpty()) { - String lspUri = URITranslator.getDefault().uriToLSP(fileWithError.toURI().toString()); - ((TextDocumentServiceImpl) server.getTextDocumentService()).publishDiagnostics(lspUri, diags); - } - } - } - for (URL fileWithError : last) { - FileObject fo = URLMapper.findFileObject(fileWithError); - if (fo != null) { - String lspUri = URITranslator.getDefault().uriToLSP(fileWithError.toURI().toString()); - ((TextDocumentServiceImpl) server.getTextDocumentService()).publishDiagnostics(lspUri, Collections.emptyList()); - } - } + Diagnostic.ReporterControl control = Diagnostic.findReporterControl(Lookups.fixed(server), null); + control.diagnosticChanged(filesWithErrors.stream().map(url -> URLMapper.findFileObject(url)).filter(fo -> fo != null).collect(Collectors.toList()), null); } } } - if (!inOpenedProject) { - lastFilesWithErrors.remove(root); - } } - } catch (IOException | URISyntaxException ex) { + } catch (Exception ex) { Exceptions.printStackTrace(ex); } } diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java index 74dbb155a7a9..09f9e6c8cbc3 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java @@ -2318,7 +2318,7 @@ public org.netbeans.api.lsp.Diagnostic.ReporterControl createReporterControl() { * @param uri file URI * @param mergedDiags the diagnostics */ - public void publishDiagnostics(String uri, List mergedDiags) { + private void publishDiagnostics(String uri, List mergedDiags) { knownFiles.put(uri, Instant.now()); client.publishDiagnostics(new PublishDiagnosticsParams(uri, mergedDiags)); } diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java index be50b041d3d9..b18c7850daff 100644 --- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java +++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java @@ -1733,7 +1733,6 @@ public void testFixImports() throws Exception { w.write(code); } List[] diags = new List[1]; - AtomicBoolean checkForDiags = new AtomicBoolean(false); CountDownLatch indexingComplete = new CountDownLatch(1); Launcher serverLauncher = createClientLauncherWithLogging(new TestCodeLanguageClient() { @Override @@ -1745,11 +1744,9 @@ public void showStatusBarMessage(ShowStatusMessageParams params) { @Override public void publishDiagnostics(PublishDiagnosticsParams params) { - if (checkForDiags.get()) { - synchronized (diags) { - diags[0] = params.getDiagnostics(); - diags.notifyAll(); - } + synchronized (diags) { + diags[0] = params.getDiagnostics(); + diags.notifyAll(); } } }, client.getInputStream(), client.getOutputStream()); @@ -1762,7 +1759,6 @@ public void publishDiagnostics(PublishDiagnosticsParams params) { InitializeResult result = server.initialize(initParams).get(); indexingComplete.await(); String uri = toURI(src); - checkForDiags.set(true); server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, "java", 0, code))); Diagnostic unresolvable = assertDiags(diags, "Error:2:8-2:12").get(0); diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java index 0e5560824b6f..52751b70485a 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java @@ -59,11 +59,8 @@ import java.util.logging.Level; import java.util.regex.Pattern; import java.util.stream.Collectors; - -import com.sun.source.tree.CompilationUnitTree; -import com.sun.source.tree.LineMap; - import javax.lang.model.SourceVersion; + import javax.lang.model.element.ElementKind; import javax.lang.model.element.ModuleElement; import javax.lang.model.element.TypeElement; @@ -71,8 +68,8 @@ import javax.tools.Diagnostic; import javax.tools.Diagnostic.Kind; import javax.tools.JavaFileObject; - import org.netbeans.api.annotations.common.CheckForNull; + import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.annotations.common.NullAllowed; import org.netbeans.api.editor.mimelookup.MimeRegistration; @@ -109,7 +106,7 @@ import org.netbeans.modules.parsing.spi.indexing.CustomIndexer; import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory; import org.netbeans.modules.parsing.spi.indexing.ErrorsCache; -import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor2; +import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Convertor; import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ErrorKind; import org.netbeans.modules.parsing.spi.indexing.Indexable; import org.netbeans.spi.java.classpath.support.ClassPathSupport; @@ -805,10 +802,10 @@ public static void addAptGenerated( } } - public static void setErrors(Context context, CompileTuple active, CompilationUnitTree cut, DiagnosticListenerImpl errors) { + public static void setErrors(Context context, CompileTuple active, DiagnosticListenerImpl errors) { if (!active.virtual) { Iterable> filteredErrorsList = Iterators.filter(errors.getDiagnostics(active.jfo), new FilterOutJDK7AndLaterWarnings()); - ErrorsCache.setErrors(context.getRootURI(), active.indexable, filteredErrorsList, new ErrorConvertorImpl(active.aptGenerated ? ErrorKind.ERROR_NO_BADGE : ErrorKind.ERROR, cut.getLineMap())); + ErrorsCache.setErrors(context.getRootURI(), active.indexable, filteredErrorsList, active.aptGenerated ? ERROR_CONVERTOR_NO_BADGE : ERROR_CONVERTOR); } } @@ -1301,15 +1298,13 @@ public CompileTuple (final PrefetchableJavaFileObject jfo, final Indexable index } } - private static final Convertor2> ERROR_CONVERTOR = new ErrorConvertorImpl(ErrorKind.ERROR, null); - private static final Convertor2> ERROR_CONVERTOR_NO_BADGE = new ErrorConvertorImpl(ErrorKind.ERROR_NO_BADGE, null); + private static final Convertor> ERROR_CONVERTOR = new ErrorConvertorImpl(ErrorKind.ERROR); + private static final Convertor> ERROR_CONVERTOR_NO_BADGE = new ErrorConvertorImpl(ErrorKind.ERROR_NO_BADGE); - private static final class ErrorConvertorImpl implements Convertor2> { + private static final class ErrorConvertorImpl implements Convertor> { private final ErrorKind errorKind; - private final LineMap lm; - public ErrorConvertorImpl(ErrorKind errorKind, LineMap lm) { + public ErrorConvertorImpl(ErrorKind errorKind) { this.errorKind = errorKind; - this.lm = lm; } @Override public ErrorKind getKind(Diagnostic t) { @@ -1320,22 +1315,6 @@ public int getLineNumber(Diagnostic t) { return (int) t.getLineNumber(); } @Override - public ErrorsCache.Range getRange(Diagnostic t) { - if (lm == null) { - return new ErrorsCache.Range(new ErrorsCache.Position((int) t.getLineNumber(), (int) t.getColumnNumber()), null); - } - ErrorsCache.Position endPos; - if (t.getEndPosition() == (-1)) { - endPos = null; - } else { - endPos = new ErrorsCache.Position((int) lm.getLineNumber(t.getEndPosition()), (int) lm.getColumnNumber(t.getEndPosition())); - } - return new ErrorsCache.Range( - new ErrorsCache.Position((int) lm.getLineNumber(t.getStartPosition()), (int) lm.getColumnNumber(t.getStartPosition())), - endPos - ); - } - @Override public String getMessage(Diagnostic t) { return t.getMessage(null); } diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java index 4a820e9c5075..9058addefbe8 100644 --- a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java +++ b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java @@ -340,7 +340,7 @@ protected ParsingOutput compile( } ExecutableFilesIndex.DEFAULT.setMainClass(context.getRoot().toURL(), active.indexable.getURL(), main[0]); dropMethodsAndErrors(jt.getContext(), unit.getKey(), dc); - JavaCustomIndexer.setErrors(context, active, unit.getKey(), dc); + JavaCustomIndexer.setErrors(context, active, dc); } if (context.isCancelled()) { return null; diff --git a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java index 482ddf14a061..bcd1c07c8701 100644 --- a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java +++ b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java @@ -27,7 +27,6 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @@ -54,16 +53,11 @@ import org.netbeans.modules.classfile.ClassFile; import org.netbeans.modules.java.source.indexing.CompileWorker.ParsingOutput; import org.netbeans.modules.java.source.indexing.JavaCustomIndexer.CompileTuple; -import org.netbeans.modules.parsing.impl.indexing.errors.TaskCache; import org.netbeans.modules.parsing.spi.indexing.Context; -import org.netbeans.modules.parsing.spi.indexing.ErrorsCache; -import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.ErrorKind; -import org.netbeans.modules.parsing.spi.indexing.ErrorsCache.Range; import org.netbeans.spi.java.classpath.support.ClassPathSupport; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; -import org.openide.util.Pair; /** * @@ -2437,54 +2431,6 @@ public void testRecord2() throws Exception { assertEquals(expected, file2Fixed); } - public void testBrokenWarningEndPos() throws Exception { //NETBEANS-7981 - setCompilerOptions(Arrays.asList("-Xlint:deprecation")); - - String code = """ - package test; - public class Test { - void t() { - new D() {}; - } - } - class D { - @Deprecated - D() {} - } - """; - ParsingOutput result = runIndexing(Arrays.asList(compileTuple("test/Test.java", - code)), - Arrays.asList()); - - assertFalse(result.lowMemory); - assertTrue(result.success); - - Set createdFiles = new HashSet(); - - for (File created : result.createdFiles) { - createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath()); - } - - assertEquals(new HashSet(Arrays.asList("cache/s1/java/15/classes/test/Test.sig", - "cache/s1/java/15/classes/test/Test$1.sig", - "cache/s1/java/15/classes/test/D.sig")), - createdFiles); - record Data(ErrorKind kind, Pair, Pair> range) {} - List errors = TaskCache.getDefault().getErrors(getRoot().getFileObject("test/Test.java"), new ErrorsCache.ReverseConvertor() { - @Override - public Data get(ErrorKind kind, Range range, String message) { - return new Data(kind, Pair.of(Pair.of(range.getStart().getLine(), - range.getStart().getColumn()), - range.getEnd() != null ? Pair.of(range.getEnd().getLine(), - range.getEnd().getColumn()) - : null)); - } - }); - assertEquals(List.of(new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 9), Pair.of(4, 19))), - new Data(ErrorKind.WARNING, Pair.of(Pair.of(4, 17), null))), - errors); - } - public static void noop() {} @Override