2015-10-14 20:01:52 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2010-2015 SAP SE.
|
|
|
|
*
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-05-21 14:58:16 +00:00
|
|
|
package com.logicalhacking.dasca.crosslanguage.util
|
2015-10-14 20:01:52 +00:00
|
|
|
|
|
|
|
import com.ibm.wala.classLoader.CallSiteReference
|
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode
|
|
|
|
import com.ibm.wala.ssa.SSAInstruction
|
|
|
|
|
|
|
|
class JavaSourceLocation(val line: Int, val filePath: String) extends SourceLocation with Equals {
|
|
|
|
|
|
|
|
override def toString = s"$filePath:$line"
|
|
|
|
|
|
|
|
override def equals(other: Any) = other match {
|
|
|
|
case o: JavaSourceLocation => line == o.line && filePath == o.filePath
|
|
|
|
case _ => false
|
|
|
|
}
|
|
|
|
|
|
|
|
def canEqual(other: Any) = {
|
2017-05-21 14:58:16 +00:00
|
|
|
other.isInstanceOf[com.logicalhacking.dasca.crosslanguage.util.JavaSourceLocation]
|
2015-10-14 20:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override def hashCode() = {
|
|
|
|
val prime = 41
|
|
|
|
prime * (prime + line.hashCode) + filePath.hashCode
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
object JavaSourceLocation {
|
|
|
|
def apply(node: CGNode, inst: SSAInstruction): JavaSourceLocation = {
|
|
|
|
val (line, path, className, method) = Util.getJavaSourceInfo(node, inst)
|
|
|
|
new JavaSourceLocation(line, path)
|
|
|
|
}
|
|
|
|
|
|
|
|
def apply(node: CGNode, csr: CallSiteReference): JavaSourceLocation = apply(node, node.getIR.getCalls(csr)(0))
|
|
|
|
|
|
|
|
def apply(node: CGNode): JavaSourceLocation = apply(node, node.getIR.getInstructions.find({ i => i != null }).get)
|
|
|
|
}
|