Skip to content

Commit bf398f3

Browse files
authored
make the hasAnnotation check more precise (#4547)
fixes #4524 fixes #4546
1 parent c1b9c3d commit bf398f3

File tree

57 files changed

+167
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+167
-121
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerFactory.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2018, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.analysis;
@@ -64,6 +64,10 @@ public abstract class AnalyzerFactory {
6464
* The genre for files recognized by this kind of analyzer.
6565
*/
6666
protected AbstractAnalyzer.Genre genre;
67+
/**
68+
* Whether the files can be annotated.
69+
*/
70+
protected boolean hasAnnotations;
6771

6872
protected AnalyzerFactory(FileAnalyzerFactory.Matcher matcher, String contentType) {
6973
cachedAnalyzer = new ThreadLocal<>();
@@ -146,12 +150,16 @@ public final AbstractAnalyzer.Genre getGenre() {
146150
}
147151

148152
/**
149-
* The user friendly name of this analyzer.
153+
* The user-friendly name of this analyzer.
150154
*
151155
* @return a genre
152156
*/
153157
public abstract String getName();
154158

159+
public boolean hasAnnotations() {
160+
return hasAnnotations;
161+
}
162+
155163
public abstract AbstractAnalyzer getAnalyzer();
156164

157165
public abstract void returnAnalyzer();

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ public class AnalyzerGuru {
237237
* Maps from {@link FileAnalyzer#getFileTypeName()} to
238238
* {@link FileAnalyzerFactory}.
239239
*/
240-
private static final Map<String, AnalyzerFactory> FILETYPE_FACTORIES =
241-
new HashMap<>();
240+
private static final Map<String, AnalyzerFactory> FILETYPE_FACTORIES = new HashMap<>();
242241

243242
/**
244243
* Maps from {@link FileAnalyzer#getFileTypeName()} to
@@ -771,6 +770,7 @@ public static AbstractAnalyzer.Genre getGenre(AnalyzerFactory factory) {
771770
* @param fileTypeName a defined instance
772771
* @return a defined instance or {@code null}
773772
*/
773+
@Nullable
774774
public static AnalyzerFactory findByFileTypeName(String fileTypeName) {
775775
return FILETYPE_FACTORIES.get(fileTypeName);
776776
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/FileAnalyzerFactory.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2021, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.analysis;
@@ -34,14 +34,14 @@
3434
*/
3535
public class FileAnalyzerFactory extends AnalyzerFactory {
3636

37-
/** The user friendly name of this analyzer. */
37+
/** The user-friendly name of this analyzer. */
3838
private final String name;
3939

4040
/**
4141
* Create an instance of {@code FileAnalyzerFactory}.
4242
*/
4343
FileAnalyzerFactory() {
44-
this(null, null, null, null, null, null, null, null);
44+
this(null, null, null, null, null, null, null, null, false);
4545
}
4646

4747
/**
@@ -56,19 +56,21 @@ public class FileAnalyzerFactory extends AnalyzerFactory {
5656
* @param contentType content type for this analyzer (possibly {@code null})
5757
* @param genre the genre for this analyzer (if {@code null}, {@code
5858
* Genre.DATA} is used)
59-
* @param name user friendly name of this analyzer (or null if it shouldn't be listed)
59+
* @param name user-friendly name of this analyzer (or null if it shouldn't be listed)
60+
* @param hasAnnotations whether the files processed by the analyzers produced by this factory can be annotated
6061
*/
6162
protected FileAnalyzerFactory(
6263
String[] names, String[] prefixes, String[] suffixes,
6364
String[] magics, Matcher matcher, String contentType,
64-
AbstractAnalyzer.Genre genre, String name) {
65+
AbstractAnalyzer.Genre genre, String name, boolean hasAnnotations) {
6566
super(matcher, contentType);
6667
this.names = asList(names);
6768
this.prefixes = asList(prefixes);
6869
this.suffixes = asList(suffixes);
6970
this.magics = asList(magics);
7071
this.genre = (genre == null) ? AbstractAnalyzer.Genre.DATA : genre;
7172
this.name = name;
73+
this.hasAnnotations = hasAnnotations;
7274
}
7375

7476
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ada/AdaAnalyzerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2010, 2024, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.analysis.ada;
@@ -41,7 +41,7 @@ public class AdaAnalyzerFactory extends FileAnalyzerFactory {
4141
};
4242

4343
public AdaAnalyzerFactory() {
44-
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
44+
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
4545
}
4646

4747
@Override

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/archive/BZip2AnalyzerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.analysis.archive;
2424

@@ -38,7 +38,7 @@ public class BZip2AnalyzerFactory extends FileAnalyzerFactory {
3838
};
3939

4040
public BZip2AnalyzerFactory() {
41-
super(null, null, SUFFIXES, MAGICS, null, null, null, NAME);
41+
super(null, null, SUFFIXES, MAGICS, null, null, null, NAME, false);
4242
}
4343

4444
@Override

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/archive/GZIPAnalyzerFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.analysis.archive;
2424

@@ -38,9 +38,8 @@ public class GZIPAnalyzerFactory extends FileAnalyzerFactory {
3838
};
3939

4040
public GZIPAnalyzerFactory() {
41-
super(null, null, SUFFIXES, MAGICS, null, null, null, NAME);
41+
super(null, null, SUFFIXES, MAGICS, null, null, null, NAME, false);
4242
}
43-
4443
@Override
4544
protected AbstractAnalyzer newAnalyzer() {
4645
return new GZIPAnalyzer(this);

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/archive/TarAnalyzerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.analysis.archive;
2424

@@ -34,7 +34,7 @@ public class TarAnalyzerFactory extends FileAnalyzerFactory {
3434
};
3535

3636
public TarAnalyzerFactory() {
37-
super(null, null, SUFFIXES, null, null, null, AbstractAnalyzer.Genre.XREFABLE, NAME);
37+
super(null, null, SUFFIXES, null, null, null, AbstractAnalyzer.Genre.XREFABLE, NAME, false);
3838
}
3939

4040
@Override

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/archive/ZipAnalyzerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2018, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.analysis.archive;
@@ -57,7 +57,7 @@ protected boolean doesCheckExtraFieldID() {
5757
new ZipAnalyzerFactory();
5858

5959
private ZipAnalyzerFactory() {
60-
super(null, null, SUFFIXES, null, MATCHER, null, AbstractAnalyzer.Genre.XREFABLE, NAME);
60+
super(null, null, SUFFIXES, null, MATCHER, null, AbstractAnalyzer.Genre.XREFABLE, NAME, false);
6161
}
6262

6363
@Override

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/asm/AsmAnalyzerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class AsmAnalyzerFactory extends FileAnalyzerFactory {
3939
* ".s" with {@link AsmAnalyzer}.
4040
*/
4141
public AsmAnalyzerFactory() {
42-
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
42+
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
4343
}
4444

4545
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/c/CAnalyzerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2019, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.analysis.c;
@@ -44,7 +44,7 @@ public class CAnalyzerFactory extends FileAnalyzerFactory {
4444
};
4545

4646
public CAnalyzerFactory() {
47-
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
47+
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
4848
}
4949

5050
@Override

0 commit comments

Comments
 (0)