package uk.ac.cam.gpe21.droidssl.analysis.util;

import soot.*;
import uk.ac.cam.gpe21.droidssl.analysis.VulnerabilityState;
import uk.ac.cam.gpe21.droidssl.analysis.tag.VulnerabilityTag;

public final class PointsToUtils {
	public static boolean anyTypeVulnerable(PointsToSet set, final String tagName) {
		final boolean[] box = new boolean[1]; // TODO this is hacky

		for (Type type : set.possibleTypes()) {
			type.apply(new TypeSwitch() {
				@Override
				public void caseRefType(RefType type) {
					VulnerabilityTag tag = (VulnerabilityTag) type.getSootClass().getTag(tagName);
					if (tag.getState() == VulnerabilityState.VULNERABLE)
						box[0] = true;
				}

				@Override
				public void caseAnySubType(AnySubType type) {
					VulnerabilityTag tag = (VulnerabilityTag) type.getBase().getSootClass().getTag(tagName);
					if (tag.getState() == VulnerabilityState.VULNERABLE)
						box[0] = true;
				}

				// TODO any other cases?
			});
		}

		return box[0];
	}

	public static boolean allTypesSafe(PointsToSet set, final String tagName) {
		final boolean[] box = new boolean[1]; // TODO this is hacky
		box[0] = true;

		for (Type type : set.possibleTypes()) {
			type.apply(new TypeSwitch() {
				@Override
				public void caseRefType(RefType type) {
					VulnerabilityTag tag = (VulnerabilityTag) type.getSootClass().getTag(tagName);
					if (tag.getState() != VulnerabilityState.SAFE)
						box[0] = false;
				}

				@Override
				public void caseAnySubType(AnySubType type) {
					VulnerabilityTag tag = (VulnerabilityTag) type.getBase().getSootClass().getTag(tagName);
					if (tag.getState() != VulnerabilityState.SAFE)
						box[0] = false;
				}

				// TODO any other cases?
			});
		}

		return box[0];
	}

	private PointsToUtils() {
		/* to prevent instantiation */
	}
}

@@ -583,32 +583,47 @@
 e);%0A%09%09%09%09%09if (tag
+ != null && tag
 .getState() == V
@@ -644,32 +644,32 @@
 ate.VULNERABLE)%0A
-
 %09%09%09%09%09%09box%5B0%5D = t
@@ -842,32 +842,47 @@
 e);%0A%09%09%09%09%09if (tag
+ != null && tag
 .getState() == V
@@ -1379,32 +1379,47 @@
 e);%0A%09%09%09%09%09if (tag
+ != null && tag
 .getState() != V
@@ -1621,32 +1621,32 @@
 etTag(tagName);%0A
-
 %09%09%09%09%09if (tag.get
@@ -1641,16 +1641,31 @@
 %09if (tag
+ != null && tag
 .getStat

Fix PointsToUtils when tag is not present.