-
-
Notifications
You must be signed in to change notification settings - Fork 110
794 check for body validations and class validations #1277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
0572bdf
a190f4b
9780fa6
8f5848e
0f81035
26b2c4e
eeee87a
f462e98
bafb3b2
ac63486
b3ea18f
7211837
4732cc9
e769aa1
ab2f192
9ea4757
4e4d842
e2048db
5e0184b
5cea9f1
5bc5ed3
1628711
4388eff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| * #%L | ||
| * Soot - a J*va Optimization Framework | ||
| * %% | ||
| * Copyright (C) 1997-2020 Raja Vallée-Rai, Linghui Luo, Akshita Dubey | ||
| * Copyright (C) 1997-2020 Raja Vallée-Rai, Linghui Luo, Akshita Dubey, Sahil Agichani | ||
| * %% | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as | ||
|
|
@@ -22,13 +22,81 @@ | |
| * #L% | ||
| */ | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.EnumSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import sootup.core.model.FieldModifier; | ||
| import sootup.core.model.SootClass; | ||
| import sootup.core.model.SootField; | ||
|
|
||
| /** Validator that checks for impossible combinations of field modifiers */ | ||
| public class FieldModifiersValidator implements ClassValidator { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reused this class, which was already there, or should I create another separate class for this wrapper?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is linked to #322 |
||
|
|
||
| private final EnumSet<FieldModifier> modifiers; | ||
|
|
||
| public FieldModifiersValidator(EnumSet<FieldModifier> modifiers) { | ||
| validate(modifiers); | ||
| this.modifiers = EnumSet.copyOf(modifiers); | ||
| } | ||
|
|
||
| public static FieldModifiersValidator of(FieldModifier... mods) { | ||
| if (mods == null || mods.length == 0) { | ||
| return new FieldModifiersValidator(EnumSet.noneOf(FieldModifier.class)); | ||
| } | ||
| return new FieldModifiersValidator(EnumSet.copyOf(Arrays.asList(mods))); | ||
| } | ||
|
|
||
| public static FieldModifiersValidator from(Set<FieldModifier> mods) { | ||
| return new FieldModifiersValidator(EnumSet.copyOf(mods)); | ||
| } | ||
|
|
||
| public Set<FieldModifier> asSet() { | ||
| return EnumSet.copyOf(modifiers); | ||
| } | ||
|
|
||
| public boolean contains(FieldModifier mod) { | ||
| return modifiers.contains(mod); | ||
| } | ||
|
|
||
| private void validate(EnumSet<FieldModifier> mods) { | ||
| long accessModifiers = | ||
| mods.stream() | ||
| .filter( | ||
| m -> | ||
| m == FieldModifier.PUBLIC | ||
| || m == FieldModifier.PRIVATE | ||
| || m == FieldModifier.PROTECTED) | ||
| .count(); | ||
|
|
||
| if (accessModifiers > 1) { | ||
| throw new IllegalArgumentException("Only one of public, protected, private is allowed."); | ||
| } | ||
| // Add more rules here if needed | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringBuilder builder = new StringBuilder(); | ||
|
|
||
| if (modifiers.contains(FieldModifier.PUBLIC)) builder.append("public "); | ||
| else if (modifiers.contains(FieldModifier.PRIVATE)) builder.append("private "); | ||
| else if (modifiers.contains(FieldModifier.PROTECTED)) builder.append("protected "); | ||
|
|
||
| if (modifiers.contains(FieldModifier.STATIC)) builder.append("static "); | ||
| if (modifiers.contains(FieldModifier.FINAL)) builder.append("final "); | ||
| if (modifiers.contains(FieldModifier.VOLATILE)) builder.append("volatile "); | ||
| if (modifiers.contains(FieldModifier.TRANSIENT)) builder.append("transient "); | ||
| if (modifiers.contains(FieldModifier.ENUM)) builder.append("enum "); | ||
| if (modifiers.contains(FieldModifier.SYNTHETIC)) builder.append("synthetic "); | ||
|
|
||
| if (!builder.isEmpty()) { | ||
| builder.setLength(builder.length() - 1); // remove trailing space | ||
| } | ||
|
|
||
| return builder.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public void validate(SootClass sc, List<ValidationException> exceptions) { | ||
| for (SootField sf : sc.getFields()) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.