Skip to content

Commit

Permalink
eclipse plugin for #4: Boxing Overloading
Browse files Browse the repository at this point in the history
  • Loading branch information
amelentev committed Nov 19, 2012
1 parent 634b929 commit e8ad485
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 38 deletions.
2 changes: 1 addition & 1 deletion eclipse-oo-plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Require-Bundle: org.eclipse.jdt.core;bundle-version="3.7.0",
org.eclipse.equinox.weaving.aspectj,
org.eclipse.equinox.weaving.caching
Eclipse-SupplementBundle: org.eclipse.jdt.core
Export-Package: javaoo.eclipse;aspects="ExpressionAspect,BinaryExpressionAspect,UnaryExpressionAspect,ArrayReferenceAspect,AssignmentAspect"
Export-Package: javaoo.eclipse;aspects="ExpressionAspect,BinaryExpressionAspect,UnaryExpressionAspect,ArrayReferenceAspect,AssignmentAspect,StatementAspect"
1 change: 1 addition & 0 deletions eclipse-oo-plugin/META-INF/aop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<aspect name="javaoo.eclipse.UnaryExpressionAspect" />
<aspect name="javaoo.eclipse.ArrayReferenceAspect" />
<aspect name="javaoo.eclipse.AssignmentAspect" />
<aspect name="javaoo.eclipse.StatementAspect" />
</aspects>
</aspectj>
1 change: 1 addition & 0 deletions eclipse-oo-plugin/src/META-INF/aop-ajc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<aspect name="javaoo.eclipse.BinaryExpressionAspect"/>
<aspect name="javaoo.eclipse.AssignmentAspect"/>
<aspect name="javaoo.eclipse.ArrayReferenceAspect"/>
<aspect name="javaoo.eclipse.StatementAspect"/>
</aspects>
</aspectj>
2 changes: 2 additions & 0 deletions eclipse-oo-plugin/src/javaoo/eclipse/ArrayReferenceAspect.aj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeIds;

@SuppressWarnings("restriction")
public aspect ArrayReferenceAspect implements TypeIds {
declare precedence: ExpressionAspect;

pointcut resolveType(ArrayReference that, BlockScope scope):
this(that) && within(org.eclipse.jdt.internal.compiler.ast.ArrayReference) &&
execution(* org.eclipse.jdt.internal.compiler.ast.ArrayReference.resolveType(BlockScope)) &&
Expand Down
18 changes: 0 additions & 18 deletions eclipse-oo-plugin/src/javaoo/eclipse/BinaryExpressionAspect.aj
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,6 @@ public aspect BinaryExpressionAspect {
return that.translate==null;
}

pointcut generateCode(BinaryExpression that, BlockScope scope, CodeStream stream, boolean valueRequired):
this(that) && within(org.eclipse.jdt.internal.compiler.ast.BinaryExpression) &&
execution(* org.eclipse.jdt.internal.compiler.ast.BinaryExpression.generateCode(BlockScope, CodeStream, boolean)) &&
args(scope, stream, valueRequired);

void around(BinaryExpression that, BlockScope scope, CodeStream codeStream, boolean valueRequired):
generateCode(that, scope, codeStream, valueRequired) {
if (that.translate==null) {
proceed(that, scope, codeStream, valueRequired);
return;
}
Utils.removeAndGetTranslate(that).generateCode(scope, codeStream, valueRequired);
if (valueRequired)
codeStream.generateImplicitConversion(that.implicitConversion);
codeStream.recordPositionsFrom(codeStream.position, that.sourceStart);
return;
}

pointcut resolveType(BinaryExpression be, BlockScope scope):
this(be) && within(org.eclipse.jdt.internal.compiler.ast.BinaryExpression) &&
execution(* org.eclipse.jdt.internal.compiler.ast.BinaryExpression.resolveType(BlockScope)) &&
Expand Down
15 changes: 15 additions & 0 deletions eclipse-oo-plugin/src/javaoo/eclipse/ExpressionAspect.aj
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package javaoo.eclipse;

import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;

public aspect ExpressionAspect {
public Expression Expression.translate;

pointcut generateCode(Expression that, BlockScope currentScope, CodeStream codeStream, boolean valueRequired):
execution(* org.eclipse.jdt.internal.compiler.ast.Expression.generateCode(BlockScope, CodeStream, boolean)) &&
this(that) && args(currentScope, codeStream, valueRequired);

void around(Expression that, BlockScope currentScope, CodeStream codeStream, boolean valueRequired):
generateCode(that, currentScope, codeStream, valueRequired) {
if (that.translate == null) {
proceed(that, currentScope, codeStream, valueRequired);
} else {
Utils.removeAndGetTranslate(that).generateCode(currentScope, codeStream, valueRequired);
}
}
}
46 changes: 46 additions & 0 deletions eclipse-oo-plugin/src/javaoo/eclipse/StatementAspect.aj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2012 Artem Melentyev <[email protected]>.
* 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
*
* Contributors:
* Artem Melentyev <[email protected]> - initial API and implementation
******************************************************************************/
package javaoo.eclipse;

import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.Statement;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.Scope;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;

public aspect StatementAspect {
pointcut isBoxingCompatible(Statement that, TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope):
this(that) && within(org.eclipse.jdt.internal.compiler.ast.Statement) &&
execution(* org.eclipse.jdt.internal.compiler.ast.Statement.isBoxingCompatible(TypeBinding, TypeBinding, Expression, Scope)) &&
args(expressionType, targetType, expression, scope);

boolean around(Statement that, TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope):
isBoxingCompatible(that, expressionType, targetType, expression, scope) {
return proceed(that, expressionType, targetType, expression, scope)
|| tryBoxingOverload(expressionType, targetType, expression, scope);
}
private static boolean tryBoxingOverload(TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope) {
if (!(scope instanceof BlockScope)) return false;
BlockScope bscope = (BlockScope) scope;
Expression receiver = new SingleNameReference(targetType.shortReadableName(), expression.sourceStart);
receiver.resolvedType = targetType;
MessageSend ms = Utils.findMethod(bscope, receiver, "valueOf", new Expression[]{expression}); //$NON-NLS-1$
if (ms != null && ms.resolvedType == targetType) {
ms.resolve(bscope);
expression.translate = ms;
expression.resolvedType = ms.resolvedType;
return true;
}
return false;
}
}
19 changes: 0 additions & 19 deletions eclipse-oo-plugin/src/javaoo/eclipse/UnaryExpressionAspect.aj
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,7 @@ public aspect UnaryExpressionAspect {
}
return null;
}

pointcut generateCode(UnaryExpression that, BlockScope scope, CodeStream stream, boolean valueRequired):
this(that) && within(org.eclipse.jdt.internal.compiler.ast.UnaryExpression) &&
execution(* org.eclipse.jdt.internal.compiler.ast.UnaryExpression.generateCode(BlockScope, CodeStream, boolean)) &&
args(scope, stream, valueRequired);

// same as in BinaryExpressionAspect
void around(UnaryExpression that, BlockScope scope, CodeStream codeStream, boolean valueRequired):
generateCode(that, scope, codeStream, valueRequired) {
if (that.translate == null) {
proceed(that, scope, codeStream, valueRequired);
return;
}
Utils.removeAndGetTranslate(that).generateCode(scope, codeStream, valueRequired);
if (valueRequired)
codeStream.generateImplicitConversion(that.implicitConversion);
codeStream.recordPositionsFrom(codeStream.position, that.sourceStart);
return;
}

pointcut resolveType(UnaryExpression that, BlockScope scope):
this(that) && within(org.eclipse.jdt.internal.compiler.ast.UnaryExpression) &&
execution(* org.eclipse.jdt.internal.compiler.ast.UnaryExpression.resolveType(BlockScope)) &&
Expand Down
1 change: 1 addition & 0 deletions eclipse-oo-plugin/test/javaoo/eclipse/AspectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static void main(String[] args) throws Exception {
compile("ListIndexGet");
compile("ListIndexSet");
compile("MapIndex");
compile("ValueOf");
compile("CompAssBug", "tests/");
}
}

0 comments on commit e8ad485

Please sign in to comment.