file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
ClassInstantiationPropagator.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/src/flow/twist/propagator/forwards/ClassInstantiationPropagator.java
package flow.twist.propagator.forwards; import static flow.twist.ifds.Propagator.KillGenInfo.gen; import static flow.twist.ifds.Propagator.KillGenInfo.identity; import java.util.Set; import soot.SootMethod; import soot.SootMethodRef; import soot.Unit; import soot.Value; import soot.jimple.AssignStmt; import soot.jimple.InstanceInvokeExpr; import soot.jimple.Stmt; import com.google.common.collect.Sets; import flow.twist.ifds.Propagator; import flow.twist.trackable.Taint; import flow.twist.trackable.Trackable; import flow.twist.util.AnalysisUtil; public class ClassInstantiationPropagator implements Propagator { private Set<String> classMethodNames = Sets.newHashSet("newInstance", "getConstructor", "getConstructors", "getDeclaredConstructor", "getDeclaredConstructors", "getEnclosingConstructor", "getEnclosingClass", "getDeclaringClass"); @Override public boolean canHandle(Trackable trackable) { return trackable instanceof Taint; } @Override public KillGenInfo propagateNormalFlow(Trackable trackable, Unit curr, Unit succ) { return identity(); } @Override public KillGenInfo propagateCallFlow(Trackable trackable, Unit callStmt, SootMethod destinationMethod) { return identity(); } @Override public KillGenInfo propagateReturnFlow(Trackable trackable, Unit callSite, SootMethod calleeMethod, Unit exitStmt, Unit returnSite) { return identity(); } @Override public KillGenInfo propagateCallToReturnFlow(Trackable trackable, Stmt callSite) { if (!(callSite instanceof AssignStmt)) return identity(); AssignStmt assignStmt = (AssignStmt) callSite; if (!(assignStmt.getInvokeExpr() instanceof InstanceInvokeExpr)) return identity(); InstanceInvokeExpr ie = (InstanceInvokeExpr) assignStmt.getInvokeExpr(); Taint t = (Taint) trackable; Value right = AnalysisUtil.getForwardsBase(ie.getBase()); if (!AnalysisUtil.maybeSameLocation(t.value, right)) return identity(); Value left = AnalysisUtil.getForwardsBase(assignStmt.getLeftOp()); SootMethodRef method = callSite.getInvokeExpr().getMethodRef(); String methodName = method.name(); String className = method.declaringClass().getName(); if ((className.equals("java.lang.Class") && classMethodNames.contains(methodName)) || (className.equals("java.lang.reflect.Constructor") && methodName.equals("newInstance"))) { return gen(t.createAlias(left, callSite)); } return identity(); } }
2,426
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
AutomataMatcher.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/src/flow/twist/states/AutomataMatcher.java
package flow.twist.states; import static flow.twist.trackable.Dummy.DUMMY; import java.util.Collection; import java.util.Set; import soot.SootMethod; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import fj.F; import fj.data.List; import flow.twist.config.AnalysisContext; import flow.twist.config.AnalysisDirection; import flow.twist.path.Path; import flow.twist.path.PathElement; import flow.twist.states.StateCache.ContextStateCache; import flow.twist.states.StateCache.StateSinkNode; import flow.twist.states.StateCache.StateStartNode; import flow.twist.util.ImmutableLinkedHashSet; public class AutomataMatcher { private Set<Path> paths = Sets.newHashSet(); public AutomataMatcher(StateCache globalStateCache) { Multimap<SootMethod, StateStartNode> startStates = HashMultimap.create(); for (ContextStateCache stateCache : globalStateCache.getAll()) { for (StateStartNode startState : stateCache.getAllStartStates()) { startStates.put(startState.method, startState); } } for (SootMethod startMethod : startStates.keySet()) { match(startStates.get(startMethod)); } } private void match(Collection<StateStartNode> states) { Set<StateStartNode> forwards = Sets.newHashSet(); Set<StateStartNode> backwards = Sets.newHashSet(); for (StateStartNode state : states) { if (state.context.direction == AnalysisDirection.BACKWARDS) backwards.add(state); else forwards.add(state); } for (StateStartNode startForwards : forwards) { for (StateStartNode startBackwards : backwards) { match(startForwards, startBackwards, ImmutableLinkedHashSet.<TransitionTuple> empty()); } } } private void match(StateNode startForwards, StateNode startBackwards, ImmutableLinkedHashSet<TransitionTuple> transitions) { if (startForwards instanceof StateSinkNode && startBackwards instanceof StateSinkNode) { createPath(transitions); } for (StateTransition transForwards : startForwards.getOutgoing()) { for (StateTransition transBackwards : startBackwards.getOutgoing()) { if (transForwards.condition == transBackwards.condition && hasSameCallSite(transForwards, transBackwards) && (hasProgress(transForwards) || hasProgress(transBackwards))) { TransitionTuple tuple = new TransitionTuple(transForwards, transBackwards); if (!transitions.contains(tuple)) { match(transForwards.getTarget(), transBackwards.getTarget(), transitions.add(tuple)); } } } } } private boolean hasProgress(StateTransition trans) { return trans.getSource() != trans.getTarget(); } protected boolean hasSameCallSite(StateTransition transForwards, StateTransition transBackwards) { return transForwards.getPath().head().from == transBackwards.getPath().head().from; } private void createPath(ImmutableLinkedHashSet<TransitionTuple> transitions) { List<PathElement> forwards = List.nil(); List<PathElement> backwards = List.nil(); List<Object> stack = List.nil(); for (TransitionTuple tuple : transitions) { forwards = appendPath(forwards, tuple.forwards); backwards = appendPath(backwards, tuple.backwards); stack = stack.cons(tuple.forwards.condition); } AnalysisContext context = transitions.head().forwards.getSource().context; paths.add(new Path(context, reverse(backwards).append(forwards), stack, null/* FIXME */)); } public static List<PathElement> appendPath(List<PathElement> existing, StateTransition t) { List<PathElement> completePath = t.getPath(); if (existing.isNotEmpty()) { if (t.getPath().isEmpty()) { PathElement connector = new PathElement(existing.last().to, DUMMY, t.connectingUnit); completePath = completePath.cons(connector); } else { PathElement connector = new PathElement(existing.last().to, DUMMY, t.getPath().head().from); completePath = completePath.cons(connector); } } completePath = existing.append(completePath); return completePath; } private List<PathElement> reverse(List<PathElement> path) { return path.reverse().map(new F<PathElement, PathElement>() { @Override public PathElement f(PathElement element) { return new PathElement(element.to, element.trackable, element.from); } }); } public Set<Path> getValidPaths() { return paths; } private static class TransitionTuple { private StateTransition forwards; private StateTransition backwards; public TransitionTuple(StateTransition forwards, StateTransition backwards) { this.forwards = forwards; this.backwards = backwards; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((backwards.condition == null) ? 0 : backwards.condition.hashCode()); result = prime * result + ((forwards.condition == null) ? 0 : forwards.condition.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; TransitionTuple other = (TransitionTuple) obj; if (backwards.condition == null) { if (other.backwards.condition != null) return false; } else if (!backwards.condition.equals(other.backwards.condition)) return false; if (forwards.condition == null) { if (other.forwards.condition != null) return false; } else if (!forwards.condition.equals(other.forwards.condition)) return false; return true; } } }
5,525
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
StateCache.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/src/flow/twist/states/StateCache.java
package flow.twist.states; import java.util.Collection; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; import soot.SootClass; import soot.SootMethod; import soot.SootMethodRef; import soot.Unit; import soot.jimple.Stmt; import com.google.common.collect.Maps; import flow.twist.config.AnalysisContext; import flow.twist.trackable.ReturnEdgeTaint; import flow.twist.trackable.Trackable; import flow.twist.util.CacheMap; public class StateCache { private CacheMap<AnalysisContext, ContextStateCache> instances = new CacheMap<AnalysisContext, ContextStateCache>() { @Override protected ContextStateCache createItem(AnalysisContext key) { return new ContextStateCache(key); } }; public ContextStateCache get(AnalysisContext context) { return instances.getOrCreate(context); } public Collection<ContextStateCache> getAll() { return instances.values(); } public static class ContextStateCache { private HashMap<StatePushNode, StatePushNode> pushCache = Maps.newHashMap(); private IdentityHashMap<Trackable, StatePopNode> popCache = Maps.newIdentityHashMap(); private Map<SootMethod, StateStartNode> startNodes = Maps.newHashMap(); public final AnalysisContext context; private Map<Unit, StateSinkNode> sinkNodes = Maps.newHashMap(); private ContextStateCache(AnalysisContext context) { this.context = context; } public StateMetadataWrapper<StatePushNode> getOrCreatePushState(ReturnEdgeTaint taint) { SootMethodRef method = ((Stmt) taint.callSite).getInvokeExpr().getMethodRef(); SootClass declaringClass = getDeclaringClass(method.declaringClass(), method); StatePushNode temp = new StatePushNode(context, declaringClass, method.name(), taint.paramIndex, method.parameterTypes()); if (pushCache.containsKey(temp)) return new StateMetadataWrapper<StatePushNode>(false, pushCache.get(temp)); else { pushCache.put(temp, temp); return new StateMetadataWrapper<StatePushNode>(true, temp); } } private static SootClass getDeclaringClass(SootClass declaringClass, SootMethodRef method) { for (SootClass i : declaringClass.getInterfaces()) { SootClass candidate = getDeclaringClass(i, method); if (candidate != null) return candidate; if (hasMethod(i, method)) return i; } if (declaringClass.hasSuperclass()) { SootClass candidate = getDeclaringClass(declaringClass.getSuperclass(), method); if (candidate != null) return candidate; if (hasMethod(declaringClass, method)) return declaringClass; } return null; } private static boolean hasMethod(SootClass declaringClass, SootMethodRef method) { for (SootMethod m : declaringClass.getMethods()) { if (m.getName().equals(method.name()) && m.getParameterTypes().equals(method.parameterTypes())) { return true; } } return false; } public StateMetadataWrapper<StatePopNode> getOrCreatePopState(Trackable trackable) { if (popCache.containsKey(trackable)) return new StateMetadataWrapper<StatePopNode>(false, popCache.get(trackable)); else { StatePopNode temp = new StatePopNode(context, trackable); popCache.put(trackable, temp); return new StateMetadataWrapper<StatePopNode>(true, temp); } } public Collection<StatePopNode> getAllPopStates() { return popCache.values(); } public Collection<StateStartNode> getAllStartStates() { return startNodes.values(); } public StateNode getOrCreateStartState(SootMethod startMethod) { if (startNodes.containsKey(startMethod)) return startNodes.get(startMethod); StateStartNode state = new StateStartNode(context, startMethod); startNodes.put(startMethod, state); return state; } public StateSinkNode getSinkState(Unit sinkUnit) { if (sinkNodes.containsKey(sinkUnit)) return sinkNodes.get(sinkUnit); else { StateSinkNode stateSinkNode = new StateSinkNode(context, sinkUnit); sinkNodes.put(sinkUnit, stateSinkNode); return stateSinkNode; } } } public static class StateStartNode extends StateNode { public final SootMethod method; public StateStartNode(AnalysisContext context, SootMethod method) { super(context); this.method = method; } } public static class StateSinkNode extends StateNode { public final Unit unit; public StateSinkNode(AnalysisContext context, Unit unit) { super(context); this.unit = unit; } } public static class StatePushNode extends StateNode { public final SootClass declaringClass; public final String methodName; public final int paramIndex; public final List paramTypes; private StatePushNode(AnalysisContext context, SootClass declaringClass, String methodName, int paramIndex, List paramTypes) { super(context); this.declaringClass = declaringClass; this.methodName = methodName; this.paramIndex = paramIndex; this.paramTypes = paramTypes; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((declaringClass == null) ? 0 : declaringClass.hashCode()); result = prime * result + ((methodName == null) ? 0 : methodName.hashCode()); result = prime * result + paramIndex; result = prime * result + ((paramTypes == null) ? 0 : paramTypes.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; StatePushNode other = (StatePushNode) obj; if (declaringClass == null) { if (other.declaringClass != null) return false; } else if (!declaringClass.equals(other.declaringClass)) return false; if (methodName == null) { if (other.methodName != null) return false; } else if (!methodName.equals(other.methodName)) return false; if (paramIndex != other.paramIndex) return false; if (paramTypes == null) { if (other.paramTypes != null) return false; } else if (!paramTypes.equals(other.paramTypes)) return false; return true; } } public static class StatePopNode extends StateNode { private Trackable trackable; private StatePopNode(AnalysisContext context, Trackable trackable) { super(context); this.trackable = trackable; } } public static class StateMetadataWrapper<T> { private boolean created; private T data; private StateMetadataWrapper(boolean created, T data) { this.created = created; this.data = data; } public boolean wasCreated() { return created; } public T get() { return data; } } }
6,639
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
StateNode.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/src/flow/twist/states/StateNode.java
package flow.twist.states; import java.util.LinkedList; import java.util.List; import flow.twist.config.AnalysisContext; public abstract class StateNode { private final List<StateTransition> incoming = new LinkedList<StateTransition>(); private final List<StateTransition> outgoing = new LinkedList<StateTransition>(); protected AnalysisContext context; protected StateNode(AnalysisContext context) { this.context = context; } public void addIncomingTransition(StateTransition s) { incoming.add(s); s.setTarget(this); } public void addOutgoingTransition(StateTransition t) { outgoing.add(t); t.setSource(this); } public void removeAllConnectionsRecursively() { for (StateTransition inc : incoming) { inc.getSource().outgoing.remove(inc); if (inc.getSource().outgoing.isEmpty()) inc.getSource().removeAllConnectionsRecursively(); } incoming.clear(); for (StateTransition out : outgoing) { out.getTarget().incoming.remove(out); if (out.getTarget().incoming.isEmpty()) out.getTarget().removeAllConnectionsRecursively(); } outgoing.clear(); } // private List<List<PathElement>> mergePaths(StateTransition first, // StateTransition second, StateTransition third) { // List<List<PathElement>> newPaths = new LinkedList<List<PathElement>>(); // // for (List<PathElement> initialPath : first.getPath()) { // List<PathElement> firstPath = new LinkedList<PathElement>(initialPath); // // for (List<PathElement> callPath : second.getPath()) { // List<PathElement> secondPath = new LinkedList<PathElement>(firstPath); // secondPath.addAll(callPath); // // for (List<PathElement> returnPath : third.getPath()) { // List<PathElement> thirdPath = new LinkedList<PathElement>(secondPath); // thirdPath.addAll(returnPath); // // newPaths.add(thirdPath); // } // } // } // return newPaths; // } public List<StateTransition> getIncoming() { return incoming; } public List<StateTransition> getOutgoing() { return outgoing; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("State ..." + hashCode() + "\n\t"); for (StateTransition transition : outgoing) { builder.append(transition.toString().replaceAll("\n", "\n\t")); builder.append("-> " + transition.getTarget().getClass()); } return builder.toString(); } }
2,354
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
StatePlotter.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/src/flow/twist/states/StatePlotter.java
package flow.twist.states; import java.util.Set; import att.grappa.Edge; import att.grappa.Graph; import att.grappa.Node; import com.google.common.collect.Sets; import flow.twist.config.AnalysisContext; import flow.twist.config.AnalysisDirection; import flow.twist.states.StateCache.ContextStateCache; import flow.twist.states.StateCache.StatePushNode; import flow.twist.states.StateCache.StateSinkNode; import flow.twist.states.StateCache.StateStartNode; import flow.twist.util.CacheMap; import flow.twist.util.DotHelper; public class StatePlotter { private StateMachineBasedPathReporter reporter; private Graph graph; private CacheMap<StateNode, Node> nodes = new CacheMap<StateNode, Node>() { @Override protected Node createItem(StateNode key) { Node node = new Node(graph); node.setAttribute("shape", "rectangle"); node.setAttribute("label", createLabel(key)); if (key instanceof StateStartNode) { node.setAttribute("style", "filled"); node.setAttribute("fillcolor", "red"); } if (key instanceof StateSinkNode) { node.setAttribute("style", "filled"); node.setAttribute("fillcolor", "green"); } graph.addNode(node); return node; } private String createLabel(StateNode key) { if (key instanceof StateStartNode) return ((StateStartNode) key).method.toString(); else if (key instanceof StateSinkNode) return ((StateSinkNode) key).unit.toString(); else if (key instanceof StatePushNode) return ((StatePushNode) key).methodName; else return "return"; } }; private Set<StateTransition> visitedTransitions = Sets.newHashSet(); public StatePlotter(StateMachineBasedPathReporter reporter) { this.reporter = reporter; } public void write(String filename) { graph = new Graph("debug graph"); graph.setAttribute("compound", "true"); for (ContextStateCache stateCache : reporter.getStateCache().getAll()) { for (StateNode state : stateCache.getAllStartStates()) { plot(state, stateCache.context); } } DotHelper.writeFilesForGraph(filename, graph); } private void plot(StateNode state, AnalysisContext context) { for (StateTransition t : state.getOutgoing()) { if (visitedTransitions.add(t)) { plot(t.getTarget(), context); createEdge(t, context); } } } private void createEdge(StateTransition t, AnalysisContext context) { Node from = nodes.getOrCreate(t.getSource()); Node to = nodes.getOrCreate(t.getTarget()); Edge edge = new Edge(graph, from, to); String label = t.toString().replaceAll("\n", "\\\\l"); edge.setAttribute("label", t.condition + " Push: " + t.isPushOnStack() + "\\l" + label); edge.setAttribute("color", context.direction == AnalysisDirection.FORWARDS ? "red" : "blue"); edge.setAttribute("fontcolor", context.direction == AnalysisDirection.FORWARDS ? "red" : "blue"); graph.addEdge(edge); } }
2,868
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
StateTransition.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/src/flow/twist/states/StateTransition.java
package flow.twist.states; import soot.SootMethod; import soot.Unit; import fj.data.List; import flow.twist.path.PathElement; public class StateTransition { // FIXME: Declaring class is missing public final SootMethod condition; private final boolean isPushOnStack; private final List<PathElement> path; private StateNode source; private StateNode target; public final Unit connectingUnit; public StateTransition(SootMethod condition, boolean isPushOnStack, List<PathElement> path, Unit connectingUnit) { super(); this.condition = condition; this.isPushOnStack = isPushOnStack; this.path = path; this.connectingUnit = connectingUnit; } public StateNode getSource() { return source; } public void setSource(StateNode source) { this.source = source; } public StateNode getTarget() { return target; } public void setTarget(StateNode target) { this.target = target; } public boolean isPushOnStack() { return isPushOnStack; } public List<PathElement> getPath() { return path; } @Override public String toString() { StringBuilder builder = new StringBuilder(); for (PathElement p : path) { builder.append(p.toString()); builder.append("\n"); } return builder.toString(); } }
1,241
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
StateMachineBasedPathReporter.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/src/flow/twist/states/StateMachineBasedPathReporter.java
package flow.twist.states; import static flow.twist.trackable.Zero.ZERO; import java.util.LinkedList; import java.util.List; import java.util.Set; import soot.SootMethod; import soot.Unit; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import flow.twist.config.AnalysisContext; import flow.twist.path.Path; import flow.twist.path.PathElement; import flow.twist.reporter.IfdsReporter; import flow.twist.reporter.DelayingReporter; import flow.twist.reporter.Report; import flow.twist.states.StateCache.ContextStateCache; import flow.twist.states.StateCache.StateMetadataWrapper; import flow.twist.states.StateCache.StatePopNode; import flow.twist.states.StateCache.StatePushNode; import flow.twist.states.StateCache.StateSinkNode; import flow.twist.trackable.ReturnEdgeTaint; import flow.twist.trackable.Trackable; import flow.twist.util.ImmutableLinkedHashSet; /** * * Does only work correctly if used within a {@link DelayingReporter}, because * it assumes that reported trackables will not change after the time they are * reported. */ public class StateMachineBasedPathReporter implements IfdsReporter { private final Set<Path> validPaths = Sets.newHashSet(); private Stopwatch reportWatch; private StateCache globalStateCache = new StateCache(); private int reportsProcessed = 0; public StateCache getStateCache() { return globalStateCache; } @Override public void analysisFinished() { if (reportWatch != null) System.out.println("Building states: " + reportWatch.stop()); Stopwatch watch = new Stopwatch().start(); collapseReturnStates(); System.out.println("Collapsing return nodes: " + watch.stop()); watch = new Stopwatch().start(); buildPathsFromStates(); System.out.println("Matching paths: " + watch.stop()); } private void collapseReturnStates() { for (ContextStateCache stateCache : globalStateCache.getAll()) { Set<StatePopNode> worklist = Sets.newHashSet(stateCache.getAllPopStates()); while (!worklist.isEmpty()) { collapseState(worklist.iterator().next(), worklist); } } } private void collapseState(StatePopNode current, Set<StatePopNode> worklist) { for (StateTransition incTrans : current.getIncoming()) { if (incTrans.getSource() instanceof StatePopNode && incTrans.getSource() != current) { collapseState((StatePopNode) incTrans.getSource(), worklist); return; } } worklist.remove(current); Set<StateNode> previousStates = Sets.newHashSet(); for (StateTransition incTrans : current.getIncoming()) { StateNode previousState = incTrans.getSource(); if (previousState == current) continue; previousStates.add(previousState); for (StateTransition newPrevTrans : previousState.getIncoming()) { buildCombinedTransitions(newPrevTrans, incTrans, current.getOutgoing()); } } current.removeAllConnectionsRecursively(); } private void buildCombinedTransitions(StateTransition first, StateTransition middle, List<StateTransition> allLast) { for (StateTransition last : allLast) { fj.data.List<PathElement> currentPath = AutomataMatcher.appendPath(last.getPath(), middle); currentPath = AutomataMatcher.appendPath(currentPath, first); StateTransition transition = new StateTransition(first.condition, first.isPushOnStack(), currentPath, first.connectingUnit); first.getSource().addOutgoingTransition(transition); last.getTarget().addIncomingTransition(transition); } } private void buildPathsFromStates() { AutomataMatcher matcher = new AutomataMatcher(globalStateCache); validPaths.addAll(matcher.getValidPaths()); } public Set<Path> getValidPaths() { return validPaths; } @Override public void reportTrackable(Report report) { if (reportWatch == null) reportWatch = new Stopwatch().start(); Set<Trackable> uniqueTrackablesSeen = Sets.newIdentityHashSet(); ContextStateCache stateCache = globalStateCache.get(report.context); LinkedList<StateWorklistItem> workQueue = Lists.newLinkedList(); StateNode startNode = stateCache.getOrCreateStartState(report.context.icfg.getMethodOf(report.targetUnit)); workQueue.add(new StateWorklistItem(null, null, new Predecessor(report.targetUnit, report.trackable), new StateTransitionBuilder(report.context, startNode, true, report.context.icfg.getMethodOf(report.targetUnit), 0 /* * TODO set to 1 , and remove handling in updatePath */))); int processed = 0; while (!workQueue.isEmpty()) { if (workQueue.getLast().unit != null && report.context.icfg.getMethodOf(workQueue.getLast().unit).toString().contains("interpretLoop")) { workQueue.removeLast(); continue; } uniqueTrackablesSeen.add(workQueue.getLast().trackable); processed++; if (processed % 100000 == 0) System.out.println("Reports processed: " + reportsProcessed + "; Current report: Processed work items: " + uniqueTrackablesSeen.size() + " / " + processed + " - WorkQueue size: " + workQueue.size()); WorklistItemWorker worker = new WorklistItemWorker(stateCache, workQueue.removeLast()); worker.start(); worker.updateQueue(workQueue); } reportsProcessed++; } private static class WorklistItemWorker { private StateWorklistItem currentWork; private AnalysisContext context; private ContextStateCache stateCache; private boolean createPredecessingWorkItems = true; private StateTransitionBuilder newTransitionBuilder; private ImmutableLinkedHashSet<PathElement> newPath; private ImmutableLinkedHashSet<PathElement> updatedPath; public WorklistItemWorker(ContextStateCache stateCache, StateWorklistItem currentWork) { this.context = stateCache.context; this.stateCache = stateCache; this.currentWork = currentWork; } public void start() { setTransitionCondition(); createUpdatedPath(); if (isPushEdge()) { processPushEdge(); } else if (isPopEdge()) { processPopEdge(); } else { processInterproceduralEdge(); } if (isAtSink()) { processSink(); } } public void updateQueue(List<StateWorklistItem> queue) { if (!createPredecessingWorkItems) return; Set<Predecessor> workPredecessors = findUnequalPredecessors(currentWork.predecessor.trackable); for (Predecessor predecessor : workPredecessors) { queue.add(new StateWorklistItem(currentWork.predecessor.trackable, currentWork.predecessor.connectingUnit, predecessor, newPath, newTransitionBuilder)); } } private void setTransitionCondition() { if (currentWork.trackable instanceof ReturnEdgeTaint) { currentWork.stateTransitionBuilder = currentWork.stateTransitionBuilder.withCondition(context.icfg .getMethodOf(currentWork.predecessor.connectingUnit)); } } private boolean isPushEdge() { return currentWork.predecessor.trackable instanceof ReturnEdgeTaint; } private void processPushEdge() { StateMetadataWrapper<StatePushNode> pushNode = stateCache.getOrCreatePushState((ReturnEdgeTaint) currentWork.predecessor.trackable); ReturnEdgeTaint taint = (ReturnEdgeTaint) currentWork.predecessor.trackable; ImmutableLinkedHashSet<PathElement> path = updatedPath .add(new PathElement(taint.callSite, taint, currentWork.predecessor.connectingUnit)); StateTransition transition = currentWork.stateTransitionBuilder.build(path.asList(), currentWork.predecessor.connectingUnit); pushNode.get().addIncomingTransition(transition); if (!pushNode.wasCreated()) createPredecessingWorkItems = false; newPath = ImmutableLinkedHashSet.empty(); newTransitionBuilder = new StateTransitionBuilder(context, pushNode.get(), true, 1); } private boolean isPopEdge() { if (currentWork.unit == null) return false; SootMethod toMethod = context.icfg.getMethodOf(currentWork.predecessor.connectingUnit); for (Predecessor pred : findUnequalPredecessors(currentWork.predecessor.trackable)) { SootMethod fromMethod = context.icfg.getMethodOf(pred.connectingUnit); if (!toMethod.equals(fromMethod)) return true; } return false; } private void processPopEdge() { StateMetadataWrapper<StatePopNode> node = stateCache.getOrCreatePopState(currentWork.trackable); StateTransition transition = currentWork.stateTransitionBuilder.build(updatedPath.asList(), currentWork.predecessor.connectingUnit); node.get().addIncomingTransition(transition); if (!node.wasCreated()) createPredecessingWorkItems = false; newTransitionBuilder = new StateTransitionBuilder(context, node.get(), false, 1); newPath = ImmutableLinkedHashSet.empty(); } private void processInterproceduralEdge() { newPath = updatedPath; newTransitionBuilder = currentWork.stateTransitionBuilder; } private boolean isAtSink() { return currentWork.predecessor.trackable == ZERO; } private void processSink() { StateSinkNode node = stateCache.getSinkState(currentWork.predecessor.connectingUnit); StateWorklistItem sinkItem = new StateWorklistItem(currentWork.predecessor.trackable, currentWork.predecessor.connectingUnit, null, newPath, newTransitionBuilder); StateTransition transition = sinkItem.buildTransition(); node.addIncomingTransition(transition); createPredecessingWorkItems = false; } private void createUpdatedPath() { if (currentWork.trackable == null) { updatedPath = currentWork.currentPath; return;// start worklist item } PathElement pathElement = new PathElement(currentWork.predecessor.connectingUnit, currentWork.trackable, currentWork.unit); if (currentWork.currentPath.contains(pathElement)) createPredecessingWorkItems = false; // loop updatedPath = currentWork.currentPath.add(pathElement); } private Set<Predecessor> findUnequalPredecessors(Trackable startPoint) { Set<Predecessor> results = Sets.newHashSet(); Set<Trackable> visitedTrackables = Sets.newIdentityHashSet(); List<Trackable> worklist = Lists.newLinkedList(); worklist.add(startPoint); while (!worklist.isEmpty()) { Trackable current = worklist.remove(0); for (Trackable neighbor : current.getSelfAndNeighbors()) { if (neighbor.predecessor == null) continue; if (neighbor.predecessor.equals(startPoint) && neighbor.predecessor.getClass() == startPoint.getClass()) { if (!visitedTrackables.add(neighbor.predecessor)) continue; // recursive path worklist.add(neighbor.predecessor); } else results.add(new Predecessor(neighbor.sourceUnit, neighbor.predecessor)); } } return results; } } private static class StateWorklistItem { private final Unit unit; private final Trackable trackable; private final Predecessor predecessor; private final ImmutableLinkedHashSet<PathElement> currentPath; private StateTransitionBuilder stateTransitionBuilder; public StateWorklistItem(Trackable trackable, Unit unit, Predecessor predecessor, StateTransitionBuilder stateTransitionBuilder) { this.trackable = trackable; this.unit = unit; this.predecessor = predecessor; this.currentPath = ImmutableLinkedHashSet.empty(); this.stateTransitionBuilder = stateTransitionBuilder; } public StateWorklistItem(Trackable trackable, Unit unit, Predecessor predecessor, ImmutableLinkedHashSet<PathElement> currentPath, StateTransitionBuilder stateTransitionBuilder) { this.trackable = trackable; this.unit = unit; this.predecessor = predecessor; this.currentPath = currentPath; this.stateTransitionBuilder = stateTransitionBuilder; } public StateTransition buildTransition() { return stateTransitionBuilder.build(currentPath.asList(), null); } } private static class StateTransitionBuilder { private StateNode sourceNode; private boolean isPushOnStack; private AnalysisContext context; public final SootMethod condition; private final int skipFirstPathElements; private StateTransitionBuilder(AnalysisContext context, StateNode sourceNode, boolean isPushOnStack, int skipFirstPathElements) { this.context = context; this.sourceNode = sourceNode; this.isPushOnStack = isPushOnStack; this.skipFirstPathElements = skipFirstPathElements; condition = null; } private StateTransitionBuilder(AnalysisContext context, StateNode sourceNode, boolean isPushOnStack, SootMethod condition, int skipFirstPathElements) { this.context = context; this.sourceNode = sourceNode; this.isPushOnStack = isPushOnStack; this.condition = condition; this.skipFirstPathElements = skipFirstPathElements; } public StateTransition build(fj.data.List<PathElement> currentPath, Unit connectingUnit) { currentPath = currentPath.reverse().drop(skipFirstPathElements).reverse(); StateTransition transition = new StateTransition(condition, isPushOnStack, currentPath, connectingUnit); sourceNode.addOutgoingTransition(transition); return transition; } public StateTransitionBuilder withCondition(SootMethod condition) { return new StateTransitionBuilder(context, sourceNode, isPushOnStack, condition, skipFirstPathElements); } } static class Predecessor { public final Unit connectingUnit; public final Trackable trackable; public Predecessor(Unit connectingUnit, Trackable trackable) { this.connectingUnit = connectingUnit; this.trackable = trackable; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((connectingUnit == null) ? 0 : connectingUnit.hashCode()); result = prime * result + ((trackable == null) ? 0 : System.identityHashCode(trackable)); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Predecessor other = (Predecessor) obj; if (connectingUnit == null) { if (other.connectingUnit != null) return false; } else if (!connectingUnit.equals(other.connectingUnit)) return false; if (trackable == null) { if (other.trackable != null) return false; } else if (trackable != other.trackable) return false; return true; } } }
14,187
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
Simple.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/Simple.java
package java.lang; public class Simple { private Class<?> nameInput(String name) throws ClassNotFoundException { String n = name; Class<?> clazz = Class.forName(n); return clazz; } public Class<?> wrapper(String name2) throws ClassNotFoundException { return nameInput(name2); } }
296
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
PrimTypes.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/PrimTypes.java
package java.lang; public class PrimTypes { public Class<?> publicMethod() throws ClassNotFoundException { @SuppressWarnings("unused") int x = 5; return Class.forName("soso"); } }
192
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ImpossiblePath.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/ImpossiblePath.java
package java.lang; public class ImpossiblePath { public Class<?> foo(String name, boolean random) throws ClassNotFoundException { Class<?> c = Class.forName(name); Class<?> a = null; Class<?> b = null; if (random) { a = c; } else { b = c; } b = a; return b; } }
289
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
DistinguishPaths.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/DistinguishPaths.java
package java.lang; public class DistinguishPaths { private Class<?> sink(String name) throws ClassNotFoundException { return Class.forName(name); } public Class<?> okMethod(String name) throws ClassNotFoundException { Class<?> result = sink(name); System.out.println(result); Class<?> checkedResult = checkResult(null); return checkedResult; } public Class<?> leakingMethod(String name) throws ClassNotFoundException { Class<?> result = sink(name); Class<?> checkedResult = checkResult(result); return checkedResult; } private Class<?> checkResult(Class<?> result) { return result; } }
617
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
CheckPackageAccess.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/CheckPackageAccess.java
package java.lang; import static sun.reflect.misc.ReflectUtil.checkPackageAccess; public class CheckPackageAccess { public static Class<?> wrapperWithCheck(String n) throws ClassNotFoundException { String name = getNameWithCheck(n); return loadIt(name); } public static Class<?> wrapperWithoutCheck(String n) throws ClassNotFoundException { String name = getNameWithoutCheck(n); return loadIt(name); } @SuppressWarnings("restriction") public static String getNameWithCheck(String className) { checkPackageAccess(className); return className; } private static String getNameWithoutCheck(String className) { return className; } private static Class<?> loadIt(String name) throws ClassNotFoundException { return Class.forName(name); } public static Class<?> wrapperWithCheck() throws ClassNotFoundException { String name = getNameWithCheck(); return loadIt(name); } public static Class<?> wrapperWithoutCheck() throws ClassNotFoundException { String name = getNameWithoutCheck(); return loadIt(name); } @SuppressWarnings("restriction") private static String getNameWithCheck() { String className = "foo"; //this is constant, so don't bother checkPackageAccess(className); return className; } private static String getNameWithoutCheck() { String className = "foo"; //this is constant, so don't bother return className; } }
1,396
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
PermissionCheckNotOnCallstack.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/PermissionCheckNotOnCallstack.java
package java.lang; import static sun.reflect.misc.ReflectUtil.checkPackageAccess; public class PermissionCheckNotOnCallstack { public Class<?> foo(String className) throws ClassNotFoundException { String name = className; bar(name); return Class.forName(name); } private void bar(String name) { checkPackageAccess(name); } }
341
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
DecoratingClassHierarchyWithDifferentBehaviors.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/DecoratingClassHierarchyWithDifferentBehaviors.java
package java.lang; public class DecoratingClassHierarchyWithDifferentBehaviors { public static interface BaseInterface { public Class<?> execute(String name1, String name2) throws ClassNotFoundException; } public static class SubClassA implements BaseInterface { private BaseInterface decoratee; public SubClassA(BaseInterface decoratee) { this.decoratee = decoratee; } @Override public Class<?> execute(String name1, String name2) throws ClassNotFoundException { return decoratee.execute("constant", name2); } } private static class SubClassB implements BaseInterface { private BaseInterface decoratee; private SubClassB(BaseInterface decoratee) { this.decoratee = decoratee; } @Override public Class<?> execute(String name1, String name2) throws ClassNotFoundException { return decoratee.execute(name2, name1); } } public static class SubClassC implements BaseInterface { @Override public Class<?> execute(String name1, String name2) throws ClassNotFoundException { return Class.forName(name1); } } }
1,071
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
RecursivePopState.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/RecursivePopState.java
package java.lang; import java.util.Random; public class RecursivePopState { static boolean random = new Random().nextBoolean(); public static Class<?> foo(String className) throws ClassNotFoundException { Class<?> result = Class.forName(className); return bar(result); } private static Class<?> bar(Class<?> result) { if (random) return bar(result); else return result; } }
399
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
StringConcatenation.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/StringConcatenation.java
package java.lang; public class StringConcatenation { public Class<?> nameInput(String name) throws ClassNotFoundException { name += "0"; return Class.forName(name); } }
179
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
Java7Exploit.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/Java7Exploit.java
package java.lang; import static sun.reflect.misc.ReflectUtil.checkPackageAccess; @SuppressWarnings("restriction") public class Java7Exploit { // taken from com.sun.beans.finder.ClassFinder public static Class<?> java7exploit(String cname) throws ClassNotFoundException { try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { loader = ClassLoader.getSystemClassLoader(); } if (loader != null) { return Class.forName(cname, false, loader); // checked } } catch (ClassNotFoundException exception) { } catch (SecurityException exception) { } return Class.forName(cname); // unchecked } public static Class<?> java7exploitFixed(String name) throws ClassNotFoundException { checkPackageAccess(name); // calls SecurityManager.checkPackageAccess -> // AccessControl.checkPermission(Permission) try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { loader = ClassLoader.getSystemClassLoader(); } if (loader != null) { return Class.forName(name, false, loader); } } catch (ClassNotFoundException exception) { } catch (SecurityException exception) { } return Class.forName(name); } public static Class<?> java7exploitNotFixed(String name, String name2) throws ClassNotFoundException { checkPackageAccess(name); // calls SecurityManager.checkPackageAccess -> // AccessControl.checkPermission(Permission) try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { loader = ClassLoader.getSystemClassLoader(); } if (loader != null) { return Class.forName(name, false, loader); } } catch (ClassNotFoundException exception) { } catch (SecurityException exception) { } return Class.forName(name2); } }
1,848
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
BeanInstantiator.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/BeanInstantiator.java
package java.lang; import javax.management.ReflectionException; import javax.management.RuntimeOperationsException; import com.sun.jmx.mbeanserver.MBeanInstantiator; @SuppressWarnings("restriction") public class BeanInstantiator { public Class<?> findClass(String className, ClassLoader loader) throws ReflectionException { return loadClass(className,loader); } static Class<?> loadClass(String className, ClassLoader loader) throws ReflectionException { Class<?> theClass; if (className == null) { throw new RuntimeOperationsException(new IllegalArgumentException("The class name cannot be null"), "Exception occurred during object instantiation"); } try { if (loader == null) loader = MBeanInstantiator.class.getClassLoader(); if (loader != null) { theClass = Class.forName(className, false, loader); } else { theClass = Class.forName(className); } } catch (ClassNotFoundException e) { throw new ReflectionException(e, "The MBean class could not be loaded"); } return theClass; } }
1,357
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
WhiteboardGraph.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/WhiteboardGraph.java
package java.lang; public class WhiteboardGraph { public Class<?> vulnerable(String s3) throws ClassNotFoundException { String s2 = checkParam(s3); Class<?> r2 = loadIt(s2); Class<?> r3 = checkReturn(r2); return r3; } private Class<?> checkReturn(Class<?> y) { return y; } private Class<?> loadIt(String s) throws ClassNotFoundException { Class<?> ret = Class.forName(s); return ret; } private String checkParam(String x) { return x; } private Class<?> notVulnerable(String s3) throws ClassNotFoundException { if (s3.length() > 10) { Class<?> r1 = loadIt(s3); r1 = null; return r1; } else { Class<?> r2 = loadIt("constant"); return r2; } } public Class<?> notVulnerableWrapper(String s3) throws ClassNotFoundException { return notVulnerable(s3); } }
809
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
Reflection.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/Reflection.java
package java.lang; import java.lang.reflect.Field; import java.security.AccessController; import java.security.PrivilegedAction; public class Reflection { public Field leakField(final Class klass, final String fieldName) { return AccessController.doPrivileged(new PrivilegedAction<Field>() { public Field run() { try { Field field = klass.getDeclaredField(fieldName); assert (field != null); field.setAccessible(true); return field; } catch (SecurityException e) { assert false; } catch (NoSuchFieldException e) { assert false; } return null; } }); } }
617
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
JavaUtil.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/JavaUtil.java
package java.lang; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; public class JavaUtil { public Class<?> hashMap(String name) throws ClassNotFoundException { HashMap<String, String> nameMap = new HashMap<>(); nameMap.put("name", name); Class<?> c = Class.forName(nameMap.get("name")); HashMap<String, Class<?>> classMap = new HashMap<>(); classMap.put("class", c); return classMap.get("class"); } public Class<?> customMap(String name, Map<String, String> nameMap, Map<String, Class<?>> classMap) throws ClassNotFoundException { nameMap.put("name", name); Class<?> c = Class.forName(nameMap.get("name")); classMap.put("class", c); return classMap.get("class"); } public static class CustomMapA<K, V> implements Map<K, V> { @Override public int size() { return 0; } @Override public boolean isEmpty() { return false; } @Override public boolean containsKey(Object key) { return false; } @Override public boolean containsValue(Object value) { return false; } @Override public V get(Object key) { return null; } @Override public V put(K key, V value) { return null; } @Override public V remove(Object key) { return null; } @Override public void putAll(Map<? extends K, ? extends V> m) { } @Override public void clear() { } @Override public Set<K> keySet() { return null; } @Override public Collection<V> values() { return null; } @Override public Set<java.util.Map.Entry<K, V>> entrySet() { return null; } } public static class CustomMapB<K, V> implements Map<K, V> { @Override public int size() { return 0; } @Override public boolean isEmpty() { return false; } @Override public boolean containsKey(Object key) { return false; } @Override public boolean containsValue(Object value) { return false; } @Override public V get(Object key) { return null; } @Override public V put(K key, V value) { return null; } @Override public V remove(Object key) { return null; } @Override public void putAll(Map<? extends K, ? extends V> m) { } @Override public void clear() { } @Override public Set<K> keySet() { return null; } @Override public Collection<V> values() { return null; } @Override public Set<java.util.Map.Entry<K, V>> entrySet() { return null; } } }
2,470
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
DoPrivileged.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/DoPrivileged.java
package java.lang; import java.security.AccessController; import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import sun.reflect.misc.ReflectUtil; public class DoPrivileged { public Class<?> callable1(final String className) { return AccessController.doPrivileged(new PrivilegedAction<Class<?>>() { @Override public Class<?> run() { try { return foo(className); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } }); } public Class<?> callable2(final String className) throws PrivilegedActionException { return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() { @Override public Class<?> run() throws Exception { return foo(className); } }); } private Class<?> foo(String className) throws ClassNotFoundException { ReflectUtil.checkPackageAccess(className); return Class.forName(className); } }
990
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ClassHierarchySimple.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/ClassHierarchySimple.java
package java.lang; public class ClassHierarchySimple { public static Class<?> foo(String className) throws ClassNotFoundException { A a = new B(); return a.test(className); } private static class A { Class<?> test(String className) throws ClassNotFoundException { return Class.forName(className); } } private static class B extends A { @Override Class<?> test(String className) throws ClassNotFoundException { return Class.forName(className); } } }
480
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
CallerClassLoader.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/CallerClassLoader.java
package java.lang; import sun.reflect.Reflection; public class CallerClassLoader { public Class<?> okMethod(String name) throws ClassNotFoundException { return Class.forName(name, true, ClassLoader.getClassLoader(Reflection.getCallerClass())); } public Class<?> problematicMethod(String name) throws ClassNotFoundException { return Class.forName(name, true, ClassLoader.getClassLoader(Reflection.getCallerClass())); } public Class<?> leakingMethod(String name) throws ClassNotFoundException { return problematicMethod(name); } }
547
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ValidPathCheck.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/ValidPathCheck.java
package java.lang; public class ValidPathCheck { private static Class<?> c(String className) throws ClassNotFoundException { return Class.forName(className); } private static Class<?> b(String paramClassName) throws ClassNotFoundException { String className = d(paramClassName); return c(className); } public static Class<?> a(String className) throws ClassNotFoundException { return b(className); } private static String d(String paramClassName) { return paramClassName; } public static String e(String className) { return d(className); } }
570
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
RecursionAndClassHierarchy.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/RecursionAndClassHierarchy.java
package java.lang; import java.util.Random; public class RecursionAndClassHierarchy { public static interface BaseInterface { public Class<?> execute(String name) throws ClassNotFoundException; } public static class SubClassA implements BaseInterface { public SubClassA decoratee; @Override public Class<?> execute(String name) throws ClassNotFoundException { if (new Random().nextBoolean()) return decoratee.execute(name); else return decoratee.execute(name); } } public static class SubClassB extends SubClassA { public BaseInterface decoratee; @Override public Class<?> execute(String name) throws ClassNotFoundException { if (new Random().nextBoolean()) return decoratee.execute(name); else return decoratee.execute(name); } } static class SubClassC extends SubClassA { @Override public Class<?> execute(String name) throws ClassNotFoundException { return Class.forName(name); } } }
962
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
PrivateMethod.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/PrivateMethod.java
package java.lang; public class PrivateMethod { public Class<?> leakingMethod3(String name) throws ClassNotFoundException { return privateMethod(name); } private Class<?> privateMethod(String name) throws ClassNotFoundException { return Class.forName(name); } }
276
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
SourceOnCallstack.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/SourceOnCallstack.java
package java.lang; public final class SourceOnCallstack { public Class<?> baz(String name) throws ClassNotFoundException { //error here name = bar(name); return foo(name); } private Class<?> foo(String name) throws ClassNotFoundException { return Class.forName(name); } public String bar(String name) { return name; } }
342
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
PermissionCheckNotOnAllPaths.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/PermissionCheckNotOnAllPaths.java
package java.lang; import static sun.reflect.misc.ReflectUtil.checkPackageAccess; public class PermissionCheckNotOnAllPaths { public Class<?> foo(String className) throws ClassNotFoundException { if (className.length() > 1) { String name = className; bar(name); } return Class.forName(className); } private void bar(String name) { checkPackageAccess(name); } }
383
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ExceptionalPath.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/ExceptionalPath.java
package java.lang; public class ExceptionalPath { public static Class<?> test(String className) { return delegate(className); } private static Class<?> delegate(String className) { try { return Class.forName(className); } catch (ClassNotFoundException e) { return null; } catch (Exception e) { throw new RuntimeException(); } } }
356
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
Aliasing.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/Aliasing.java
package java.lang; public class Aliasing { static class A { String f; } static class B { String f; } static class C extends A { } // here we assume that "name" may be tainted because we // only use a dumb pointer analysis // name2 should not be tainted, though, because B is of a different type public Class<?> nameInput(String name, String name2, String name3) throws ClassNotFoundException { A a1 = new A(); A a2 = new A(); B b = new B(); C c = new C(); c.f = name3; b.f = name2; a1.f = name; String arg = a2.f; return Class.forName(arg); } // name is tainted; name2 not public Class<?> nameInput2(String name, String name2) throws ClassNotFoundException { String[] a1 = new String[] { name }; String[] a2 = new String[] { name2 }; @SuppressWarnings("unused") String s = a2[0]; return Class.forName(a1[0]); } }
866
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
Loop.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/Loop.java
package java.lang; public class Loop { public static Class<?> foo(String className) throws ClassNotFoundException { Class<?> forName = Class.forName(className); Class[] result = new Class[10]; for (int i = 0; i < 10; i++) { result[i] = forName; } return result[0]; } }
286
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
MultipleSinksInSameContext.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/MultipleSinksInSameContext.java
package java.lang; public class MultipleSinksInSameContext { public static boolean random; public static Class<?> bar(String name) throws ClassNotFoundException { return foo(name); } private static Class<?> foo(String name) throws ClassNotFoundException { if (random) { Class<?> c1 = Class.forName(name); return c1; } else { Class<?> c2 = Class.forName(name); return c2; } } }
406
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
Recursion.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/Recursion.java
package java.lang; public class Recursion { public static Class<?> recursive(String className) throws ClassNotFoundException { Class<?> result = Class.forName(className); if (result == null) { Class<?> recResult = recursive(className); return recResult; } else return result; } public static Class<?> recursiveA(String className) throws ClassNotFoundException { if (className.length() > 10) return recursiveB(className); else return Class.forName(className); } private static Class<?> recursiveB(String className) throws ClassNotFoundException { if (className.length() < 10) return recursiveA(className); else return recursiveB(className); } }
689
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ClassInstanceCastedBeforeReturned.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/ClassInstanceCastedBeforeReturned.java
package java.lang; import java.lang.reflect.InvocationTargetException; import java.util.List; @SuppressWarnings("rawtypes") public class ClassInstanceCastedBeforeReturned { public Object newInstance(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Class<?> clazz = Class.forName(name); List result = (List) clazz.newInstance(); return result; } public Object explicitConstructor(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { Class<?> clazz = Class.forName(name); List result = (List) clazz.getConstructor().newInstance(); return result; } public Object allConstructors(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException { Class<?> clazz = Class.forName(name); List result = (List) clazz.getConstructors()[0].newInstance(); return result; } }
1,075
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
NotReturnedValue.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/NotReturnedValue.java
package java.lang; public class NotReturnedValue { public void instantiate(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Class<?> clazz = Class.forName(name); Object newInstance = clazz.newInstance(); newInstance.toString(); } }
286
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
HiddenClass.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/HiddenClass.java
package java.lang; class HiddenClass { HiddenClass() { } public Class<?> uncheckedMethod(String name123) throws ClassNotFoundException { return Class.forName(name123); } }
185
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
BackwardsIntoThrow.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/BackwardsIntoThrow.java
package java.lang; public class BackwardsIntoThrow { public Class<?> foo(String name) throws ClassNotFoundException { String checkedName = checkParam(name); return Class.forName(checkedName); } private String checkParam(String name) { if (name.length() > 5) throw new IllegalArgumentException(); else return name; } }
339
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
CallBack.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/CallBack.java
package java.lang; public class CallBack { public Class<?> privateMethodOverwriteable(String name) throws ClassNotFoundException { return Class.forName(getPublicName()); } public String getPublicName() { return null; } }
235
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ClassInstanceReturned.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/ClassInstanceReturned.java
package java.lang; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; public class ClassInstanceReturned { public Object newInstance(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Class<?> clazz = Class.forName(name); Object result = clazz.newInstance(); return result; } public Object explicitConstructor(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { Class<?> clazz = Class.forName(name); Constructor<?> constructor = clazz.getConstructor(); Object result = constructor.newInstance(); return result; } public Object allConstructors(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException { Class<?> clazz = Class.forName(name); Object result = clazz.getConstructors()[0].newInstance(); return result; } }
1,077
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ClassHierarchyHard.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/ClassHierarchyHard.java
package java.lang; public class ClassHierarchyHard { public static Class<?> invokeable(String inv_className, A a) throws ClassNotFoundException { String inv_name = a.test(inv_className); return Class.forName(inv_name); } public static Class<?> redundantInvokeable(String red_className, A a) throws ClassNotFoundException { String red_name = a.test(red_className); return Class.forName(red_name); } private static class A { String test(String a_param) throws ClassNotFoundException { String a_test_name = "Constant"; return a_test_name; } } private static class B extends A { @Override String test(String b_test_name) throws ClassNotFoundException { return b_test_name; } } }
716
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
SummaryFunction.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/SummaryFunction.java
package java.lang; public class SummaryFunction { public Class<?> foo(String name) throws ClassNotFoundException { Class<?> clazz = Class.forName(name); Class<?> id = id(clazz); return id; } public Class<?> bar(String name) throws ClassNotFoundException { Class<?> clazz = Class.forName(name); Class<?> id = id(clazz); return id; } private Class<?> id(Class<?> param) { Class<?> result = param; return result; } }
440
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
Switch.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/Switch.java
package java.lang; public class Switch { public static Class<?> foo(String className) throws ClassNotFoundException { while (className.length() == 0) { switch (className.length()) { case 0: className += "0"; break; case 1: className += "1"; break; case 2: case 3: case 4: break; default: break; } } return Class.forName(className); } }
394
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
RecursionClassAsParameter.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/RecursionClassAsParameter.java
package java.lang; public class RecursionClassAsParameter { public Class<?> foo(String name) throws ClassNotFoundException { Class<?> c = Class.forName(name); recursive(c); return c; } private void recursive(Class<?> c) { if (c.getName().length() > 10) recursive(c); } }
290
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ReturnEdgeMerge.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/ReturnEdgeMerge.java
package java.lang; public class ReturnEdgeMerge { public Class<?> foo(String name, boolean random1, boolean random2) throws ClassNotFoundException { Class<?> result = Class.forName(name); if (random1) { result = foo(name, true, true); } else if (random2) { result = bar(result); } return result; } private Class<?> bar(Class<?> c) { return c; } }
373
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
MultipleReturns.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/MultipleReturns.java
package java.lang; public class MultipleReturns { public static Class<?> test(String className) throws ClassNotFoundException { String name = foo(className); return Class.forName(name); } private static String foo(String className) { if (className.length() > 50) return className; else return "something" + className; } }
343
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
MultipleClasses.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/MultipleClasses.java
package java.lang; public class MultipleClasses { public Class<?> leakingMethod(String name) throws ClassNotFoundException { return new HiddenClass().uncheckedMethod(name); } }
184
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
MergeTest.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/MergeTest.java
package java.lang; public class MergeTest { public void a(String className) throws ClassNotFoundException { b(className); c(className); } private void b(String className) throws ClassNotFoundException { Class.forName(className); } private void c(String className) throws ClassNotFoundException { Class.forName(className); } }
344
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
UseExistingSummary.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/java/lang/UseExistingSummary.java
package java.lang; public class UseExistingSummary { public Class<?> foo(String name) throws ClassNotFoundException { Class<?> c = Class.forName(name); Class<?> d = bar(c); Class<?> e = bar(d); return e; } private Class<?> bar(Class<?> c) { return c; } }
272
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
CombiningMultipleTargets.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/callersensitive/CombiningMultipleTargets.java
package callersensitive; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; public class CombiningMultipleTargets { public Object foo(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Class<?> clazz = Class.forName(name); Object instance = instantiate(clazz); return instance; } private Object instantiate(Class<?> clazz) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Constructor<?>[] constructors = clazz.getConstructors(); Object instance = constructors[0].newInstance(); return instance; } }
719
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
Confidentiality.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/callersensitive/Confidentiality.java
package callersensitive; import sun.reflect.CallerSensitive; @SuppressWarnings("restriction") public class Confidentiality { @CallerSensitive public static Object dangerous() { return new Object(); } public static Object foo() { return dangerous(); } }
266
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
Integrity.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/callersensitive/Integrity.java
package callersensitive; import sun.reflect.CallerSensitive; @SuppressWarnings("restriction") public class Integrity { @CallerSensitive public static void dangerous(Object o) { } public static void foo(Object o) { dangerous(o); } }
243
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
IntegrityAndConfidentiality.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/callersensitive/IntegrityAndConfidentiality.java
package callersensitive; import sun.reflect.CallerSensitive; @SuppressWarnings("restriction") public class IntegrityAndConfidentiality { @CallerSensitive public static Object dangerous(Object o) { return new Object(); } public static Object foo(Object o) { return dangerous(o); } }
295
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
InitiallyDeclaredMethodTests.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/analysisutil/InitiallyDeclaredMethodTests.java
package analysisutil; public class InitiallyDeclaredMethodTests { public static interface I { public void inInterface(); } public static interface J extends I { } public static class A implements I { public void inInterface() { } public void inSuperType() { } } public static class B extends A { @Override public void inInterface() { super.inInterface(); } @Override public void inSuperType() { super.inSuperType(); } public void inCurrentType() { } } public static class C implements J { @Override public void inInterface() { } } public static class D extends B { } public static class E extends D { @Override public void inSuperType() { super.inSuperType(); } } }
744
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
SubTypeTests.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/analysisutil/SubTypeTests.java
package analysisutil; public class SubTypeTests { public static class A { } public static class B extends A { public String helloWorld() { return "hello"; } } public static interface I { } public static class J implements I { } }
253
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ParameterWithTaintedField.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/typestate/ParameterWithTaintedField.java
package typestate; public class ParameterWithTaintedField { public static class DataStruct { String className; } public static Class<?> foo(DataStruct ds) throws ClassNotFoundException { return Class.forName(ds.className); } }
238
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
PreInitializeStatic.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/typestate/PreInitializeStatic.java
package typestate; public class PreInitializeStatic { private static String name; public static void set(String _name) { name = _name; } public static Class<?> retrieve() throws ClassNotFoundException { return Class.forName(name); } }
248
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
PreInitializeInstance.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/typestate/PreInitializeInstance.java
package typestate; public class PreInitializeInstance { private String name; public void set(String name) { this.name = name; } public Class<?> retrieve() throws ClassNotFoundException { return Class.forName(name); } }
232
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ThreePhasesRetrieval.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/typestate/ThreePhasesRetrieval.java
package typestate; public class ThreePhasesRetrieval { private String name; private Class<?> clazz; public void set(String name) { this.name = name; } public void load() throws ClassNotFoundException { clazz = Class.forName(name); } public Class<?> retrieve() { return clazz; } }
299
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ForwardThroughGeneric.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/generics/ForwardThroughGeneric.java
package generics; public class ForwardThroughGeneric { public Class<?> foo(String name, A<Class<?>> a) throws ClassNotFoundException { Class<?> clazz = Class.forName(name); Class<?> result = a.id(clazz); return result; } public static interface A<T> { T id(T t); } public static class B implements A<Class<?>> { @Override public Class<?> id(Class<?> t) { return t; } } public static class C implements A<Integer> { @Override public Integer id(Integer t) { return t; } } }
513
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
BackwardOutOfGeneric.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/generics/BackwardOutOfGeneric.java
package generics; public class BackwardOutOfGeneric { public void string(String name, A<String> a) throws ClassNotFoundException { a.foo(name); } public void integer(Integer name, A<Integer> a) throws ClassNotFoundException { a.foo(name); } public void object(Object name, A<Object> a) throws ClassNotFoundException { a.foo(name); } public static interface A<T> { void foo(T t) throws ClassNotFoundException; } public static class B implements A<String> { @Override public void foo(String t) throws ClassNotFoundException { Class<?> c = Class.forName(t); } } }
595
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
BackwardThroughGeneric.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/generics/BackwardThroughGeneric.java
package generics; import java.lang.Class; import java.lang.ClassNotFoundException; import java.lang.Integer; import java.lang.Object; import java.lang.Override; import java.lang.String; public class BackwardThroughGeneric { public Class<?> foo(String name, A<String> a) throws ClassNotFoundException { String idName = a.id(name); return Class.forName(idName); } public static interface A<T> { T id(T t); } public static class B implements A<String> { @Override public String id(String t) { return "CONSTANT"; } } public static class C implements A<Integer> { @Override public Integer id(Integer t) { return t; } } }
656
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
ForwardOutOfGeneric.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/generics/ForwardOutOfGeneric.java
package generics; public class ForwardOutOfGeneric { public Class<?> clazz(A<Class<?>> a) throws ClassNotFoundException { return a.foo(); } public Integer integer(A<Integer> a) throws ClassNotFoundException { return a.foo(); } public Object object(A<Object> a) throws ClassNotFoundException { return a.foo(); } public static interface A<T> { T foo() throws ClassNotFoundException; } public static class B implements A<Class<?>> { private String className; @Override public Class<?> foo() throws ClassNotFoundException { return Class.forName(className); } } }
596
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
TypeConversion.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/type/TypeConversion.java
package type; public class TypeConversion { public static Class<?> local(Integer param) throws ClassNotFoundException { Object x = param; return Class.forName((String) x); } public static Class<?> arrayItem(Integer param) throws ClassNotFoundException { Object[] x = new Object[] { param }; return Class.forName((String) x[0]); } public static Class<?> array(Integer param) throws ClassNotFoundException { Object[] x = new Integer[] { param }; return Class.forName((String) x[0]); } }
507
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
StringBuilderTest.java
/FileExtraction/Java_unseen/johanneslerch_FlowTwist/FlowTwist/testcases/type/StringBuilderTest.java
package type; public class StringBuilderTest { public Class<?> leakStringBuilder(StringBuilder a) throws ClassNotFoundException { return Class.forName(a.toString()); } public Class<?> throughStringBuilder(String a) throws ClassNotFoundException { StringBuilder b = new StringBuilder(a); return Class.forName(b.toString()); } public Class<?> trackStringBuilder(String b) throws ClassNotFoundException { String a = b; StringBuilder builder = new StringBuilder(a); StringBuilder alias = builder; return Class.forName(alias.toString()); } }
561
Java
.java
johanneslerch/FlowTwist
9
4
0
2014-03-14T10:26:08Z
2015-02-13T09:54:39Z
GuiLibrary.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/GuiLibrary.java
package com.mcf.davidee.guilib; import java.util.Arrays; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.event.FMLPreInitializationEvent; @Mod(modid = "guilib", name = "GUI Library", version = "1.0.7.2") public class GuiLibrary { @EventHandler public void preInit(FMLPreInitializationEvent event) { ModMetadata modMeta = event.getModMetadata(); modMeta.authorList = Arrays.asList(new String[] { "Davidee" }); modMeta.autogenerated = false; modMeta.credits = "Thanks to Mojang, Forge, and all your support."; modMeta.description = "A small library for creating minecraft GUIs."; modMeta.url = "http://www.minecraftforum.net/topic/1909236-/"; } }
765
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
Tooltip.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/basic/Tooltip.java
package com.mcf.davidee.guilib.basic; import com.mcf.davidee.guilib.core.Widget; import net.minecraft.client.Minecraft; public class Tooltip extends Widget { protected int color, txtColor; private String str; public Tooltip(String text) { super(Minecraft.getMinecraft().fontRenderer.getStringWidth(text) + 4, 12); this.zLevel = 1.0f; this.str = text; this.color = 0xff000000; this.txtColor = 0xffffff; } public Tooltip(String text, int color, int txtColor) { super(Minecraft.getMinecraft().fontRenderer.getStringWidth(text) + 4, 12); this.zLevel = 1.0f; this.str = text; this.color = color; this.txtColor = txtColor; } public void setBackgroundColor(int color) { this.color = color; } public void setTextColor(int color) { this.txtColor = color; } @Override public void draw(int mx, int my) { drawRect(x, y, x + width, y + height, color); drawCenteredString(mc.fontRenderer, str, x + width / 2, y + (height - 8) / 2, txtColor); } @Override public boolean click(int mx, int my) { return false; } }
1,056
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
Label.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/basic/Label.java
package com.mcf.davidee.guilib.basic; import java.util.ArrayList; import java.util.List; import net.minecraft.client.Minecraft; import com.mcf.davidee.guilib.core.Widget; public class Label extends Widget { private String str; private int color, hoverColor; private List<Widget> tooltips; private boolean hover, center; private boolean shadow; private long hoverStart; public Label(String text, int color, int hoverColor, Widget... tooltips) { this(text, color, hoverColor, true, tooltips); } public Label(String text, Widget... tooltips) { this(text, 0xffffff, 0xffffff, true, tooltips); } public Label(String text, int color, int hoverColor, boolean center, Widget... tooltips) { super(getStringWidth(text), 11); this.center = center; this.str = text; this.color = color; this.hoverColor = hoverColor; this.shadow = true; this.tooltips = new ArrayList<Widget>(); for (Widget w : tooltips) this.tooltips.add(w); } public Label(String text, boolean center, Widget... tooltips) { this(text, 0xffffff, 0xffffff, center, tooltips); } public void setColor(int color) { this.color = color; } public void setHoverColor(int hoverColor) { this.hoverColor = hoverColor; } public void setShadowedText(boolean useShadow) { this.shadow = useShadow; } public String getText() { return str; } public void setText(String text) { //Find the center if (center) this.x += width / 2; this.str = text; width = getStringWidth(text); if (center) this.x -= width / 2; } @Override public void draw(int mx, int my) { boolean newHover = inBounds(mx, my); if (newHover && !hover) { hoverStart = System.currentTimeMillis(); //Label is designed for a single tooltip for (Widget w : tooltips) w.setPosition(mx + 3, y + height); } hover = newHover; if (shadow) mc.fontRenderer.drawStringWithShadow(str, x, y + 2, (hover) ? hoverColor : color); else mc.fontRenderer.drawString(str, x, y + 2, (hover) ? hoverColor : color); } @Override public List<Widget> getTooltips() { return (hover && System.currentTimeMillis() - hoverStart >= 500) ? tooltips : super.getTooltips(); } @Override public boolean click(int mx, int my) { return false; } private static int getStringWidth(String text) { return Minecraft.getMinecraft().fontRenderer.getStringWidth(text); } @Override public void setPosition(int x, int y) { this.x = (center) ? x - width / 2 : x; this.y = y; } }
2,482
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
OverlayScreen.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/basic/OverlayScreen.java
package com.mcf.davidee.guilib.basic; public abstract class OverlayScreen extends BasicScreen { protected BasicScreen bg; public OverlayScreen(BasicScreen bg) { super(bg); this.bg = bg; } @Override public void drawBackground() { bg.drawScreen(-1, -1, 0); } @Override protected void revalidateGui() { bg.width = width; bg.height = height; bg.revalidateGui(); } @Override protected void reopenedGui() { } }
436
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
MultiTooltip.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/basic/MultiTooltip.java
package com.mcf.davidee.guilib.basic; import java.util.List; import net.minecraft.client.Minecraft; import com.mcf.davidee.guilib.core.Widget; public class MultiTooltip extends Widget { protected int color, txtColor; private List<String> text; public MultiTooltip(List<String> strings) { super(getMaxStringWidth(strings) + 4, strings.size() * 12); this.text = strings; this.zLevel = 1.0f; this.color = 0xff000000; this.txtColor = 0xffffff; } public MultiTooltip(List<String> strings, int color, int txtColor) { super(getMaxStringWidth(strings) + 4, strings.size() * 12); this.text = strings; this.zLevel = 1.0f; this.color = color; this.txtColor = txtColor; } @Override public void draw(int mx, int my) { drawRect(x, y, x + width, y + height, color); int textY = y + 2; for (String line : text) { mc.fontRenderer.drawStringWithShadow(line, x + 2, textY, txtColor); textY += 11; } } @Override public boolean click(int mx, int my) { return false; } public void setBackgroundColor(int color) { this.color = color; } public void setTextColor(int color) { this.txtColor = color; } public static int getMaxStringWidth(List<String> strings) { Minecraft mc = Minecraft.getMinecraft(); int max = 0; for (String s : strings) { int width = mc.fontRenderer.getStringWidth(s); if (width > max) max = width; } return max; } }
1,406
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
BasicScreen.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/basic/BasicScreen.java
package com.mcf.davidee.guilib.basic; import java.util.ArrayList; import java.util.List; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.MathHelper; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import com.mcf.davidee.guilib.core.Button; import com.mcf.davidee.guilib.core.Button.ButtonHandler; import com.mcf.davidee.guilib.core.Container; import com.mcf.davidee.guilib.core.Widget; /** * * The core GuiScreen - use this class for your GUIs. * */ public abstract class BasicScreen extends GuiScreen { private GuiScreen parent; private boolean hasInit, closed; protected List<Container> containers; protected Container selectedContainer; public BasicScreen(GuiScreen parent) { this.parent = parent; this.containers = new ArrayList<Container>(); } /** * Revalidate this GUI. * Reset your widget locations/dimensions here. */ protected abstract void revalidateGui(); /** * Called ONCE to create this GUI. * Create your containers and widgets here. */ protected abstract void createGui(); /** * Called when this GUI is reopened after being closed. */ protected abstract void reopenedGui(); public GuiScreen getParent() { return parent; } public List<Container> getContainers() { return containers; } public void close() { mc.displayGuiScreen(parent); } /** * Called when the selectedContainer did not capture this keyboard event. * * @param c Character typed (if any) * @param code Keyboard.KEY_ code for this key */ protected void unhandledKeyTyped(char c, int code) { } /** * Called to draw this screen's background */ protected void drawBackground() { drawDefaultBackground(); } @Override public void drawScreen(int mx, int my, float f) { drawBackground(); List<Widget> overlays = new ArrayList<Widget>(); int scale = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight).getScaleFactor(); for (Container c : containers) overlays.addAll(c.draw(mx, my, scale)); for (Widget w : overlays) w.draw(mx, my); } @Override public void updateScreen() { for (Container c : containers) c.update(); } @Override protected void mouseClicked(int mx, int my, int code) { if (code == 0){ for (Container c : containers){ if (c.mouseClicked(mx, my)){ selectedContainer = c; break; } } for (Container c : containers) if (c != selectedContainer) c.setFocused(null); } } @Override protected void mouseMovedOrUp(int mx, int my, int code) { if (code == 0){ for (Container c : containers) c.mouseReleased(mx, my); } } /** * See {@link GuiScreen#handleMouseInput} for more information about mx and my. */ @Override public void handleMouseInput() { super.handleMouseInput(); int delta = Mouse.getEventDWheel(); if (delta != 0) { int mx = Mouse.getEventX() * this.width / this.mc.displayWidth; int my = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; boolean handled = false; delta = MathHelper.clamp_int(delta, -5, 5); for (Container c : containers) { if (c.inBounds(mx, my)) { c.mouseWheel(delta); handled = true; break; } } if (!handled && selectedContainer != null) selectedContainer.mouseWheel(delta); } } @Override public void keyTyped(char c, int code) { boolean handled = (selectedContainer != null) ? selectedContainer.keyTyped(c, code) : false; if (!handled) unhandledKeyTyped(c,code); } @Override public void initGui() { Keyboard.enableRepeatEvents(true); if (!hasInit){ createGui(); hasInit = true; } revalidateGui(); if (closed){ reopenedGui(); closed = false; } } public void drawCenteredStringNoShadow(FontRenderer ft, String str, int cx, int y, int color) { ft.drawString(str, cx - ft.getStringWidth(str) / 2, y, color); } @Override public void onGuiClosed() { closed = true; Keyboard.enableRepeatEvents(false); } public class CloseHandler implements ButtonHandler{ public void buttonClicked(Button button) { close(); } } }
4,193
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
FocusedContainer.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/basic/FocusedContainer.java
package com.mcf.davidee.guilib.basic; import com.mcf.davidee.guilib.core.Container; import com.mcf.davidee.guilib.core.Scrollbar; import com.mcf.davidee.guilib.core.Widget; import com.mcf.davidee.guilib.focusable.FocusableWidget; /** * * A "Focused" version of a Container. * This container will always have a focused widget * as long as there is a focusable widget contained. * */ public class FocusedContainer extends Container { public FocusedContainer() { super(); } public FocusedContainer(Scrollbar scrollbar, int shiftAmount, int extraScrollHeight) { super(scrollbar, shiftAmount, extraScrollHeight); } @Override public void setFocused(FocusableWidget f) { if (f != null) super.setFocused(f); } @Override public void addWidgets(Widget... arr) { super.addWidgets(arr); if (focusIndex == -1 && focusList.size() > 0) { focusIndex = 0; focusList.get(focusIndex).focusGained(); } } }
931
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
FocusableLabel.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/focusable/FocusableLabel.java
package com.mcf.davidee.guilib.focusable; import java.util.ArrayList; import java.util.List; import net.minecraft.client.Minecraft; import com.mcf.davidee.guilib.core.Widget; import com.mcf.davidee.guilib.core.Scrollbar.Shiftable; /** * * A simple focusable label. * */ public class FocusableLabel extends FocusableWidget implements Shiftable { private String str; private int color, hoverColor, focusColor; private List<Widget> tooltips; private boolean hover, center, focused; private Object userData; public FocusableLabel(String text, int color, int hoverColor, int focusColor, Widget... tooltips) { this(text, color, hoverColor, focusColor, true, tooltips); } public FocusableLabel(String text, Widget... tooltips) { this(text,0xffffff,16777120, 0x22aaff, true, tooltips); } public FocusableLabel(String text, int color, int hoverColor, int focusColor, boolean center, Widget... tooltips) { super(getStringWidth(text), 11); this.center = center; this.str = text; this.color = color; this.hoverColor = hoverColor; this.focusColor = focusColor; this.tooltips = new ArrayList<Widget>(); for (Widget w : tooltips) this.tooltips.add(w); } public FocusableLabel(String text, boolean center, Widget... tooltips) { this(text, 0xffffff, 16777120, 0x22aaff, center, tooltips); } public FocusableLabel(int x, int y, String text, Widget... tooltips) { this(text, 0xffffff, 16777120, 0x22aaff, true, tooltips); setPosition(x, y); } public void setColors(int color, int hoverColor, int focusColor) { this.color = color; this.hoverColor = hoverColor; this.focusColor = focusColor; } public void setColor(int color) { this.color = color; } public void setHoverColor(int hoverColor) { this.hoverColor = hoverColor; } public void setFocusColor(int focusColor) { this.focusColor = focusColor; } public String getText() { return str; } public void setText(String text) { if (center) this.x += width/2; this.str = text; width = getStringWidth(text); if (center) this.x -= width/2; } public void setUserData(Object data) { userData = data; } public Object getUserData() { return userData; } @Override public void draw(int mx, int my) { boolean newHover = inBounds(mx,my); if (newHover && !hover) { for (Widget w : tooltips) w.setPosition(mx+3, y + height); } hover = newHover; if (focused) drawRect(x, y, x+width, y+height, 0x99999999); mc.fontRenderer.drawStringWithShadow(str, x, y + 2, (focused) ? focusColor : (hover) ? hoverColor : color); } @Override public List<Widget> getTooltips() { return (hover) ? tooltips : super.getTooltips(); } @Override public boolean click(int mx, int my) { return inBounds(mx,my); } private static int getStringWidth(String text) { return Minecraft.getMinecraft().fontRenderer.getStringWidth(text); } @Override public void setPosition(int x, int y) { this.x = (center) ? x - width/2 : x; this.y = y; } @Override public void shiftY(int dy) { this.y += dy; } @Override public void focusGained() { focused = true; } @Override public void focusLost() { focused = false; } }
3,194
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
FocusableSpecialLabel.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/focusable/FocusableSpecialLabel.java
package com.mcf.davidee.guilib.focusable; import com.mcf.davidee.guilib.core.Widget; /** * * A FocusableLabel that is meant to display different text * than what it really means in the background. * */ public class FocusableSpecialLabel extends FocusableLabel { private String actualText; public FocusableSpecialLabel(String text, String actualText, Widget... tooltips) { super(text, tooltips); this.actualText = actualText; } public FocusableSpecialLabel(int x, int y, String text, String actualText, Widget... tooltips) { this(text, actualText, tooltips); setPosition(x,y); } public String getSpecialText() { return actualText; } public void setSpecialText(String str) { this.actualText = str; } }
737
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
FocusableWidget.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/focusable/FocusableWidget.java
package com.mcf.davidee.guilib.focusable; import com.mcf.davidee.guilib.core.Widget; /** * A Focusable Widget. * This widget can gain and lose focus. * */ public abstract class FocusableWidget extends Widget { public FocusableWidget(int width, int height) { super(width, height); } public FocusableWidget(int x, int y, int width, int height) { super(x, y, width, height); } public abstract void focusGained(); public abstract void focusLost(); }
473
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
Slider.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/core/Slider.java
package com.mcf.davidee.guilib.core; import net.minecraft.util.MathHelper; /** * * Abstract representation of a minecraft slider. * */ public abstract class Slider extends Widget { public interface SliderFormat { String format(Slider slider); } protected SliderFormat format; protected float value; protected boolean dragging; public Slider(int width, int height, float value, SliderFormat format) { super(width, height); this.value = MathHelper.clamp_float(value, 0, 1); this.format = format; } @Override public boolean click(int mx, int my) { if (inBounds(mx, my)) { value = (float) (mx - (this.x + 4)) / (float) (this.width - 8); value = MathHelper.clamp_float(value, 0, 1); dragging = true; return true; } return false; } @Override public void handleClick(int mx, int my) { value = (float) (mx - (this.x + 4)) / (float) (this.width - 8); value = MathHelper.clamp_float(value, 0, 1); dragging = true; } @Override public void mouseReleased(int mx, int my) { dragging = false; } public float getValue() { return value; } }
1,095
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
Button.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/core/Button.java
package com.mcf.davidee.guilib.core; /** * * Abstract representation of a minecraft button. * The buttons calls handler.buttonClicked(this) when it is pressed. * */ public abstract class Button extends Widget { public interface ButtonHandler { void buttonClicked(Button button); } protected ButtonHandler handler; public Button(int width, int height, ButtonHandler handler) { super(width, height); this.handler = handler; } @Override public boolean click(int mx, int my) { return enabled && inBounds(mx, my); } @Override public void handleClick(int mx, int my) { if (handler != null) handler.buttonClicked(this); } public void setEnabled(boolean flag) { this.enabled = flag; } public String getText() { return ""; } public void setText(String str) { } }
805
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
Checkbox.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/core/Checkbox.java
package com.mcf.davidee.guilib.core; /** * * Abstract representation of a checkbox. * */ public abstract class Checkbox extends Widget { protected String str; protected boolean check; public Checkbox(int width, int height, String text) { super(width, height); this.str = text; } public Checkbox(int width, int height, String text, boolean checked) { this(width, height, text); this.check = checked; } @Override public boolean click(int mx, int my) { return inBounds(mx, my); } @Override public void handleClick(int mx, int my) { check = !check; } public boolean isChecked() { return check; } public void setChecked(boolean checked) { this.check = checked; } }
709
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
Scrollbar.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/core/Scrollbar.java
package com.mcf.davidee.guilib.core; import org.lwjgl.input.Mouse; /** * * Abstract representation of a scrollbar. * */ public abstract class Scrollbar extends Widget { public interface Shiftable { void shiftY(int dy); } protected int yClick; protected Container container; private int topY, bottomY; private int offset; public Scrollbar(int width) { super(width, 0); yClick = -1; } protected abstract void shiftChildren(int dy); protected abstract void drawBoundary(int x, int y, int width, int height); protected abstract void drawScrollbar(int x, int y, int width, int height); public void revalidate(int topY, int bottomY) { this.topY = topY; this.bottomY = bottomY; this.height = bottomY - topY; int heightDiff = getHeightDifference(); if (offset != 0 && heightDiff <= 0) offset = 0; if (heightDiff > 0 && offset < -heightDiff) offset = -heightDiff; if (offset != 0) shiftChildren(offset); } public void onChildRemoved() { int heightDiff = getHeightDifference(); if (offset != 0) { if (heightDiff <= 0) { shiftChildren(-offset); offset = 0; } else if (offset < -heightDiff) { shiftChildren(-heightDiff - offset); offset = -heightDiff; } } } public void setContainer(Container c) { this.container = c; } protected int getHeightDifference() { return container.getContentHeight() - (bottomY - topY); } protected int getLength() { if (container.getContentHeight() == 0) return 0; int length = (bottomY - topY) * (bottomY - topY) / container.getContentHeight(); if (length < 32) length = 32; if (length > bottomY - topY - 8) // Prevent it from getting too big length = bottomY - topY - 8; return length; } @Override public void draw(int mx, int my) { int length = getLength(); if (Mouse.isButtonDown(0)) { if (yClick == -1) { if (inBounds(mx, my)) { yClick = my; } } else { float scrollMultiplier = 1.0F; int diff = getHeightDifference(); if (diff < 1) diff = 1; scrollMultiplier /= (bottomY - topY - length) / (float)diff; shift((int) ((yClick - my) * scrollMultiplier)); yClick = my; } } else yClick = -1; drawBoundary(x, topY, width, height); int y = -offset * (bottomY - topY - length) / getHeightDifference() + (topY); if (y < topY) y = topY; drawScrollbar(x, y, width, length); } @Override public boolean click(int mx, int my) { return false; } @Override public boolean shouldRender(int topY, int bottomY) { return getHeightDifference() > 0; } /** * Shifts this scrollbar relative to its size + contentHeight. * * @param i Base pixels to shift. */ public void shiftRelative(int i) { int heightDiff = getHeightDifference(); if (heightDiff > 0) { i *= 1 + heightDiff/(float)(bottomY-topY); //shift(i) inlined int dif = offset + i; if (dif > 0) dif = 0; if (dif < -heightDiff) dif = -heightDiff; int result = dif - offset; if (result != 0) shiftChildren(result); offset = dif; } } /** * Shifts the scrollbar by i pixels. * * @param i How many pixels to shift the scrollbar. */ public void shift(int i) { int heightDiff = getHeightDifference(); if (heightDiff > 0) { int dif = offset + i; if (dif > 0) dif = 0; if (dif < -heightDiff) dif = -heightDiff; int result = dif - offset; if (result != 0) shiftChildren(result); offset = dif; } } }
3,475
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
Container.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/core/Container.java
package com.mcf.davidee.guilib.core; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.util.MathHelper; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import com.mcf.davidee.guilib.core.Scrollbar.Shiftable; import com.mcf.davidee.guilib.focusable.FocusableWidget; public class Container { protected final Minecraft mc = Minecraft.getMinecraft(); protected List<FocusableWidget> focusList; protected List<Widget> widgets; protected int left, right, top, bottom, shiftAmount, extraScrollHeight, scrollbarWidth; protected int cHeight, focusIndex; protected Scrollbar scrollbar; protected Widget lastSelected; protected boolean clip; /** * Create this Container, which by default will clip the elements contained. * * @param scrollbar The scrollbar for this container * @param shiftAmount The amount to shift the scrollbar when focus is shifted; * this should normally be the height of the FocusableWidget, depending on spacing. * @param extraScrollHeight The sum of the supposed gap between the top+bottom of this container * and the FocusableWidgets that are inside. Say that the items in the list should go from this container's top+2 * to this container's bottom-2, then extraScrollHeight should be 4. */ public Container(Scrollbar scrollbar, int shiftAmount, int extraScrollHeight) { this.scrollbar = scrollbar; this.shiftAmount = shiftAmount; this.extraScrollHeight = extraScrollHeight; this.widgets = new ArrayList<Widget>(); this.focusList = new ArrayList<FocusableWidget>(); this.focusIndex = -1; this.clip = true; if (scrollbar != null) { scrollbar.setContainer(this); scrollbarWidth = scrollbar.width; } } /** * Create this Container, which by default will clip the elements contained. */ public Container() { this(null, 0, 0); } public void revalidate(int x, int y, int width, int height) { this.left = x; this.right = x + width; this.top = y; this.bottom = y + height; calculateContentHeight(); if (scrollbar != null) { scrollbar.revalidate(top, bottom); scrollbarWidth = scrollbar.width; } } public List<Widget> getWidgets() { return widgets; } public List<FocusableWidget> getFocusableWidgets() { return focusList; } public void addWidgets(Widget... arr) { for (Widget w : arr) { widgets.add(w); if (w instanceof FocusableWidget) focusList.add((FocusableWidget) w); } calculateContentHeight(); } private void calculateContentHeight() { int minY = Integer.MAX_VALUE, maxY = Integer.MIN_VALUE; for (Widget w : widgets) { if (w instanceof Shiftable) { if (w.y < minY) minY = w.y; if (w.y + w.height > maxY) maxY = w.y + w.height; } } cHeight = (minY > maxY) ? 0 : maxY - minY + extraScrollHeight; } public int getContentHeight() { return cHeight; } public void update() { for (Widget w : widgets) w.update(); } public List<Widget> draw(int mx, int my, int scale) { if (clip) { GL11.glEnable(GL11.GL_SCISSOR_TEST); GL11.glScissor(left*scale, mc.displayHeight-bottom*scale, (right-left-scrollbarWidth)*scale, (bottom-top)*scale); } List<Widget> overlays = new ArrayList<Widget>(); /* * Fix to prevent clipped widgets from thinking that they extend * outside of the container when checking for hover. */ boolean mouseInBounds = inBounds(mx, my); int widgetX = (mouseInBounds || !clip) ? mx : -1; int widgetY = (mouseInBounds || !clip) ? my : -1; for (Widget w : widgets) { if (w.shouldRender(top, bottom)) { w.draw(widgetX, widgetY); overlays.addAll(w.getTooltips()); } } //Don't clip the scrollbar! if (clip) GL11.glDisable(GL11.GL_SCISSOR_TEST); if (scrollbar != null && scrollbar.shouldRender(top, bottom)) scrollbar.draw(mx, my); return overlays; } public void setFocused(FocusableWidget f) { int newIndex = (f == null) ? -1 : focusList.indexOf(f); if (focusIndex != newIndex) { if (focusIndex != -1) focusList.get(focusIndex).focusLost(); if (newIndex != -1) focusList.get(newIndex).focusGained(); focusIndex = newIndex; } } public boolean inBounds(int mx, int my) { return mx >= left && my >= top && mx < right && my < bottom; } public boolean mouseClicked(int mx, int my) { if (inBounds(mx, my)) { boolean resetFocus = true; if (scrollbar != null && scrollbar.shouldRender(top, bottom) && scrollbar.inBounds(mx, my)) return true; for (Widget w : widgets) { if (w.shouldRender(top, bottom) && w.click(mx, my)) { lastSelected = w; if (w instanceof FocusableWidget) { setFocused((FocusableWidget) w); resetFocus = false; } w.handleClick(mx, my); break; } } if (resetFocus) setFocused(null); return true; } return false; } public FocusableWidget deleteFocused() { if (hasFocusedWidget()) { FocusableWidget w = getFocusedWidget(); if (lastSelected == w) lastSelected = null; focusList.remove(focusIndex); if (focusList.size() == 0) focusIndex = -1; else { focusIndex = MathHelper.clamp_int(focusIndex, 0, focusList.size() - 1); focusList.get(focusIndex).focusGained(); } int index = widgets.indexOf(w), offset = Integer.MAX_VALUE; for (int i = index + 1; i < widgets.size(); ++i) { Widget cur = widgets.get(i); if (cur instanceof Shiftable) { if (offset == Integer.MAX_VALUE) offset = w.getY() - cur.getY(); ((Shiftable) cur).shiftY(offset); } } widgets.remove(w); calculateContentHeight(); if (scrollbar != null) scrollbar.onChildRemoved(); return w; } return null; } public void removeFocusableWidgets() { focusIndex = -1; if (lastSelected instanceof FocusableWidget) lastSelected = null; widgets.removeAll(focusList); focusList.clear(); calculateContentHeight(); if (scrollbar != null) scrollbar.onChildRemoved(); } public void mouseReleased(int mx, int my) { if (lastSelected != null) { lastSelected.mouseReleased(mx, my); lastSelected = null; } } public boolean hasFocusedWidget() { return focusIndex != -1; } public FocusableWidget getFocusedWidget() { return focusList.get(focusIndex); } public boolean keyTyped(char c, int code) { boolean handled = (focusIndex != -1) ? focusList.get(focusIndex).keyTyped(c, code) : false; if (!handled) { switch (code) { case Keyboard.KEY_UP: shift(-1); handled = true; break; case Keyboard.KEY_DOWN: shift(1); handled = true; break; case Keyboard.KEY_TAB: shiftFocusToNext(); handled = true; break; } } return handled; } protected void shiftFocusToNext() { if (focusIndex != -1 && focusList.size() > 1) { int newIndex = (focusIndex + 1) % focusList.size(); if (newIndex != focusIndex) { focusList.get(focusIndex).focusLost(); focusList.get(newIndex).focusGained(); if (scrollbar != null && scrollbar.shouldRender(top, bottom)) scrollbar.shift((focusIndex - newIndex) * shiftAmount); focusIndex = newIndex; } } } protected void shiftFocus(int newIndex) { if (focusIndex != newIndex) { focusList.get(focusIndex).focusLost(); focusList.get(newIndex).focusGained(); if (scrollbar != null && scrollbar.shouldRender(top, bottom)) scrollbar.shift((focusIndex - newIndex) * shiftAmount); focusIndex = newIndex; } } protected void shift(int delta) { if (focusIndex != -1) shiftFocus(MathHelper.clamp_int(focusIndex + delta, 0, focusList.size() - 1)); else if (scrollbar != null && scrollbar.shouldRender(top, bottom)) scrollbar.shiftRelative(delta * -4); } public void mouseWheel(int delta) { if (scrollbar != null && scrollbar.shouldRender(top, bottom)) scrollbar.shiftRelative(delta); else { boolean done = false; if (focusIndex != -1) done = focusList.get(focusIndex).mouseWheel(delta); else for (Iterator<Widget> it = widgets.iterator(); it.hasNext() && !done;) done = it.next().mouseWheel(delta); } } public void setClipping(boolean clip) { this.clip = clip; } public boolean isClipping() { return clip; } public int left() { return left; } public int right() { return right; } public int top() { return top; } public int bottom() { return bottom; } }
8,445
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
TextField.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/core/TextField.java
package com.mcf.davidee.guilib.core; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.MathHelper; import org.lwjgl.opengl.GL11; import com.mcf.davidee.guilib.focusable.FocusableWidget; /** * * Abstract representation of a minecraft textfield. * This is pretty much a copy of the vanilla textfield, * so it support highlighting/copying/pasting text. * */ public abstract class TextField extends FocusableWidget { public interface CharacterFilter { public String filter(String s); public boolean isAllowedCharacter(char c); } protected String text; protected int maxLength = 32; protected boolean focused; protected int cursorCounter, cursorPosition, charOffset, selectionEnd; protected int color; protected CharacterFilter filter; public TextField(int width, int height, CharacterFilter filter) { super(width, height); this.text = ""; this.filter = filter; this.color = 0xffffff; } protected abstract int getDrawX(); protected abstract int getDrawY(); public abstract int getInternalWidth(); protected abstract void drawBackground(); @Override public void draw(int mx, int my) { drawBackground(); int j = cursorPosition - charOffset; int k = selectionEnd - charOffset; String s = mc.fontRenderer.trimStringToWidth(text.substring(charOffset), getInternalWidth()); boolean flag = j >= 0 && j <= s.length(); boolean cursor = focused && this.cursorCounter / 6 % 2 == 0 && flag; int l = getDrawX(); int i1 = getDrawY(); int j1 = l; if (k > s.length()) k = s.length(); if (s.length() > 0) { String s1 = flag ? s.substring(0, j) : s; j1 = mc.fontRenderer.drawStringWithShadow(s1, l, i1, color); } boolean flag2 = this.cursorPosition < text.length() || text.length() >= maxLength; int k1 = j1; if (!flag) k1 = j > 0 ? l + this.width : l; else if (flag2) { k1 = j1 - 1; --j1; } if (s.length() > 0 && flag && j < s.length()) mc.fontRenderer.drawStringWithShadow(s.substring(j), j1, i1, color); if (cursor) { if (flag2) Gui.drawRect(k1, i1 - 1, k1 + 1, i1 + 1 + mc.fontRenderer.FONT_HEIGHT, -3092272); else mc.fontRenderer.drawStringWithShadow("_", k1, i1, color); } if (k != j) { int l1 = l + mc.fontRenderer.getStringWidth(s.substring(0, k)); drawCursorVertical(k1, i1 - 1, l1 - 1, i1 + 1 + mc.fontRenderer.FONT_HEIGHT); } } protected void drawCursorVertical(int x1, int y1, int x2, int y2) { int temp; if (x1 < x2) { temp = x1; x1 = x2; x2 = temp; } if (y1 < y2) { temp = y1; y1 = y2; y2 = temp; } Tessellator tessellator = Tessellator.instance; GL11.glColor4f(0.0F, 0.0F, 255.0F, 255.0F); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_COLOR_LOGIC_OP); GL11.glLogicOp(GL11.GL_OR_REVERSE); tessellator.startDrawingQuads(); tessellator.addVertex((double) x1, (double) y2, 0.0D); tessellator.addVertex((double) x2, (double) y2, 0.0D); tessellator.addVertex((double) x2, (double) y1, 0.0D); tessellator.addVertex((double) x1, (double) y1, 0.0D); tessellator.draw(); GL11.glDisable(GL11.GL_COLOR_LOGIC_OP); GL11.glEnable(GL11.GL_TEXTURE_2D); } @Override public boolean click(int mx, int my) { return inBounds(mx, my); } @Override public void handleClick(int mx, int my) { int pos = mx - x; pos -= Math.abs(getInternalWidth() - width) / 2; String s = mc.fontRenderer.trimStringToWidth( text.substring(charOffset), getWidth()); setCursorPosition(mc.fontRenderer.trimStringToWidth(s, pos).length() + charOffset); } @Override public void update() { ++cursorCounter; } @Override public void focusGained() { cursorCounter = 0; focused = true; } @Override public void focusLost() { focused = false; } public String getText() { return text; } public void setMaxLength(int length) { maxLength = length; if (text.length() > length) text = text.substring(0, length); } public void setColor(int color) { this.color = color; } public String getSelectedtext() { int start = cursorPosition < selectionEnd ? cursorPosition : selectionEnd; int end = cursorPosition < selectionEnd ? selectionEnd : cursorPosition; return text.substring(start, end); } public void setText(String str) { text = (str.length() > maxLength) ? str.substring(0, maxLength) : str; setCursorPosition(text.length()); } public void moveCursorBy(int offs) { setCursorPosition(selectionEnd + offs); } public void writeText(String str) { String s1 = ""; str = filter.filter(str); int i = this.cursorPosition < this.selectionEnd ? this.cursorPosition : this.selectionEnd; int j = this.cursorPosition < this.selectionEnd ? this.selectionEnd : this.cursorPosition; int k = maxLength - text.length() - (i - this.selectionEnd); if (this.text.length() > 0) s1 = s1 + this.text.substring(0, i); int l; if (k < str.length()) { s1 = s1 + str.substring(0, k); l = k; } else { s1 = s1 + str; l = str.length(); } if (text.length() > 0 && j < text.length()) s1 = s1 + this.text.substring(j); text = s1; moveCursorBy(i - this.selectionEnd + l); } public void deleteFromCursor(int amt) { if (text.length() > 0) { if (selectionEnd != cursorPosition) writeText(""); else { boolean flag = amt < 0; int j = flag ? this.cursorPosition + amt : this.cursorPosition; int k = flag ? this.cursorPosition : this.cursorPosition + amt; String s = ""; if (j >= 0) s = this.text.substring(0, j); if (k < this.text.length()) s = s + this.text.substring(k); this.text = s; if (flag) moveCursorBy(amt); } } } public void setCursorPosition(int index) { cursorPosition = MathHelper.clamp_int(index, 0, text.length()); setSelectionPos(this.cursorPosition); } public void setSelectionPos(int index) { index = MathHelper.clamp_int(index, 0, text.length()); selectionEnd = index; if (charOffset > index) charOffset = index; int width = this.getInternalWidth(); String s = mc.fontRenderer.trimStringToWidth(text.substring(charOffset), width); int pos = s.length() + charOffset; if (index == charOffset) charOffset -= mc.fontRenderer.trimStringToWidth(this.text, width, true).length(); if (index > pos) charOffset += index - 1; else if (index <= charOffset) charOffset = index; charOffset = MathHelper.clamp_int(charOffset, 0, text.length()); } public boolean keyTyped(char par1, int par2) { if (focused) { switch (par1) { case 1: setCursorPosition(text.length()); setSelectionPos(0); return true; case 3: GuiScreen.setClipboardString(getSelectedtext()); return true; case 22: writeText(GuiScreen.getClipboardString()); return true; case 24: GuiScreen.setClipboardString(this.getSelectedtext()); writeText(""); return true; default: switch (par2) { case 14: deleteFromCursor(-1); return true; case 199: this.setSelectionPos(0); this.setCursorPosition(0); return true; case 203: if (GuiScreen.isShiftKeyDown()) setSelectionPos(selectionEnd - 1); else moveCursorBy(-1); return true; case 205: if (GuiScreen.isShiftKeyDown()) setSelectionPos(selectionEnd + 1); else moveCursorBy(1); return true; case 207: if (GuiScreen.isShiftKeyDown()) setSelectionPos(text.length()); else setCursorPosition(text.length()); return true; case 211: deleteFromCursor(1); return true; default: if (filter.isAllowedCharacter(par1)) { writeText(Character.toString(par1)); return true; } return false; } } } return false; } }
7,831
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
Widget.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/core/Widget.java
package com.mcf.davidee.guilib.core; import java.util.Collections; import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; /** * * Widgets are the core of this library. * All controls should be a subclass of Widget. * */ public abstract class Widget extends Gui { protected Minecraft mc = Minecraft.getMinecraft(); protected int x, y, width, height; protected boolean enabled; /** * * @param width Widget of this widget * @param height Height of this widget */ public Widget(int width, int height) { this.width = width; this.height = height; this.enabled = true; } /** * * @param x Leftmost x of this widget * @param y Topmost y of this widget * @param width Widget of this widget * @param height Height of this widget */ public Widget(int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; this.height = height; this.enabled = true; } /** * Draws this widget * * @param mx Mouse-X * @param my Mouse-Y */ public abstract void draw(int mx, int my); /** * Called when the mouse is clicked. * * @param mx Mouse-X * @param my Mouse-Y * @return Whether the control should handleClick */ public abstract boolean click(int mx, int my); /** * Called when a call to click(mx, my) returns true. * Handle the click event in this method. * * @param mx Mouse-X * @param my Mouse-Y */ public void handleClick(int mx, int my){ } /** * Update this control (if necessary). */ public void update(){ } /** * Called when the mouse is released. * * @param mx Mouse-X * @param my Mouse-Y */ public void mouseReleased(int mx, int my){ } /** * Called when a key is typed. * * @param c Character typed (if any) * @param code Keyboard.KEY_ code for this key * @return Whether this widget has captured this keyboard event */ public boolean keyTyped(char c, int code) { return false; } /** * Called when the mouse wheel has moved. * * @param delta Clamped difference, currently either +5 or -5 * @return Whether this widget has captured this mouse wheel event */ public boolean mouseWheel(int delta) { return false; } /** * Called when rendering to get tooltips. * * @return Tooltips for this widget */ public List<Widget> getTooltips() { return Collections.emptyList(); } /** * Called to see if the specified coordinate is in bounds. * * @param mx Mouse-X * @param my Mouse-Y * @return Whether the mouse is in the bounds of this widget */ public boolean inBounds(int mx, int my) { return mx >= x && my >= y && mx < x + width && my < y + height; } /** * Called to see if this widget should render. * * @param topY Top-Y of the screen * @param bottomY Bottom-Y of the screen * @return Whether or not this widget should be rendered */ public boolean shouldRender(int topY, int bottomY) { return y + height >= topY && y <= bottomY; } /** * Set the position of this widget. * * @param x Left-most X * @param y Top-most Y */ public void setPosition(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public int getWidth() { return width; } public int getHeight() { return height; } }
3,345
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
CheckboxVanilla.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/vanilla/CheckboxVanilla.java
package com.mcf.davidee.guilib.vanilla; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import com.mcf.davidee.guilib.core.Checkbox; /** * * Default style checkbox. * */ public class CheckboxVanilla extends Checkbox { private static final ResourceLocation TEXTURE = new ResourceLocation("guilib", "textures/gui/checkbox.png"); public static final int SIZE = 10; public CheckboxVanilla(String text) { super(SIZE + 2 + Minecraft.getMinecraft().fontRenderer.getStringWidth(text), SIZE, text); } public CheckboxVanilla(String text, boolean checked) { this(text); this.check = checked; } @Override public void handleClick(int mx, int my) { mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); super.handleClick(mx, my); } @Override public void draw(int mx, int my) { mc.renderEngine.bindTexture(TEXTURE); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); drawTexturedModalRect(x, y, 0, check ? SIZE : 0, SIZE, SIZE); mc.fontRenderer.drawStringWithShadow(str, x + SIZE + 1, y + 1, (inBounds(mx, my)) ? 16777120 : 0xffffff); } }
1,247
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
ScrollbarVanilla.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/vanilla/ScrollbarVanilla.java
package com.mcf.davidee.guilib.vanilla; import com.mcf.davidee.guilib.core.Scrollbar; import com.mcf.davidee.guilib.core.Widget; /** * * Default style scrollbar. * */ public class ScrollbarVanilla extends Scrollbar { public ScrollbarVanilla(int width) { super(width); } @Override protected void drawBoundary(int x, int y, int width, int height) { drawRect(x, y, x + width, y + height, 0x80000000); } @Override protected void drawScrollbar(int x, int y, int width, int height) { drawGradientRect(x, y, x + width, y + height, 0x80ffffff, 0x80222222); } @Override protected void shiftChildren(int dy) { for (Widget w : container.getWidgets()) { if (w instanceof Shiftable) ((Shiftable) w).shiftY(dy); } } }
745
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
ButtonVanilla.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/vanilla/ButtonVanilla.java
package com.mcf.davidee.guilib.vanilla; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import com.mcf.davidee.guilib.core.Button; /** * * Vanilla GuiButton in Widget form. * */ public class ButtonVanilla extends Button { private static final ResourceLocation TEXTURE = new ResourceLocation("textures/gui/widgets.png"); protected String str; public ButtonVanilla(int width, int height, String text, ButtonHandler handler) { super(width, height, handler); this.str = text; } public ButtonVanilla(String text, ButtonHandler handler) { this(200, 20, text, handler); } @Override public void draw(int mx, int my) { mc.renderEngine.bindTexture(TEXTURE); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); boolean hover = inBounds(mx, my); int u = 0, v = 46 + getStateOffset(hover); if (width == 200 && height == 20) //Full size button drawTexturedModalRect(x, y, u, v, width, height); else{ drawTexturedModalRect(x, y, u, v, width/2, height/2); drawTexturedModalRect(x+width/2, y, u +200 - width /2, v, width/2, height/2); drawTexturedModalRect(x, y+height/2, u, v+20-height/2, width/2, height/2); drawTexturedModalRect(x+width/2, y+height/2, u + 200-width/2, v+20-height/2, width/2, height/2); } drawCenteredString(mc.fontRenderer, str, x + width / 2, y + (height - 8) / 2, getTextColor(hover)); } private int getStateOffset(boolean hover) { return ((enabled) ? ((hover) ? 40 : 20) : 0); } private int getTextColor(boolean hover) { return ((enabled) ? ((hover) ? 16777120 : 14737632) : 6250336); } public String getText() { return str; } public void setText(String str) { this.str = str; } public void handleClick(int mx, int my) { mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); super.handleClick(mx, my); } }
1,948
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
TextFieldVanilla.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/vanilla/TextFieldVanilla.java
package com.mcf.davidee.guilib.vanilla; import net.minecraft.util.ChatAllowedCharacters; import com.mcf.davidee.guilib.core.TextField; /** * * Vanilla GuiTextField in Widget form. * */ public class TextFieldVanilla extends TextField { private int outerColor, innerColor; public TextFieldVanilla(int width, int height, CharacterFilter filter) { super(width, height, filter); outerColor = -6250336; innerColor = -16777216; } public TextFieldVanilla(CharacterFilter filter) { this(200, 20, filter); } public TextFieldVanilla(int width, int height, int innerColor, int outerColor, CharacterFilter filter) { super(width, height, filter); this.outerColor = outerColor; this.innerColor = innerColor; } public void setInnerColor(int c) { this.innerColor = c; } public void setOuterColor(int c) { this.outerColor = c; } @Override protected int getDrawX() { return x + 4; } @Override protected int getDrawY() { return y + (height - 8) / 2; } @Override public int getInternalWidth() { return width - 8; } @Override protected void drawBackground() { drawRect(x - 1, y - 1, x + width + 1, y + height + 1, outerColor); drawRect(x, y, x + width, y + height, innerColor); } public static class NumberFilter implements CharacterFilter { public String filter(String s) { StringBuilder sb = new StringBuilder(); for (char c : s.toCharArray()) if (isAllowedCharacter(c)) sb.append(c); return sb.toString(); } public boolean isAllowedCharacter(char c) { return Character.isDigit(c); } } public static class VanillaFilter implements CharacterFilter { public String filter(String s) { return ChatAllowedCharacters.filerAllowedCharacters(s); } public boolean isAllowedCharacter(char c) { return ChatAllowedCharacters.isAllowedCharacter(c); } } }
1,851
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
SliderVanilla.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/vanilla/SliderVanilla.java
package com.mcf.davidee.guilib.vanilla; import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import com.mcf.davidee.guilib.core.Slider; /** * * Vanilla GuiSlider in Widget form. * */ public class SliderVanilla extends Slider { private static final ResourceLocation TEXTURE = new ResourceLocation("textures/gui/widgets.png"); public SliderVanilla(int width, int height, float value, SliderFormat format) { super(width, height, value, format); } public SliderVanilla(float value, SliderFormat format) { this(150, 20, value, format); } @Override public void handleClick(int mx, int my) { super.handleClick(mx, my); mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); } @Override public void draw(int mx, int my) { if (dragging){ value = (float)(mx - (this.x + 4)) / (float)(this.width - 8); value = MathHelper.clamp_float(value, 0, 1); } mc.renderEngine.bindTexture(TEXTURE); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); drawTexturedModalRect(x, y, 0, 46, width / 2, height); drawTexturedModalRect(x + width / 2, y, 200 - width / 2, 46, width / 2, height); drawTexturedModalRect(x + (int)(value * (float)(width - 8)), y, 0, 66, 4, 20); drawTexturedModalRect(x + (int)(value * (float)(width - 8)) + 4, y, 196, 66, 4, 20); drawCenteredString(mc.fontRenderer, format.format(this), x + width / 2, y + (height - 8) / 2, (inBounds(mx,my)) ? 16777120 : 0xffffff); } }
1,600
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
ItemButton.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/vanilla/items/ItemButton.java
package com.mcf.davidee.guilib.vanilla.items; import java.util.Arrays; import java.util.List; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.item.ItemStack; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import com.mcf.davidee.guilib.core.Button; import com.mcf.davidee.guilib.core.Scrollbar.Shiftable; import com.mcf.davidee.guilib.core.Widget; /** * * This class is a Widget copy of a vanilla item button. * This button supports "Air" - an itemstack without an item. * Note that the air representation is volatile - getItem() returns null, and calling toString() on the itemstack will crash. * * Note that items use zLevel for rendering - change zLevel as needed. * */ public class ItemButton extends Button implements Shiftable { public static final int WIDTH = 18; public static final int HEIGHT = 18; public static final RenderItem itemRenderer = new RenderItem(); protected ItemStack item; protected List<Widget> tooltip; private GuiScreen parent; protected boolean hover; public ItemButton(ItemStack item, ButtonHandler handler) { super(WIDTH, HEIGHT, handler); this.parent = mc.currentScreen; this.zLevel = 100; setItem(item); } protected void setItem(ItemStack item) { this.item = item; this.tooltip = Arrays.asList((Widget)new ItemTooltip(item, parent)); } public ItemStack getItem() { return item; } /** * Draws the item or string "Air" if stack.getItem() is null */ @Override public void draw(int mx, int my) { hover = inBounds(mx, my); if (hover) { GL11.glDisable(GL11.GL_DEPTH_TEST); drawRect(x, y, x + width, y + height, 0x55909090); GL11.glEnable(GL11.GL_DEPTH_TEST); tooltip.get(0).setPosition(mx, my); } if (item.getItem() != null) { RenderHelper.enableGUIStandardItemLighting(); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); GL11.glEnable(GL12.GL_RESCALE_NORMAL); itemRenderer.zLevel = this.zLevel; itemRenderer.renderItemAndEffectIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, x + 1, y + 1); itemRenderer.zLevel = 0; GL11.glDisable(GL12.GL_RESCALE_NORMAL); RenderHelper.disableStandardItemLighting(); } else //Air drawString(mc.fontRenderer, "Air" , x + 3, y + 5, -1); } @Override public List<Widget> getTooltips() { return (hover) ? tooltip : super.getTooltips(); } @Override public void shiftY(int dy) { this.y += dy; } }
2,598
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
ItemTooltip.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/vanilla/items/ItemTooltip.java
package com.mcf.davidee.guilib.vanilla.items; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import net.minecraft.block.Block; import net.minecraft.block.BlockEndPortal; import net.minecraft.block.BlockPistonExtension; import net.minecraft.block.BlockPistonMoving; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import org.lwjgl.opengl.GL11; import com.mcf.davidee.guilib.core.Widget; /** * * This class represents a Widget copy of an Item's tooltip. * */ public class ItemTooltip extends Widget { public static final Map<Class<?>, String> NAME_MAP = new HashMap<Class<?>, String>(); static { NAME_MAP.put(BlockPistonExtension.class, "Piston Extension"); NAME_MAP.put(BlockPistonMoving.class, "Piston Moving"); NAME_MAP.put(BlockEndPortal.class, "End Portal"); } private static String getUnknownName(ItemStack stack) { Item item = stack.getItem(); if (item instanceof ItemBlock) { Class<? extends Block> blockClass = ((ItemBlock)item).field_150939_a.getClass(); return NAME_MAP.containsKey(blockClass) ? NAME_MAP.get(blockClass) : "Unknown"; } return "Unknown"; } private final List<String> tooltips; private final FontRenderer font; private final GuiScreen parent; /** * See {@link net.minecraft.client.gui.inventory.GuiContainer#drawScreen} for more information. */ @SuppressWarnings("unchecked") public ItemTooltip(ItemStack stack, GuiScreen parent) { super(0, 0); if (stack.getItem() != null) { tooltips = (List<String>) stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips); if (!tooltips.isEmpty()) { String name = tooltips.get(0); if (name.startsWith("tile.null.name")) name = name.replace("tile.null.name", getUnknownName(stack)); tooltips.set(0, stack.getRarity().rarityColor.toString() + name); for (int i = 1; i < tooltips.size(); ++i) tooltips.set(i, EnumChatFormatting.GRAY.toString() + tooltips.get(i)); } FontRenderer itemRenderer = stack.getItem().getFontRenderer(stack); font = (itemRenderer == null) ? mc.fontRenderer : itemRenderer; } else { tooltips = Arrays.asList("Air"); font = mc.fontRenderer; } this.parent = parent; this.width = getMaxStringWidth(); this.height = (tooltips.size() > 1) ? tooltips.size()*10 : 8; } @Override public void setPosition(int newX, int newY) { this.x = newX + 12; this.y = newY - 12; if (x + width + 6 > parent.width) x -= 28 + width; if (y + height + 6 > parent.height) y = parent.height - height - 6; } /** * See {@link net.minecraft.client.gui.inventory.GuiContainer#drawHoveringText} */ @Override public void draw(int mx, int my) { GL11.glDisable(GL11.GL_DEPTH_TEST); if (!tooltips.isEmpty()) { final int outlineColor = 0xf0100010; drawRect(x - 3, y - 4, x + width + 3, y - 3, outlineColor); drawRect(x - 3, y + height + 3, x + width + 3, y + height + 4, outlineColor); drawRect(x - 3, y - 3, x + width + 3, y + height + 3, outlineColor); drawRect(x - 4, y - 3, x - 3, y + height + 3, outlineColor); drawRect(x + width + 3, y - 3, x + width + 4, y + height + 3, outlineColor); int gradient1 = 1347420415; int gradient2 = (gradient1 & 16711422) >> 1 | gradient1 & -16777216; drawGradientRect(x - 3, y - 3 + 1, x - 3 + 1, y + height + 3 - 1, gradient1, gradient2); drawGradientRect(x + width + 2, y - 3 + 1, x + width + 3, y + height + 3 - 1, gradient1, gradient2); drawGradientRect(x - 3, y - 3, x + width + 3, y - 3 + 1, gradient1, gradient1); drawGradientRect(x - 3, y + height + 2, x + width + 3, y + height + 3, gradient2, gradient2); for (int index = 0; index < tooltips.size(); ++index) { font.drawStringWithShadow(tooltips.get(index), x, y, -1); if (index == 0) y += 2; y += 10; } } GL11.glEnable(GL11.GL_DEPTH_TEST); } @Override public boolean click(int mx, int my) { return false; } private int getMaxStringWidth() { int max = 0; for (String s : tooltips) { int width = font.getStringWidth(s); if (width > max) max = width; } return max; } }
4,309
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
IntSlider.java
/FileExtraction/Java_unseen/DavidGoldman_GuiLib/src/com/mcf/davidee/guilib/vanilla/sliders/IntSlider.java
package com.mcf.davidee.guilib.vanilla.sliders; import net.minecraft.util.MathHelper; import com.mcf.davidee.guilib.core.Slider; import com.mcf.davidee.guilib.vanilla.SliderVanilla; /** * * A Vanilla-style Integer slider that supports the mouse wheel. * */ public class IntSlider extends SliderVanilla { protected final int minVal, maxVal; protected final String nameFormat; protected boolean hover; /** * @param nameFormat Format string, used as a parameter to String.format */ public IntSlider(int width, int height, String nameFormat, int val, int minVal, int maxVal) { super(width, height, getFloatValue(val,minVal,maxVal), null); this.format = new IntSliderFormat(); this.nameFormat = nameFormat; this.minVal = minVal; this.maxVal = maxVal; } public IntSlider(String name, int val, int minVal, int maxVal) { this(150, 20, name, val, minVal, maxVal); } @Override public void draw(int mx, int my){ hover = inBounds(mx,my); super.draw(mx, my); } @Override public boolean mouseWheel(int delta){ if (hover && !dragging){ value = getFloatValue(getIntValue()+(int)Math.signum(delta),minVal,maxVal); return true; } return false; } public static float getFloatValue(int val, int min, int max){ val = MathHelper.clamp_int(val, min, max); return (float)(val-min) / (max-min); } public void setIntValue(int val) { value = MathHelper.clamp_float(getFloatValue(val, minVal, maxVal), 0, 1); } public int getIntValue(){ return Math.round(value*(maxVal-minVal)+minVal); } protected class IntSliderFormat implements SliderFormat{ public String format(Slider slider) { return String.format(nameFormat, getIntValue()); } } }
1,714
Java
.java
DavidGoldman/GuiLib
15
11
0
2013-07-25T15:05:03Z
2014-10-19T21:44:43Z
SampleApp.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/sample/src/main/java/com/dazhi/sample/SampleApp.java
package com.dazhi.sample; import com.dazhi.libroot.root.RootApp; import com.dazhi.libroot.util.RtLog; /** * 功能: * 描述: * 作者:WangZezhi * 邮箱:wangzezhi528@163.com * 创建日期:2018/12/8 15:15 * 修改日期:2018/12/8 15:15 */ public class SampleApp extends RootApp { @Override public void onCreate() { super.onCreate(); // ARouter // if(BuildConfig.DEBUG) { // ARouter.openLog(); // 打印日志 // ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险) // } // ARouter.init((Application) RtCmn.getAppContext()); // 尽可能早,推荐在Application中初始化 // RtLog.setOpen(); // 友盟统计(没有推送,最后一个值填null即可) // UMConfigure.init(Context context, String appkey, String channel, int deviceType, String pushSecret); // UMConfigure.init(this, "5e070e85570df387c2000353", "MvvmAndroidLib", // UMConfigure.DEVICE_TYPE_PHONE, null); // MobclickAgent.setCatchUncaughtExceptions(true); // UtConfig.self().initEngineLifecycle(new EngineLifecycleApp()); // // FactoryDaoPerson.self().init(AppDatabase.self(this).getDaoPerson()); } }
1,389
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z
AppDatabase.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/sample/src/main/java/com/dazhi/sample/db/AppDatabase.java
//package com.dazhi.sample.db; // //import android.content.Context; // //import androidx.room.Database; //import androidx.room.Room; //import androidx.room.RoomDatabase; // ///** // * 功能:room 框架 数据库构建类 // * 描述: // * 作者:WangZezhi // * 邮箱:wangzezhi528@163.com // * 创建日期:2018/12/8 15:29 // * 修改日期:2018/12/8 15:29 // */ //@Database(entities = {DbPerson.class}, version = 1, exportSchema = false) //public abstract class AppDatabase extends RoomDatabase { // public abstract DaoPerson getDaoPerson(); // // /**======================================= // * 作者:WangZezhi (2018/12/8 15:44) // * 功能:单列获得实例方法 // * 描述: // *=======================================*/ // private static AppDatabase instance = null; // public static synchronized AppDatabase self(Context context) { // if (instance == null) { // instance = buildDatabase(context); // } // return instance; // } // private static AppDatabase buildDatabase(Context context) { // return Room.databaseBuilder(context, AppDatabase.class, "intelink_app.db") // .build(); // } // // //}
1,256
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z
DaoPerson.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/sample/src/main/java/com/dazhi/sample/db/DaoPerson.java
//package com.dazhi.sample.db; // //import java.util.List; //import androidx.room.Dao; //import androidx.room.Delete; //import androidx.room.Insert; //import androidx.room.OnConflictStrategy; //import androidx.room.Query; // ///** // * 功能: // * 描述: // * 作者:WangZezhi // * 邮箱:wangzezhi528@163.com // * 创建日期:2018/12/8 15:50 // * 修改日期:2018/12/8 15:50 // */ //@Dao //public interface DaoPerson { // // 查询所有数据 // @Query("SELECT * FROM tab_person") // List<DbPerson> dbGetAllBnPerson(); // // // 批量插入 // @Insert(onConflict = OnConflictStrategy.REPLACE) // void dbInsertLsBnPerson(List<DbPerson> lsBnPerson); // // // 批量删除 // @Delete // void dbDeleteLsBnPerson(List<DbPerson> lsBnPerson); // //}
820
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z
DbPerson.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/sample/src/main/java/com/dazhi/sample/db/DbPerson.java
//package com.dazhi.sample.db; // //import androidx.room.ColumnInfo; //import androidx.room.Entity; //import androidx.room.Ignore; //import androidx.room.PrimaryKey; // ///** // * 功能:表 tab_person 实体类 // * 描述: // * 作者:WangZezhi // * 邮箱:wangzezhi528@163.com // * 创建日期:2018/12/8 15:45 // * 修改日期:2018/12/8 15:45 // */ //@Entity(tableName = "tab_person") //public class DbPerson { // @PrimaryKey(autoGenerate = true) // private long id=0L; //数据库主键(数据库增加字段) // // @ColumnInfo(name = "name") // private String strName=""; // // // 构造函数 // public DbPerson(){ // // } // @Ignore // public DbPerson(String strName) { // this.strName = strName; // } // // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getStrName() { // return strName; // } // // public void setStrName(String strName) { // this.strName = strName; // } // // //}
1,118
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z
FactoryDaoPerson.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/sample/src/main/java/com/dazhi/sample/db/FactoryDaoPerson.java
//package com.dazhi.sample.db; // ///** // * 功能:用于获得Dao对象的工厂类 // * 描述: // * 作者:WangZezhi // * 邮箱:wangzezhi528@163.com // * 创建日期:2018/12/8 15:52 // * 修改日期:2018/12/8 15:52 // */ //public class FactoryDaoPerson { // private DaoPerson daoPerson; // // public void init(DaoPerson daoPerson) { // this.daoPerson = daoPerson; // } // // public DaoPerson getDaoPerson() { // return daoPerson; // } // // /**======================================= // * 作者:WangZezhi (2018/12/8 15:54) // * 功能:单例 // * 描述: // *=======================================*/ // private FactoryDaoPerson(){ // } // private static final class HolderClass { // static final FactoryDaoPerson INSTANCE = new FactoryDaoPerson(); // } // public static FactoryDaoPerson self() { // return HolderClass.INSTANCE; // } // // //}
989
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z
EngineLifecycleApp.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/sample/src/main/java/com/dazhi/sample/youmeng/EngineLifecycleApp.java
//package com.dazhi.sample.youmeng; // //import android.content.Context; //import com.dazhi.libroot.inte.InteRootEngineLifecycle; //import com.umeng.analytics.MobclickAgent; // ///** // * 功能: // * 描述: // * 作者:WangZezhi // * 邮箱:wangzezhi528@163.com // * 创建日期:2019-12-28 15:39 // * 修改日期:2019-12-28 15:39 // */ //public class EngineLifecycleApp implements InteRootEngineLifecycle { // // @Override // public void onCreateRoot(Context context) { // } // // @Override // public void onResumeRoot(Context context) { // // 友盟统计 // MobclickAgent.onResume(context); // } // // @Override // public void onPauseRoot(Context context) { // // 友盟统计 // MobclickAgent.onPause(context); // } // // @Override // public void onStopRoot(Context context) { // } // @Override // public void onDestroyRoot(Context context) { // } // //}
947
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z
IRootCallObject.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/library/src/main/java/com/dazhi/libroot/inte/IRootCallObject.java
package com.dazhi.libroot.inte; /** * 功能: * 描述: * 作者:WangZezhi * 邮箱:wangzezhi528@163.com * 创建日期:2018/4/19 14:48 * 修改日期:2018/4/19 14:48 */ public interface IRootCallObject<T> { void call(T obj); }
252
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z
IRootEngineLifecycle.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/library/src/main/java/com/dazhi/libroot/inte/IRootEngineLifecycle.java
package com.dazhi.libroot.inte; import android.content.Context; /** * 功能:基类生命周期方法扩展引擎 * 描述: * 作者:WangZezhi * 邮箱:wangzezhi528@163.com * 创建日期:2019-12-28 10:59 * 修改日期:2019-12-28 10:59 */ public interface IRootEngineLifecycle { void onCreateRoot(Context context); void onResumeRoot(Context context); void onPauseRoot(Context context); void onStopRoot(Context context); void onDestroyRoot(Context context); }
501
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z
IRootCall.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/library/src/main/java/com/dazhi/libroot/inte/IRootCall.java
package com.dazhi.libroot.inte; /** * 功能:单纯回调事件 * 描述: * 作者:WangZezhi * 邮箱:wangzezhi528@163.com * 创建日期:2018/6/6 15:42 * 修改日期:2018/6/6 15:42 */ public interface IRootCall { void call(); }
254
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z
RootAdapter.java
/FileExtraction/Java_unseen/Dazhi528_MvvmAndroidFrame/library/src/main/java/com/dazhi/libroot/root/RootAdapter.java
package com.dazhi.libroot.root; import android.content.Context; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.List; /** * 功能:通用适配器 * 描述: * 作者:WangZezhi * 邮箱:wangzezhi528@163.com * 创建日期:2018/3/8 11:51 * 修改日期:2018/3/8 11:51 * 用法: * myAdadpter = new MyAdapter<Hero>(mData,R.layout.item_spin_hero) { * / @Override * public void bindView(ViewHolder holder, Hero obj) { * holder.setImageResource(R.id.img_icon,obj.gethIcon()); * holder.setText(R.id.txt_name, obj.gethName()); * } * }; */ @SuppressWarnings({"unused", "RedundantSuppression"}) public abstract class RootAdapter<T> extends BaseAdapter { private final int intLayout; //布局id private final List<T> lsData; //引入数据集合 public RootAdapter(int intLayout, List<T> lsData) { this.intLayout = intLayout; this.lsData = lsData; } @Override public int getCount() { return lsData!=null ? lsData.size() : 0; } @Override public T getItem(int position) { return lsData!=null ? lsData.get(position) : null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = ViewHolder.bind(convertView, parent, intLayout, position); onBindView(holder, getItem(position)); return holder.getConvertView(); } /**======================================= * 作者:WangZezhi (2018/3/8 12:09) * 功能: * 描述: *=======================================*/ public abstract void onBindView(ViewHolder holder, T obj); /**======================================= * 作者:WangZezhi (2018/3/8 12:00) * 功能:视图持有器 * 描述: *=======================================*/ @SuppressWarnings({"unused", "RedundantSuppression"}) public static class ViewHolder { private final SparseArray<View> saView; //存储ListView 的 item中的View private View convertView; //存放convertView private int position; //游标 //构造方法,完成相关初始化 //private ViewHolder(Context context, ViewGroup parent, int layoutRes) { private ViewHolder(ViewGroup parent, int layoutRes) { //Context上下文 Context context = parent.getContext(); saView = new SparseArray<>(); View convertView = LayoutInflater.from(context).inflate(layoutRes, parent, false); convertView.setTag(this); this.convertView = convertView; } //绑定ViewHolder与item public static ViewHolder bind(View convertView, ViewGroup parent, int layoutRes, int position) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(parent, layoutRes); } else { holder = (ViewHolder) convertView.getTag(); holder.convertView = convertView; } holder.position = position; return holder; } /** * 获取view */ @SuppressWarnings("unchecked") public <T extends View> T getView(int id) { T t = (T)saView.get(id); if (t == null) { t = convertView.findViewById(id); saView.put(id, t); } return t; } /** * 获取当前条目 */ private View getConvertView() { return convertView; } /** * 获取条目位置 */ public int getItemPosition() { return position; } /** * 设置文字 */ public ViewHolder setText(int id, CharSequence text) { View view = getView(id); if (view instanceof TextView) { ((TextView) view).setText(text); } return this; } /** * 设置图片 */ public ViewHolder setImageResource(int id, int drawableRes) { View view = getView(id); if (view instanceof ImageView) { ((ImageView) view).setImageResource(drawableRes); } else { view.setBackgroundResource(drawableRes); } return this; } /** * 设置可见 */ public ViewHolder setVisibility(int id, int visible) { getView(id).setVisibility(visible); return this; } /** * 设置点击监听 */ public ViewHolder setOnClickListener(int id, View.OnClickListener listener) { getView(id).setOnClickListener(listener); return this; } } }
5,361
Java
.java
Dazhi528/MvvmAndroidFrame
16
1
0
2018-12-07T02:20:44Z
2021-01-29T10:04:38Z