Skip to content

Commit

Permalink
make the hasAnnotation check more precise (#4547)
Browse files Browse the repository at this point in the history
fixes #4524
fixes #4546
  • Loading branch information
vladak committed Feb 23, 2024
1 parent c1b9c3d commit bf398f3
Show file tree
Hide file tree
Showing 57 changed files with 167 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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

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

/**
* The user friendly name of this analyzer.
* The user-friendly name of this analyzer.
*
* @return a genre
*/
public abstract String getName();

public boolean hasAnnotations() {
return hasAnnotations;
}

public abstract AbstractAnalyzer getAnalyzer();

public abstract void returnAnalyzer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ public class AnalyzerGuru {
* Maps from {@link FileAnalyzer#getFileTypeName()} to
* {@link FileAnalyzerFactory}.
*/
private static final Map<String, AnalyzerFactory> FILETYPE_FACTORIES =
new HashMap<>();
private static final Map<String, AnalyzerFactory> FILETYPE_FACTORIES = new HashMap<>();

/**
* Maps from {@link FileAnalyzer#getFileTypeName()} to
Expand Down Expand Up @@ -771,6 +770,7 @@ public static AbstractAnalyzer.Genre getGenre(AnalyzerFactory factory) {
* @param fileTypeName a defined instance
* @return a defined instance or {@code null}
*/
@Nullable
public static AnalyzerFactory findByFileTypeName(String fileTypeName) {
return FILETYPE_FACTORIES.get(fileTypeName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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

/** The user friendly name of this analyzer. */
/** The user-friendly name of this analyzer. */
private final String name;

/**
* Create an instance of {@code FileAnalyzerFactory}.
*/
FileAnalyzerFactory() {
this(null, null, null, null, null, null, null, null);
this(null, null, null, null, null, null, null, null, false);
}

/**
Expand All @@ -56,19 +56,21 @@ public class FileAnalyzerFactory extends AnalyzerFactory {
* @param contentType content type for this analyzer (possibly {@code null})
* @param genre the genre for this analyzer (if {@code null}, {@code
* Genre.DATA} is used)
* @param name user friendly name of this analyzer (or null if it shouldn't be listed)
* @param name user-friendly name of this analyzer (or null if it shouldn't be listed)
* @param hasAnnotations whether the files processed by the analyzers produced by this factory can be annotated
*/
protected FileAnalyzerFactory(
String[] names, String[] prefixes, String[] suffixes,
String[] magics, Matcher matcher, String contentType,
AbstractAnalyzer.Genre genre, String name) {
AbstractAnalyzer.Genre genre, String name, boolean hasAnnotations) {
super(matcher, contentType);
this.names = asList(names);
this.prefixes = asList(prefixes);
this.suffixes = asList(suffixes);
this.magics = asList(magics);
this.genre = (genre == null) ? AbstractAnalyzer.Genre.DATA : genre;
this.name = name;
this.hasAnnotations = hasAnnotations;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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

public AdaAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.analysis.archive;

Expand All @@ -38,7 +38,7 @@ public class BZip2AnalyzerFactory extends FileAnalyzerFactory {
};

public BZip2AnalyzerFactory() {
super(null, null, SUFFIXES, MAGICS, null, null, null, NAME);
super(null, null, SUFFIXES, MAGICS, null, null, null, NAME, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.analysis.archive;

Expand All @@ -38,9 +38,8 @@ public class GZIPAnalyzerFactory extends FileAnalyzerFactory {
};

public GZIPAnalyzerFactory() {
super(null, null, SUFFIXES, MAGICS, null, null, null, NAME);
super(null, null, SUFFIXES, MAGICS, null, null, null, NAME, false);
}

@Override
protected AbstractAnalyzer newAnalyzer() {
return new GZIPAnalyzer(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.analysis.archive;

Expand All @@ -34,7 +34,7 @@ public class TarAnalyzerFactory extends FileAnalyzerFactory {
};

public TarAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, null, AbstractAnalyzer.Genre.XREFABLE, NAME);
super(null, null, SUFFIXES, null, null, null, AbstractAnalyzer.Genre.XREFABLE, NAME, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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

private ZipAnalyzerFactory() {
super(null, null, SUFFIXES, null, MATCHER, null, AbstractAnalyzer.Genre.XREFABLE, NAME);
super(null, null, SUFFIXES, null, MATCHER, null, AbstractAnalyzer.Genre.XREFABLE, NAME, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class AsmAnalyzerFactory extends FileAnalyzerFactory {
* ".s" with {@link AsmAnalyzer}.
*/
public AsmAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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

public CAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.analysis.c;

Expand All @@ -44,7 +44,7 @@ public class CxxAnalyzerFactory extends FileAnalyzerFactory {
};

public CxxAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.analysis.clojure;

Expand All @@ -36,7 +36,7 @@ public class ClojureAnalyzerFactory extends FileAnalyzerFactory {
};

public ClojureAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.csharp;
Expand All @@ -35,7 +35,7 @@ public class CSharpAnalyzerFactory extends FileAnalyzerFactory {
};

public CSharpAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.analysis.data;

Expand All @@ -45,7 +45,7 @@ public class IgnorantAnalyzerFactory extends FileAnalyzerFactory {
};

public IgnorantAnalyzerFactory() {
super(null, null, SUFFIXES, MAGICS, null, null, null, null);
super(null, null, SUFFIXES, MAGICS, null, null, null, null, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.analysis.data;

Expand All @@ -38,7 +38,7 @@ public class ImageAnalyzerFactory extends FileAnalyzerFactory {
};

public ImageAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, null, AbstractAnalyzer.Genre.IMAGE, NAME);
super(null, null, SUFFIXES, null, null, null, AbstractAnalyzer.Genre.IMAGE, NAME, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.document;
Expand Down Expand Up @@ -53,7 +53,7 @@ public AnalyzerFactory forFactory() {
new MandocAnalyzerFactory();

protected MandocAnalyzerFactory() {
super(null, null, null, null, MATCHER, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
super(null, null, null, null, MATCHER, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.document;
Expand Down Expand Up @@ -50,7 +50,7 @@ public AnalyzerFactory forFactory() {
new TroffAnalyzerFactory();

protected TroffAnalyzerFactory() {
super(null, null, null, null, MATCHER, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
super(null, null, null, null, MATCHER, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class EiffelAnalyzerFactory extends FileAnalyzerFactory {
*/
public EiffelAnalyzerFactory() {
super(null, null, SUFFIXES, null, null, "text/plain", AbstractAnalyzer.Genre.PLAIN,
NAME);
NAME, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.erlang;
Expand All @@ -39,7 +39,7 @@ public class ErlangAnalyzerFactory extends FileAnalyzerFactory {
};

public ErlangAnalyzerFactory() {
super(null, null, SUFFIXES, MAGICS, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME);
super(null, null, SUFFIXES, MAGICS, null, "text/plain", AbstractAnalyzer.Genre.PLAIN, NAME, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.analysis.executables;

Expand All @@ -34,7 +34,8 @@ public class ELFAnalyzerFactory extends FileAnalyzerFactory {
};

public ELFAnalyzerFactory() {
super(null, null, null, MAGICS, null, null, AbstractAnalyzer.Genre.XREFABLE, NAME);
super(null, null, null, MAGICS, null, null,
AbstractAnalyzer.Genre.XREFABLE, NAME, false);
}

@Override
Expand Down
Loading

0 comments on commit bf398f3

Please sign in to comment.