diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/FieldData.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/FieldData.java index 082d97936f2..219199d7134 100644 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/FieldData.java +++ b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/FieldData.java @@ -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; + } } diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/FieldDataImpl.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/FieldDataImpl.java deleted file mode 100644 index 0164699d8ab..00000000000 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/FieldDataImpl.java +++ /dev/null @@ -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; - } -} diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/InterceptionInstrumenter.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/InterceptionInstrumenter.java index 2e56fab08a7..5ee478402a3 100644 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/InterceptionInstrumenter.java +++ b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/InterceptionInstrumenter.java @@ -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(), diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MemberData.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MemberData.java index 31b4641776e..8a0537e0e0a 100644 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MemberData.java +++ b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MemberData.java @@ -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; + } } diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MemberDataImpl.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MemberDataImpl.java deleted file mode 100644 index f2cc1f00c58..00000000000 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MemberDataImpl.java +++ /dev/null @@ -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; - } -} diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodData.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodData.java index 4be00c227cf..31936fea2fa 100644 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodData.java +++ b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodData.java @@ -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; + } } diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodDataImpl.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodDataImpl.java deleted file mode 100644 index 0f738409885..00000000000 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodDataImpl.java +++ /dev/null @@ -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; - } -} diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenter.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenter.java index c2c347ce60a..d1e4be18737 100644 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenter.java +++ b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenter.java @@ -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 enterData; + private final List normalReturnData; + private final List exceptionData; + private final boolean logApplications; - List getNormalReturnData(); + public MethodInstrumenter( + String debugName, + Pattern classPattern, Pattern namePattern, + Pattern descPattern, + boolean allowMultipleMatches, + List enterData, + List normalReturnData, + List 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 getExceptionData(); + public boolean allowsMultipleMatches() { + return allowMultipleMatches; + } - List 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 getEnterData() { + return enterData; + } + + public List getNormalReturnData() { + return normalReturnData; + } + + public List getExceptionData() { + return exceptionData; + } + + @Override + public String toString() { + return debugName + "[" + classPattern + ":" + namePattern + " " + descPattern + (allowMultipleMatches ? " multiple" : "") + "]"; + } } diff --git a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenterImpl.java b/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenterImpl.java deleted file mode 100644 index 8f666fc4412..00000000000 --- a/compiler/preloader/instrumentation/src/org/jetbrains/jet/preloading/instrumentation/MethodInstrumenterImpl.java +++ /dev/null @@ -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 enterData; - private final List normalReturnData; - private final List exceptionData; - private final boolean logApplications; - - public MethodInstrumenterImpl( - String debugName, - Pattern classPattern, Pattern namePattern, - Pattern descPattern, - boolean allowMultipleMatches, - List enterData, - List normalReturnData, - List 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 getEnterData() { - return enterData; - } - - @Override - public List getNormalReturnData() { - return normalReturnData; - } - - @Override - public List getExceptionData() { - return exceptionData; - } - - @Override - public String toString() { - return debugName + "[" + classPattern + ":" + namePattern + " " + descPattern + (allowMultipleMatches ? " multiple" : "") + "]"; - } -}