Unneeded interfaces removed

This commit is contained in:
Andrey Breslav
2013-05-13 16:10:22 +04:00
parent 71791d6080
commit 9f7a4ffe56
9 changed files with 135 additions and 262 deletions
@@ -18,6 +18,16 @@ package org.jetbrains.jet.preloading.instrumentation;
import org.jetbrains.asm4.Type;
interface FieldData extends MemberData {
Type getRuntimeType();
class FieldData extends MemberData {
private final Type runtimeType;
public FieldData(String declaringClass, String name, String desc, Type runtimeType) {
super(declaringClass, name, desc);
this.runtimeType = runtimeType;
}
public Type getRuntimeType() {
return runtimeType;
}
}
@@ -1,34 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.preloading.instrumentation;
import org.jetbrains.asm4.Type;
class FieldDataImpl extends MemberDataImpl implements FieldData {
private final Type runtimeType;
public FieldDataImpl(String declaringClass, String name, String desc, Type runtimeType) {
super(declaringClass, name, desc);
this.runtimeType = runtimeType;
}
@Override
public Type getRuntimeType() {
return runtimeType;
}
}
@@ -111,7 +111,7 @@ public class InterceptionInstrumenter {
String nameFromAnnotation = annotation.methodName();
String methodName = nameFromAnnotation.isEmpty() ? field.getName() : nameFromAnnotation;
MethodInstrumenterImpl instrumenter = new MethodInstrumenterImpl(
MethodInstrumenter instrumenter = new MethodInstrumenter(
field.getDeclaringClass().getSimpleName() + "." + field.getName(),
classPattern,
compilePattern(methodName),
@@ -147,7 +147,7 @@ public class InterceptionInstrumenter {
}
private static FieldData getFieldData(Field field, Class<?> runtimeType) {
return new FieldDataImpl(
return new FieldData(
Type.getInternalName(field.getDeclaringClass()),
field.getName(),
Type.getDescriptor(field.getType()),
@@ -188,7 +188,7 @@ public class InterceptionInstrumenter {
}
}
}
return new MethodDataImpl(
return new MethodData(
interceptorField,
Type.getInternalName(method.getDeclaringClass()),
method.getName(),
@@ -16,8 +16,27 @@
package org.jetbrains.jet.preloading.instrumentation;
interface MemberData {
String getDeclaringClass();
String getName();
String getDesc();
class MemberData {
private final String declaringClass;
private final String name;
private final String desc;
public MemberData(String declaringClass, String name, String desc) {
this.declaringClass = declaringClass;
this.name = name;
this.desc = desc;
}
public String getDeclaringClass() {
return declaringClass;
}
public String getName() {
return name;
}
public String getDesc() {
return desc;
}
}
@@ -1,45 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.preloading.instrumentation;
class MemberDataImpl implements MemberData {
private final String declaringClass;
private final String name;
private final String desc;
public MemberDataImpl(String declaringClass, String name, String desc) {
this.declaringClass = declaringClass;
this.name = name;
this.desc = desc;
}
@Override
public String getDeclaringClass() {
return declaringClass;
}
@Override
public String getName() {
return name;
}
@Override
public String getDesc() {
return desc;
}
}
@@ -16,18 +16,48 @@
package org.jetbrains.jet.preloading.instrumentation;
interface MethodData extends MemberData {
FieldData getOwnerField();
public class MethodData extends MemberData {
private final FieldData ownerField;
private final int thisParameterIndex;
private final int methodNameParameterIndex;
private final int methodDescParameterIndex;
private final int allArgsParameterIndex;
// -1 for no @This parameter
int getThisParameterIndex();
MethodData(
FieldData ownerField,
String declaringClass,
String name,
String desc,
int thisParameterIndex,
int methodNameParameterIndex,
int methodDescParameterIndex,
int allArgsParameterIndex
) {
super(declaringClass, name, desc);
this.ownerField = ownerField;
this.thisParameterIndex = thisParameterIndex;
this.methodNameParameterIndex = methodNameParameterIndex;
this.methodDescParameterIndex = methodDescParameterIndex;
this.allArgsParameterIndex = allArgsParameterIndex;
}
// -1 for no @MethodName
int getMethodNameParameterIndex();
public FieldData getOwnerField() {
return ownerField;
}
// -1 for no @MethodDesc
int getMethodDescParameterIndex();
public int getThisParameterIndex() {
return thisParameterIndex;
}
// -1 for no @AllArgs
int getAllArgsParameterIndex();
public int getMethodNameParameterIndex() {
return methodNameParameterIndex;
}
public int getMethodDescParameterIndex() {
return methodDescParameterIndex;
}
public int getAllArgsParameterIndex() {
return allArgsParameterIndex;
}
}
@@ -1,68 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.preloading.instrumentation;
public class MethodDataImpl extends MemberDataImpl implements MethodData {
private final FieldData ownerField;
private final int thisParameterIndex;
private final int methodNameParameterIndex;
private final int methodDescParameterIndex;
private final int allArgsParameterIndex;
MethodDataImpl(
FieldData ownerField,
String declaringClass,
String name,
String desc,
int thisParameterIndex,
int methodNameParameterIndex,
int methodDescParameterIndex,
int allArgsParameterIndex
) {
super(declaringClass, name, desc);
this.ownerField = ownerField;
this.thisParameterIndex = thisParameterIndex;
this.methodNameParameterIndex = methodNameParameterIndex;
this.methodDescParameterIndex = methodDescParameterIndex;
this.allArgsParameterIndex = allArgsParameterIndex;
}
@Override
public FieldData getOwnerField() {
return ownerField;
}
@Override
public int getThisParameterIndex() {
return thisParameterIndex;
}
@Override
public int getMethodNameParameterIndex() {
return methodNameParameterIndex;
}
@Override
public int getMethodDescParameterIndex() {
return methodDescParameterIndex;
}
@Override
public int getAllArgsParameterIndex() {
return allArgsParameterIndex;
}
}
@@ -17,17 +17,67 @@
package org.jetbrains.jet.preloading.instrumentation;
import java.util.List;
import java.util.regex.Pattern;
interface MethodInstrumenter {
boolean isApplicable(String name, String desc);
class MethodInstrumenter {
private final String debugName;
private final Pattern classPattern;
private final Pattern namePattern;
private final Pattern descPattern;
private final boolean allowMultipleMatches;
private final List<MethodData> enterData;
private final List<MethodData> normalReturnData;
private final List<MethodData> exceptionData;
private final boolean logApplications;
List<MethodData> getNormalReturnData();
public MethodInstrumenter(
String debugName,
Pattern classPattern, Pattern namePattern,
Pattern descPattern,
boolean allowMultipleMatches,
List<MethodData> enterData,
List<MethodData> normalReturnData,
List<MethodData> exceptionData, boolean logApplications
) {
this.debugName = debugName;
this.classPattern = classPattern;
this.namePattern = namePattern;
this.descPattern = descPattern;
this.allowMultipleMatches = allowMultipleMatches;
this.enterData = enterData;
this.normalReturnData = normalReturnData;
this.exceptionData = exceptionData;
this.logApplications = logApplications;
}
List<MethodData> getExceptionData();
public boolean allowsMultipleMatches() {
return allowMultipleMatches;
}
List<MethodData> getEnterData();
public void reportApplication(String className, String methodName, String methodDesc) {
if (logApplications) {
System.out.println(toString() + " applied to " + className + ":" + methodName + methodDesc);
}
}
boolean allowsMultipleMatches();
public boolean isApplicable(String name, String desc) {
return namePattern.matcher(name).matches() && descPattern.matcher(desc).matches();
}
void reportApplication(String className, String methodName, String methodDesc);
public List<MethodData> getEnterData() {
return enterData;
}
public List<MethodData> getNormalReturnData() {
return normalReturnData;
}
public List<MethodData> getExceptionData() {
return exceptionData;
}
@Override
public String toString() {
return debugName + "[" + classPattern + ":" + namePattern + " " + descPattern + (allowMultipleMatches ? " multiple" : "") + "]";
}
}
@@ -1,89 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.preloading.instrumentation;
import java.util.List;
import java.util.regex.Pattern;
class MethodInstrumenterImpl implements MethodInstrumenter {
private final String debugName;
private final Pattern classPattern;
private final Pattern namePattern;
private final Pattern descPattern;
private final boolean allowMultipleMatches;
private final List<MethodData> enterData;
private final List<MethodData> normalReturnData;
private final List<MethodData> exceptionData;
private final boolean logApplications;
public MethodInstrumenterImpl(
String debugName,
Pattern classPattern, Pattern namePattern,
Pattern descPattern,
boolean allowMultipleMatches,
List<MethodData> enterData,
List<MethodData> normalReturnData,
List<MethodData> exceptionData, boolean logApplications
) {
this.debugName = debugName;
this.classPattern = classPattern;
this.namePattern = namePattern;
this.descPattern = descPattern;
this.allowMultipleMatches = allowMultipleMatches;
this.enterData = enterData;
this.normalReturnData = normalReturnData;
this.exceptionData = exceptionData;
this.logApplications = logApplications;
}
@Override
public boolean allowsMultipleMatches() {
return allowMultipleMatches;
}
@Override
public void reportApplication(String className, String methodName, String methodDesc) {
if (logApplications) {
System.out.println(toString() + " applied to " + className + ":" + methodName + methodDesc);
}
}
@Override
public boolean isApplicable(String name, String desc) {
return namePattern.matcher(name).matches() && descPattern.matcher(desc).matches();
}
@Override
public List<MethodData> getEnterData() {
return enterData;
}
@Override
public List<MethodData> getNormalReturnData() {
return normalReturnData;
}
@Override
public List<MethodData> getExceptionData() {
return exceptionData;
}
@Override
public String toString() {
return debugName + "[" + classPattern + ":" + namePattern + " " + descPattern + (allowMultipleMatches ? " multiple" : "") + "]";
}
}