mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-4744: Last tweaks and formatting.
This commit is contained in:
parent
0dea3d49ca
commit
78d4d38a80
7 changed files with 74 additions and 65 deletions
|
@ -20,11 +20,13 @@ import java.lang.annotation.Annotation;
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import javax.tools.Diagnostic.Kind;
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
|
||||||
|
import ghidra.util.database.DBAnnotatedObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract class for validating annotations on {@link DBAnnotatedObject}.
|
* An abstract class for validating annotations on {@link DBAnnotatedObject}.
|
||||||
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* Performs validation checks on annotated fields and their enclosing types.
|
* Performs validation checks on annotated fields and their enclosing types.
|
||||||
* </p>
|
|
||||||
*/
|
*/
|
||||||
public class AbstractDBAnnotationValidator {
|
public class AbstractDBAnnotationValidator {
|
||||||
protected final ValidationContext ctx;
|
protected final ValidationContext ctx;
|
||||||
|
|
|
@ -20,8 +20,8 @@ import java.util.Set;
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An enum to represent different levels of access specifiers
|
* An enum to represent different levels of access specifiers (private, package-private, protected,
|
||||||
* (private, package-private, protected, public) with corresponding access levels
|
* public) with corresponding access levels
|
||||||
*/
|
*/
|
||||||
public enum AccessSpec {
|
public enum AccessSpec {
|
||||||
PRIVATE(0), PACKAGE(1), PROTECTED(2), PUBLIC(3);
|
PRIVATE(0), PACKAGE(1), PROTECTED(2), PUBLIC(3);
|
||||||
|
|
|
@ -23,10 +23,11 @@ import javax.tools.Diagnostic.Kind;
|
||||||
import ghidra.util.database.annot.DBAnnotatedColumn;
|
import ghidra.util.database.annot.DBAnnotatedColumn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class for validating fields annotated with {@link DBAnnotatedColumn}
|
* A class for validating fields annotated with {@link DBAnnotatedColumn}.
|
||||||
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* To ensure fields annotated with {@link DBAnnotatedColumn}
|
* To ensure fields annotated with {@link DBAnnotatedColumn} comply with the expected criteria for
|
||||||
* comply with the expected criteria for database columns in Ghidra.
|
* database columns in Ghidra.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -34,9 +35,11 @@ public class DBAnnotatedColumnValidator extends AbstractDBAnnotationValidator {
|
||||||
final VariableElement column;
|
final VariableElement column;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new {@code DBAnnotatedColumnValidator} with the specified validation context and the column element.
|
* Construct a new {@code DBAnnotatedColumnValidator} with the specified validation context and
|
||||||
* @param ctx
|
* the column element.
|
||||||
* @param column
|
*
|
||||||
|
* @param ctx the validation context
|
||||||
|
* @param column the field representing the column
|
||||||
*/
|
*/
|
||||||
public DBAnnotatedColumnValidator(ValidationContext ctx, VariableElement column) {
|
public DBAnnotatedColumnValidator(ValidationContext ctx, VariableElement column) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
@ -52,9 +55,9 @@ public class DBAnnotatedColumnValidator extends AbstractDBAnnotationValidator {
|
||||||
* <li>The field must be of the type specified by {@code ctx.DB_OBJECT_COLUMN_ELEM}.</li>
|
* <li>The field must be of the type specified by {@code ctx.DB_OBJECT_COLUMN_ELEM}.</li>
|
||||||
* <li>The field must not be declared as {@code final}.</li>
|
* <li>The field must not be declared as {@code final}.</li>
|
||||||
* <li>The field must be declared as {@code static}.</li>
|
* <li>The field must be declared as {@code static}.</li>
|
||||||
* <li>The enclosing type of the field must meet the criteria defined in {@code checkEnclosingType}.</li>
|
* <li>The enclosing type of the field must meet the criteria defined in
|
||||||
|
* {@code checkEnclosingType}.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* </p>
|
|
||||||
*/
|
*/
|
||||||
public void validate() {
|
public void validate() {
|
||||||
if (!ctx.hasType(column, ctx.DB_OBJECT_COLUMN_ELEM)) {
|
if (!ctx.hasType(column, ctx.DB_OBJECT_COLUMN_ELEM)) {
|
||||||
|
|
|
@ -25,11 +25,11 @@ import ghidra.util.database.annot.DBAnnotatedField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class for validating fields annotated with {@link DBAnnotatedField}
|
* A class for validating fields annotated with {@link DBAnnotatedField}
|
||||||
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* To ensure fields annotated with {@link DBAnnotatedField} meet the criteria required for database fields
|
* To ensure fields annotated with {@link DBAnnotatedField} meet the criteria required for database
|
||||||
* in Ghidra. It extends the {@code AbstractDBAnnotationValidator} to provide additional
|
* fields in Ghidra. It extends the {@code AbstractDBAnnotationValidator} to provide additional
|
||||||
* validation logic specific to database field annotations.
|
* validation logic specific to database field annotations.
|
||||||
* </p>
|
|
||||||
*/
|
*/
|
||||||
public class DBAnnotatedFieldValidator extends AbstractDBAnnotationValidator {
|
public class DBAnnotatedFieldValidator extends AbstractDBAnnotationValidator {
|
||||||
final VariableElement field;
|
final VariableElement field;
|
||||||
|
@ -48,9 +48,11 @@ public class DBAnnotatedFieldValidator extends AbstractDBAnnotationValidator {
|
||||||
final TypeElement ENUM_CODEC_ELEM;
|
final TypeElement ENUM_CODEC_ELEM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new {@code DBAnnotatedFieldValidator} with the specified validation context and field element.
|
* Construct a new {@code DBAnnotatedFieldValidator} with the specified validation context and
|
||||||
* @param ctx
|
* field element.
|
||||||
* @param field
|
*
|
||||||
|
* @param ctx the validation context
|
||||||
|
* @param field the field to validate
|
||||||
*/
|
*/
|
||||||
public DBAnnotatedFieldValidator(ValidationContext ctx, VariableElement field) {
|
public DBAnnotatedFieldValidator(ValidationContext ctx, VariableElement field) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
@ -118,15 +120,16 @@ public class DBAnnotatedFieldValidator extends AbstractDBAnnotationValidator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the annotated field to ensure it meets the requirements for database fields.
|
* Validate the annotated field to ensure it meets the requirements for database fields.
|
||||||
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* It performs the following checks:
|
* It performs the following checks:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>The field must not be declared as {@code final}.</li>
|
* <li>The field must not be declared as {@code final}.</li>
|
||||||
* <li>The field must not be declared as {@code static}.</li>
|
* <li>The field must not be declared as {@code static}.</li>
|
||||||
* <li>The enclosing type of the field must meet the criteria defined in {@code checkEnclosingType}.</li>
|
* <li>The enclosing type of the field must meet the criteria defined in
|
||||||
|
* {@code checkEnclosingType}.</li>
|
||||||
* <li>The codec types for the field must be appropriate.</li>
|
* <li>The codec types for the field must be appropriate.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* </p>
|
|
||||||
*/
|
*/
|
||||||
public void validate() {
|
public void validate() {
|
||||||
Set<Modifier> mods = field.getModifiers();
|
Set<Modifier> mods = field.getModifiers();
|
||||||
|
@ -161,8 +164,8 @@ public class DBAnnotatedFieldValidator extends AbstractDBAnnotationValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the codec type element specified in the {@link DBAnnotatedField} annotation
|
* Return the codec type element specified in the {@link DBAnnotatedField} annotation for the
|
||||||
* for the field, or the default codec type if none is specified.
|
* field, or the default codec type if none is specified.
|
||||||
*
|
*
|
||||||
* @return the codec type element for the field
|
* @return the codec type element for the field
|
||||||
*/
|
*/
|
||||||
|
@ -182,7 +185,8 @@ public class DBAnnotatedFieldValidator extends AbstractDBAnnotationValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the codec types associated with the field to ensure they meet the necessary requirements.
|
* Check the codec types associated with the field to ensure they meet the necessary
|
||||||
|
* requirements.
|
||||||
*
|
*
|
||||||
* @param objectType the type of the enclosing object
|
* @param objectType the type of the enclosing object
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -31,10 +31,8 @@ import ghidra.util.database.annot.*;
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This processor performs compile-time validation checks on annotations related to
|
* This processor performs compile-time validation checks on annotations related to
|
||||||
* {@link DBAnnotatedObject}.
|
* {@link DBAnnotatedObject}. Currently just performs compile-time checks. It does not generate any
|
||||||
* Currently just performs compile-time checks. It does not generate any code, but perhaps one day,
|
* code, but perhaps one day, it will.
|
||||||
* it will.
|
|
||||||
* </p>
|
|
||||||
*/
|
*/
|
||||||
//@AutoService(Processor.class) // TODO: Evaluate Google's auto-service as a dependency
|
//@AutoService(Processor.class) // TODO: Evaluate Google's auto-service as a dependency
|
||||||
public class DBAnnotatedObjectProcessor extends AbstractProcessor {
|
public class DBAnnotatedObjectProcessor extends AbstractProcessor {
|
||||||
|
@ -60,7 +58,8 @@ public class DBAnnotatedObjectProcessor extends AbstractProcessor {
|
||||||
*
|
*
|
||||||
* @param annotations the set of annotations to process
|
* @param annotations the set of annotations to process
|
||||||
* @param roundEnv the environment for information about the current and prior round
|
* @param roundEnv the environment for information about the current and prior round
|
||||||
* @return {@code true} if the annotations are claimed by this processor, {@code false} otherwise
|
* @return {@code true} if the annotations are claimed by this processor, {@code false}
|
||||||
|
* otherwise
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||||
|
@ -104,7 +103,6 @@ public class DBAnnotatedObjectProcessor extends AbstractProcessor {
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends Completion> getCompletions(Element element,
|
public Iterable<? extends Completion> getCompletions(Element element,
|
||||||
AnnotationMirror annotation, ExecutableElement member, String userText) {
|
AnnotationMirror annotation, ExecutableElement member, String userText) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return super.getCompletions(element, annotation, member, userText);
|
return super.getCompletions(element, annotation, member, userText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +123,8 @@ public class DBAnnotatedObjectProcessor extends AbstractProcessor {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getSupportedAnnotationTypes() {
|
public Set<String> getSupportedAnnotationTypes() {
|
||||||
return SUPPORTED_ANNOTATIONS.stream().map(Class::getCanonicalName).collect(
|
return SUPPORTED_ANNOTATIONS.stream()
|
||||||
Collectors.toSet());
|
.map(Class::getCanonicalName)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,15 +20,16 @@ import java.util.*;
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import javax.tools.Diagnostic.Kind;
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
|
||||||
|
import ghidra.util.database.DBAnnotatedObject;
|
||||||
import ghidra.util.database.annot.*;
|
import ghidra.util.database.annot.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate {@link DBAnnotatedObject}-related annotations on a given type element.
|
* Validate {@link DBAnnotatedObject}-related annotations on a given type element.
|
||||||
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* This class ensures that annotations such as {@link DBAnnotatedField}, {@link DBAnnotatedColumn},
|
* This class ensures that annotations such as {@link DBAnnotatedField}, {@link DBAnnotatedColumn},
|
||||||
* and {@link DBAnnotatedObjectInfo} are applied correctly and consistently on the fields and columns
|
* and {@link DBAnnotatedObjectInfo} are applied correctly and consistently on the fields and
|
||||||
* of a class.
|
* columns of a class.
|
||||||
* </p>
|
|
||||||
*/
|
*/
|
||||||
public class DBAnnotatedObjectValidator {
|
public class DBAnnotatedObjectValidator {
|
||||||
private final ValidationContext ctx;
|
private final ValidationContext ctx;
|
||||||
|
@ -71,6 +72,8 @@ public class DBAnnotatedObjectValidator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the annotated fields, columns, and the type element itself.
|
* Validate the annotated fields, columns, and the type element itself.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
* Checks for various annotation constraints and consistency rules.
|
* Checks for various annotation constraints and consistency rules.
|
||||||
*/
|
*/
|
||||||
public void validate() {
|
public void validate() {
|
||||||
|
@ -160,6 +163,7 @@ public class DBAnnotatedObjectValidator {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the access specifiers of the field and column are compatible.
|
* Check that the access specifiers of the field and column are compatible.
|
||||||
|
*
|
||||||
* @param field the field element
|
* @param field the field element
|
||||||
* @param column the column element
|
* @param column the column element
|
||||||
* @param name the name of the column
|
* @param name the name of the column
|
||||||
|
|
|
@ -153,8 +153,7 @@ public class ValidationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the supertype of a set of declared types that matches the specified
|
* Find the supertype of a set of declared types that matches the specified super type.
|
||||||
* super type.
|
|
||||||
*
|
*
|
||||||
* @param types the set of declared types
|
* @param types the set of declared types
|
||||||
* @param superType the super type element to match
|
* @param superType the super type element to match
|
||||||
|
@ -180,8 +179,7 @@ public class ValidationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the supertype of a declared type that matches the specified super type
|
* Find the supertype of a declared type that matches the specified super type element.
|
||||||
* element.
|
|
||||||
*
|
*
|
||||||
* @param type the declared type
|
* @param type the declared type
|
||||||
* @param superElem the super type element to match
|
* @param superElem the super type element to match
|
||||||
|
@ -192,8 +190,7 @@ public class ValidationContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the supertype of a type element that matches the specified super type
|
* Find the supertype of a type element that matches the specified super type element.
|
||||||
* element.
|
|
||||||
*
|
*
|
||||||
* @param elem the type element
|
* @param elem the type element
|
||||||
* @param superElem the super type element to match
|
* @param superElem the super type element to match
|
||||||
|
@ -263,8 +260,8 @@ class FormatVisitor implements TypeVisitor<Void, Void> {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit method for {@link TypeMirror}. Delegates to specific visit methods
|
* Visit method for {@link TypeMirror}. Delegates to specific visit methods based on the type
|
||||||
* based on the type kind.
|
* kind.
|
||||||
*
|
*
|
||||||
* @param t the type mirror to visit
|
* @param t the type mirror to visit
|
||||||
* @param p unused parameter (can be {@code null})
|
* @param p unused parameter (can be {@code null})
|
||||||
|
@ -408,7 +405,7 @@ class FormatVisitor implements TypeVisitor<Void, Void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit method for {@link WindcardType}.
|
* Visit method for {@link WildcardType}.
|
||||||
*
|
*
|
||||||
* @param t the wildcard type to visit
|
* @param t the wildcard type to visit
|
||||||
* @param p unused parameter (can be {@code null})
|
* @param p unused parameter (can be {@code null})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue