-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse plugin for #4: Boxing Overloading
- Loading branch information
Showing
9 changed files
with
67 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters