Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class PropertiesFileValidator {
private final Map<String, Property> potentiallyUnknownProperties;
private Set<String> declaredProperties;
private Map<String, ItemMetadata> availableProperties;
private Set<String> referencedProperties;

private ValidationKeyContext validationKeyContext;
private ValidationValueContext validationValueContext;
Expand All @@ -87,6 +88,7 @@ public PropertiesFileValidator(MicroProfileProjectInfo projectInfo, List<Diagnos
// to be lazily init
this.declaredProperties = null;
this.availableProperties = null;
this.referencedProperties = null;
}

public void validate(PropertiesModel document, CancelChecker cancelChecker) {
Expand Down Expand Up @@ -312,7 +314,8 @@ private void validatePropertyValueExpressions(String propertyName, ItemMetadata
return;
}

// Lazy initialization: collect declared properties, available properties, and referenced properties
// Lazy initialization: collect declared properties, available properties, and
// referenced properties
// in a single pass when processing the first expression
if (declaredProperties == null) {
initializePropertiesCollections(property.getOwnerModel());
Expand Down Expand Up @@ -426,48 +429,58 @@ private void addDiagnosticsForRequiredIfNoValue(String propertyName, DiagnosticS
}

private void addDiagnosticsForUnknownProperties() {
// Properties that are referenced in expressions have already been removed from potentiallyUnknownProperties
// Properties that are referenced in expressions have already been removed from
// potentiallyUnknownProperties
// or are in referencedProperties set
potentiallyUnknownProperties.forEach((propertyName, property) -> {
// Skip properties that are referenced in expressions (they may have been added
// after initialization)
if (referencedProperties != null && referencedProperties.contains(propertyName)) {
return;
}
DiagnosticSeverity severity = validationSettings.getUnknown().getDiagnosticSeverity(propertyName);
if (severity != null) {
addDiagnostic("Unrecognized property '" + propertyName + "', it is not referenced in any Java files",
addDiagnostic(
"Unrecognized property '" + propertyName
+ "', it is not referenced in any Java, Properties files",
property.getKey(), severity, ValidationType.unknown.name());
}
});
}

/**
* Initialize properties collections in a single pass over the properties model.
* Collects:
* - declaredProperties: all property names defined in the file
* - availableProperties: all properties from project metadata
* Also removes referenced properties from potentiallyUnknownProperties
* Collects: - declaredProperties: all property names defined in the file -
* availableProperties: all properties from project metadata -
* referencedProperties: all properties referenced in expressions
*/
private void initializePropertiesCollections(PropertiesModel model) {
declaredProperties = new java.util.HashSet<>();

// Single pass to collect declared properties and remove referenced ones from potentially unknown
// Single pass to collect declared properties and referenced properties
for (Node node : model.getChildren()) {
if (node.getNodeType() == NodeType.PROPERTY) {
Property prop = (Property) node;
// Collect declared property
declaredProperties.add(prop.getPropertyNameWithProfile());

// Remove referenced properties from potentiallyUnknownProperties
// Collect referenced properties in expressions
if (prop.getValue() != null) {
for (Node child : prop.getValue().getChildren()) {
if (child.getNodeType() == NodeType.PROPERTY_VALUE_EXPRESSION) {
PropertyValueExpression expr = (PropertyValueExpression) child;
potentiallyUnknownProperties.remove(expr.getReferencedPropertyName());
if (referencedProperties == null) {
referencedProperties = new java.util.HashSet<>();
}
referencedProperties.add(expr.getReferencedPropertyName());
}
}
}
}
}

// Collect available properties from project metadata
availableProperties = projectInfo.getProperties()
.stream()
availableProperties = projectInfo.getProperties().stream()
.collect(Collectors.toMap(ItemMetadata::getName, Function.identity(), (i1, i2) -> i1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void sysemPropertyInKey() {
// dbuser doesn't exists a System property
String value = "dbuser = FOO";
testDiagnosticsFor(value, //
d(0, 0, 6, "Unrecognized property 'dbuser', it is not referenced in any Java files",
d(0, 0, 6, "Unrecognized property 'dbuser', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown));

// user.name exists as System property
Expand All @@ -61,7 +61,7 @@ public void environmentVariableInKey() {
// DBUSER doesn't exists a Environment variable
String value = "DBUSER = FOO";
testDiagnosticsFor(value, //
d(0, 0, 6, "Unrecognized property 'DBUSER', it is not referenced in any Java files",
d(0, 0, 6, "Unrecognized property 'DBUSER', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown));

// PATH exists as Environment variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void codeActionsForUnknownProperties() throws BadLocationException {
"\n" + //
"";
Diagnostic d = d(1, 0, 23,
"Unrecognized property 'quarkus.application.nme', it is not referenced in any Java files",
"Unrecognized property 'quarkus.application.nme', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);

testDiagnosticsFor(value, d);
Expand All @@ -65,22 +65,22 @@ public void codeActionsForUnknownPropertiesParentKey() throws BadLocationExcepti
"abcdefghij.readiness-probe.initial-delay-seconds=20\n" + //
"abcdefghij.readiness-probe.period-seconds=45";

Diagnostic d1 = d(0, 0, 16, "Unrecognized property 'abcdefghij.group', it is not referenced in any Java files",
Diagnostic d1 = d(0, 0, 16, "Unrecognized property 'abcdefghij.group', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);
Diagnostic d2 = d(1, 0, 19,
"Unrecognized property 'abcdefghij.registry', it is not referenced in any Java files",
"Unrecognized property 'abcdefghij.registry', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);
Diagnostic d3 = d(2, 0, 24,
"Unrecognized property 'abcdefghij.labels[0].key', it is not referenced in any Java files",
"Unrecognized property 'abcdefghij.labels[0].key', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);
Diagnostic d4 = d(3, 0, 26,
"Unrecognized property 'abcdefghij.labels[0].value', it is not referenced in any Java files",
"Unrecognized property 'abcdefghij.labels[0].value', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);
Diagnostic d5 = d(4, 0, 48,
"Unrecognized property 'abcdefghij.readiness-probe.initial-delay-seconds', it is not referenced in any Java files",
"Unrecognized property 'abcdefghij.readiness-probe.initial-delay-seconds', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);
Diagnostic d6 = d(5, 0, 41,
"Unrecognized property 'abcdefghij.readiness-probe.period-seconds', it is not referenced in any Java files",
"Unrecognized property 'abcdefghij.readiness-probe.period-seconds', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);

testDiagnosticsFor(value, d1, d2, d3, d4, d5, d6);
Expand All @@ -107,9 +107,9 @@ public void codeActionsForUnknownPropertiesParentKey2() throws BadLocationExcept
String value = "a.b.c.d=123\n" + //
"a.c.d=123";

Diagnostic d1 = d(0, 0, 7, "Unrecognized property 'a.b.c.d', it is not referenced in any Java files",
Diagnostic d1 = d(0, 0, 7, "Unrecognized property 'a.b.c.d', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);
Diagnostic d2 = d(1, 0, 5, "Unrecognized property 'a.c.d', it is not referenced in any Java files",
Diagnostic d2 = d(1, 0, 5, "Unrecognized property 'a.c.d', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);

testDiagnosticsFor(value, d1, d2);
Expand All @@ -126,7 +126,7 @@ public void codeActionsForUnknownPropertiesParentKey3() throws BadLocationExcept

String value = "quarkus.a.b.c.d=123";

Diagnostic d = d(0, 0, 15, "Unrecognized property 'quarkus.a.b.c.d', it is not referenced in any Java files",
Diagnostic d = d(0, 0, 15, "Unrecognized property 'quarkus.a.b.c.d', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);

testDiagnosticsFor(value, d);
Expand All @@ -140,7 +140,7 @@ public void codeActionsForUnknownPropertiesParentKey4() throws BadLocationExcept

String value = "a.b.c.d=123";

Diagnostic d1 = d(0, 0, 7, "Unrecognized property 'a.b.c.d', it is not referenced in any Java files",
Diagnostic d1 = d(0, 0, 7, "Unrecognized property 'a.b.c.d', it is not referenced in any Java, Properties files",
DiagnosticSeverity.Warning, ValidationType.unknown);

testDiagnosticsFor(value, d1);
Expand Down
Loading
Loading