Analysis.java
/*
* Copyright © 2026 The CTAN Team and individual authors
*
* This file is distributed under the 3-clause BSD license.
* See file LICENSE for details.
*/
package org.ctan.analysers;
import java.util.HashMap;
import java.util.Map;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Builder.Default;
import lombok.Getter;
import lombok.Setter;
/**
* The class <code>Analysis</code> contains the transport object for an analysis
* result.
*
* @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
*/
@Builder
@AllArgsConstructor
@SuppressFBWarnings(value = "EI_EXPOSE_REP2")
public class Analysis {
/**
* The class <code>Def</code> contains the container for the definition
* attributes.
*/
@Builder
@Getter
@AllArgsConstructor
public static class Def {
DefType type;
int lineno;
}
/**
* The enum <code>DefType</code> contains the classification of definitions.
*/
public enum DefType {
BOX(Engine.TEX), //
CHAR(Engine.TEX), //
COUNT(Engine.TEX), //
DIMEN(Engine.TEX), //
FONT(Engine.TEX), //
IF(Engine.TEX), //
INSERT(Engine.TEX), //
LET(Engine.TEX), //
MACRO(Engine.TEX), //
SKIP(Engine.TEX), //
TOKS(Engine.TEX), //
LATEX_MACRO(Engine.LATEX), //
LATEX_ENVIRONMENT(Engine.LATEX), //
LATEX_PACKAGE(Engine.LATEX), //
LATEX_CLASS(Engine.LATEX), //
CONTEXT_DEF(Engine.CONTEXT);
/**
* The field <code>engine</code> contains the engine containing the
* code.
*/
@Getter
private Engine engine;
/**
* This is the constructor for <code>DefType</code>.
*
* @param eng the engine
*/
DefType(Engine eng) {
this.engine = eng;
}
}
/**
* The enum <code>Engine</code> contains a classification for macros.
*/
private enum Engine {
TEX, LATEX, CONTEXT
}
/**
* The field <code>source</code> contains the path to the file which has
* been analysed.
*/
@Getter
@Setter
private String source;
/**
* The field <code>title</code> contains the optional title.
*/
@Getter
@Setter
@Default
private String title = null;
/**
* The field <code>macros</code> contains the map of definitions.
*/
@Getter
@Default
@SuppressFBWarnings(value = "EI_EXPOSE_REP")
private Map<String, Def> macros = new HashMap<String, Def>();
/**
* The field <code>fromLaTeX</code> contains the indicator for a LaTeX
* macro.
*/
@Getter
@Default
private boolean fromLaTeX = false;
/**
* The field <code>fromConTeXt</code> contains the indicator for a ConTeXt
* macro.
*/
@Getter
@Default
private boolean fromConTeXt = false;
/**
* The method <code>set</code> provides means to store a macro.
*
* @param name the name
* @param type the type
* @param lineno the line number
*/
public void set(String name, DefType type, int lineno) {
macros.put(name, new Def(type, lineno));
switch (type.getEngine()) {
case CONTEXT:
fromConTeXt = true;
break;
case LATEX:
fromLaTeX = true;
break;
default:
break;
}
}
}