forked from eclipse-lsp4mp/lsp4mp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contribute to exclude property from validation
Fixes eclipse-lsp4mp#95 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
ab86a54
commit 6079e9c
Showing
8 changed files
with
288 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...se.lsp4mp.ls/src/main/java/org/eclipse/lsp4mp/settings/MicroProfileExtensionSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package org.eclipse.lsp4mp.settings; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.Enumeration; | ||
import java.util.List; | ||
|
||
import org.eclipse.lsp4mp.services.ValidationType; | ||
|
||
import com.google.gson.Gson; | ||
|
||
public class MicroProfileExtensionSettings { | ||
|
||
private List<MicroProfileGeneralClientSettings> extensionSettings; | ||
|
||
public void merge(MicroProfileGeneralClientSettings settings) { | ||
getExtensionSettings().forEach(extensionSettings -> { | ||
merge(settings, extensionSettings); | ||
}); | ||
} | ||
|
||
private void merge(MicroProfileGeneralClientSettings settings, | ||
MicroProfileGeneralClientSettings extensionSettings) { | ||
// Merge validation unknown excluded | ||
List<String> extensionValidationUnknownExcluded = getValidationExcluded(extensionSettings, | ||
ValidationType.unknown, false); | ||
if (extensionValidationUnknownExcluded != null && !extensionValidationUnknownExcluded.isEmpty()) { | ||
List<String> validationUnknownExcluded = getValidationExcluded(settings, ValidationType.unknown, | ||
true); | ||
merge(extensionValidationUnknownExcluded, validationUnknownExcluded); | ||
} | ||
} | ||
|
||
private void merge(List<String> from, List<String> to) { | ||
for (String value : from) { | ||
if (!to.contains(value)) { | ||
to.add(value); | ||
} | ||
} | ||
} | ||
|
||
private static List<String> getValidationExcluded(MicroProfileGeneralClientSettings settings, ValidationType type, | ||
boolean create) { | ||
MicroProfileValidationSettings validation = settings.getValidation(); | ||
if (validation == null && create) { | ||
validation = new MicroProfileValidationSettings(); | ||
settings.setValidation(validation); | ||
} | ||
if (validation == null) { | ||
return null; | ||
} | ||
MicroProfileValidationTypeSettings validationType = null; | ||
switch (type) { | ||
case unknown: | ||
validationType = validation.getUnknown(); | ||
if (validationType == null && create) { | ||
validationType = new MicroProfileValidationTypeSettings(); | ||
validation.setUnknown(validationType); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
if (validationType == null) { | ||
return null; | ||
} | ||
List<String> excluded = validationType.getExcluded(); | ||
if (excluded == null && create) { | ||
excluded = new ArrayList<>(); | ||
validationType.setExcluded(excluded); | ||
} | ||
return excluded; | ||
} | ||
|
||
public List<MicroProfileGeneralClientSettings> getExtensionSettings() { | ||
if (extensionSettings == null) { | ||
extensionSettings = loadExtensionSettings(); | ||
} | ||
return extensionSettings; | ||
} | ||
|
||
private synchronized List<MicroProfileGeneralClientSettings> loadExtensionSettings() { | ||
if (extensionSettings != null) { | ||
return extensionSettings; | ||
} | ||
List<MicroProfileGeneralClientSettings> extensionSettings = new ArrayList<>(); | ||
|
||
try { | ||
Enumeration<URL> resources = this.getClass().getClassLoader().getResources("META-INF/lsp4mp/settings.json"); | ||
while (resources.hasMoreElements()) { | ||
URL url1 = resources.nextElement(); | ||
MicroProfileGeneralClientSettings settings = new Gson().fromJson( | ||
new InputStreamReader((InputStream) url1.getContent()), | ||
MicroProfileGeneralClientSettings.class); | ||
extensionSettings.add(settings); | ||
} | ||
} catch (IOException e) { | ||
|
||
} | ||
return extensionSettings; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.