summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpschonbac2009-02-22 12:42:19 (EST)
committer pschonbac2009-02-22 12:42:19 (EST)
commit168ee03ffefced4beafe2fb6d6a6bd05d137e63f (patch)
tree22a52fa5034e93302015d7b76000e50d479a699b
parentf1a73033d1c2a4d26bce888923aa36caebe4232d (diff)
downloadorg.eclipse.xpand-168ee03ffefced4beafe2fb6d6a6bd05d137e63f.zip
org.eclipse.xpand-168ee03ffefced4beafe2fb6d6a6bd05d137e63f.tar.gz
org.eclipse.xpand-168ee03ffefced4beafe2fb6d6a6bd05d137e63f.tar.bz2
Ensured correct regression
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/AbstractExpressionVisitor.java94
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/BooleanLiteral.java3
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java50
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/ConstructorCallExpression.java7
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/IntegerLiteral.java2
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/OperationCall.java141
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/SwitchExpression.java15
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ExpressionProposalComputer.java8
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactory.java11
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactoryDefaultImpl.java1
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/BaseSpecialTreatment.java20
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/ExpressionModelPresentation.java30
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java10
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/IntegerTypeImpl.java126
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/StringTypeImpl.java592
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/AbstractExtension.java332
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/Check.java214
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/JavaExtensionStatement.java52
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java15
19 files changed, 876 insertions, 847 deletions
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/AbstractExpressionVisitor.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/AbstractExpressionVisitor.java
index 287f5ef..1abc1db 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/AbstractExpressionVisitor.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/AbstractExpressionVisitor.java
@@ -10,8 +10,9 @@
*******************************************************************************/
package org.eclipse.internal.xtend.expression.ast;
-public abstract class AbstractExpressionVisitor extends AbstractVisitor{
+public abstract class AbstractExpressionVisitor extends AbstractVisitor {
+ @Override
public final Object visit(final ISyntaxElement ele) {
Object result = null;
if (result == null && ele instanceof BooleanOperation) {
@@ -71,120 +72,139 @@ public abstract class AbstractExpressionVisitor extends AbstractVisitor{
return result;
}
- protected Object visitBooleanOperation(BooleanOperation node){
- if(node.getLeft() != null)
+ protected Object visitBooleanOperation(BooleanOperation node) {
+ if (node.getLeft() != null) {
node.getLeft().accept(this);
- if(node.getRight() != null)
+ }
+ if (node.getRight() != null) {
node.getRight().accept(this);
+ }
return node;
}
- protected Object visitCast(Cast node){
- if(node.getTarget() != null)
+ protected Object visitCast(Cast node) {
+ if (node.getTarget() != null) {
node.getTarget().accept(this);
+ }
return node;
}
- protected Object visitConstructorCallExpression(ConstructorCallExpression node){
+ protected Object visitConstructorCallExpression(ConstructorCallExpression node) {
return node;
}
- protected Object visitGlobalVarExpression(GlobalVarExpression node){
+ protected Object visitGlobalVarExpression(GlobalVarExpression node) {
return node;
}
protected Object visitChainExpression(ChainExpression ce) {
- if(ce.getFirst() != null)
+ if (ce.getFirst() != null) {
ce.getFirst().accept(this);
- if(ce.getNext() != null)
+ }
+ if (ce.getNext() != null) {
ce.getNext().accept(this);
+ }
return ce;
}
protected Object visitFeatureCall(FeatureCall fc) {
- if(fc.getTarget() != null)
+ if (fc.getTarget() != null) {
fc.getTarget().accept(this);
+ }
return fc;
}
- protected Object visitCollectionExpression(CollectionExpression node){
- if(node.getClosure() != null)
+ protected Object visitCollectionExpression(CollectionExpression node) {
+ if (node.getClosure() != null) {
node.getClosure().accept(this);
- if(node.getTarget() != null)
+ }
+ if (node.getTarget() != null) {
node.getTarget().accept(this);
+ }
return node;
}
protected Object visitOperationCall(OperationCall oc) {
- if(oc.getTarget() != null)
+ if (oc.getTarget() != null) {
oc.getTarget().accept(this);
- if(oc.getParamsAsList() != null){
- for(Expression expr: oc.getParamsAsList()){
+ }
+ if (oc.getParamsAsList() != null) {
+ for (Expression expr : oc.getParamsAsList()) {
expr.accept(this);
}
}
return oc;
}
- protected Object visitTypeSelectExpression(TypeSelectExpression node){
- if(node.getTarget() != null)
+ protected Object visitTypeSelectExpression(TypeSelectExpression node) {
+ if (node.getTarget() != null) {
node.getTarget().accept(this);
+ }
return node;
}
- protected Object visitIfExpression(IfExpression node){
- if(node.getCondition() != null)
+ protected Object visitIfExpression(IfExpression node) {
+ if (node.getCondition() != null) {
node.getCondition().accept(this);
- if(node.getThenPart() != null)
+ }
+ if (node.getThenPart() != null) {
node.getThenPart().accept(this);
- if(node.getElsePart() != null)
+ }
+ if (node.getElsePart() != null) {
node.getElsePart().accept(this);
+ }
return node;
}
- protected Object visitLetExpression(LetExpression node){
- if(node.getTargetExpression() != null)
+ protected Object visitLetExpression(LetExpression node) {
+ if (node.getTargetExpression() != null) {
node.getTargetExpression().accept(this);
- if(node.getVarExpression() != null)
+ }
+ if (node.getVarExpression() != null) {
node.getVarExpression().accept(this);
+ }
return node;
}
- protected Object visitSwitchExpression(SwitchExpression node){
+ protected Object visitSwitchExpression(SwitchExpression node) {
for (Case caze : node.getCases()) {
- if(caze.getCondition() != null)
+ if (caze.getCondition() != null) {
caze.getCondition().accept(this);
- if(caze.getThenPart() != null)
+ }
+ if (caze.getThenPart() != null) {
caze.getThenPart().accept(this);
}
- if(node.getSwitchExpr() != null)
+ }
+ if (node.getSwitchExpr() != null) {
node.getSwitchExpr().accept(this);
- if(node.getDefaultExpr() != null)
+ }
+ if (node.getDefaultExpr() != null) {
node.getDefaultExpr().accept(this);
+ }
return node;
}
- protected Object visitListLiteral(ListLiteral node){
+ protected Object visitListLiteral(ListLiteral node) {
return node;
}
- protected Object visitBooleanLiteral(BooleanLiteral node){
+ protected Object visitBooleanLiteral(BooleanLiteral node) {
return node;
}
- protected Object visitIntegerLiteral(IntegerLiteral node){
+ protected Object visitIntegerLiteral(IntegerLiteral node) {
return node;
}
- protected Object visitNullLiteral(NullLiteral node){
+ protected Object visitNullLiteral(NullLiteral node) {
return node;
}
- protected Object visitRealLiteral(RealLiteral node){
+ protected Object visitRealLiteral(RealLiteral node) {
return node;
}
- protected Object visitStringLiteral(StringLiteral node){
+ protected Object visitStringLiteral(StringLiteral node) {
return node;
}
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/BooleanLiteral.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/BooleanLiteral.java
index 4a3c0ab..cf86724 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/BooleanLiteral.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/BooleanLiteral.java
@@ -23,7 +23,7 @@ import org.eclipse.xtend.typesystem.Type;
*/
public class BooleanLiteral extends Literal {
- public BooleanLiteral( final Identifier literalValue) {
+ public BooleanLiteral(final Identifier literalValue) {
super(literalValue);
}
@@ -32,6 +32,7 @@ public class BooleanLiteral extends Literal {
return new Boolean(getLiteralValue().getValue());
}
+ @Override
public Type analyzeInternal(final ExecutionContext ctx, final Set<AnalysationIssue> issues) {
return ctx.getBooleanType();
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java
index 4c520eb..6085e70 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java
@@ -41,7 +41,7 @@ public class CollectionExpression extends FeatureCall {
private Identifier eleName;
public CollectionExpression(final Identifier name, final Identifier eleName, final Expression closure) {
- super(name,null);
+ super(name, null);
this.eleName = eleName;
this.closure = closure;
}
@@ -51,7 +51,7 @@ public class CollectionExpression extends FeatureCall {
return super.toStringInternal() + "(" + (eleName != null ? eleName.getValue() + "|" : "") + closure + ")";
}
- public Expression getClosure () {
+ public Expression getClosure() {
return closure;
}
@@ -63,14 +63,15 @@ public class CollectionExpression extends FeatureCall {
if (v != null) {
targetObj = v.getValue();
}
- } else {
+ }
+ else {
targetObj = getTarget().evaluate(ctx);
}
if (targetObj == null)
return ctx.handleNullEvaluation(this);
- if (!(targetObj instanceof Collection)) {
- throw new EvaluationException("Couldn't call '"+this.toString()+"' on an object of java type "+targetObj.getClass().getName(),this, ctx);
- }
+ if (!(targetObj instanceof Collection))
+ throw new EvaluationException("Couldn't call '" + toString() + "' on an object of java type "
+ + targetObj.getClass().getName(), this, ctx);
if (getName().getValue().equals(SyntaxConstants.COLLECT))
return executeCollect((Collection) targetObj, ctx);
@@ -97,22 +98,23 @@ public class CollectionExpression extends FeatureCall {
private Object executeSortBy(Collection collection, final ExecutionContext ctx) {
List<Object> result = new ArrayList<Object>();
result.addAll(collection);
- Collections.sort(result, new Comparator<Object> () {
+ Collections.sort(result, new Comparator<Object>() {
@SuppressWarnings("unchecked")
public int compare(Object o1, Object o2) {
final Object a = closure.evaluate(ctx.cloneWithVariable(new Variable(getElementName(), o1)));
final Object b = closure.evaluate(ctx.cloneWithVariable(new Variable(getElementName(), o2)));
- if (a==b)
+ if (a == b)
return 0;
- if (a==null)
+ if (a == null)
return -1;
- if (b==null)
+ if (b == null)
return 1;
if (a instanceof Comparable)
- return ((Comparable)a).compareTo(b);
+ return ((Comparable) a).compareTo(b);
return a.toString().compareTo(b.toString());
- }});
+ }
+ });
return result;
}
@@ -183,7 +185,8 @@ public class CollectionExpression extends FeatureCall {
resultCol.add(ele);
}
}
- if ( resultCol.size() == 0 ) return null;
+ if (resultCol.size() == 0)
+ return null;
return resultCol.iterator().next();
}
@@ -206,7 +209,8 @@ public class CollectionExpression extends FeatureCall {
if (v != null) {
targetType = (Type) v.getValue();
}
- } else {
+ }
+ else {
targetType = getTarget().analyze(ctx, issues);
}
if (targetType == null)
@@ -229,19 +233,20 @@ public class CollectionExpression extends FeatureCall {
return ctx.getListType(closureType);
else
return ctx.getCollectionType(closureType);
- } else if (getName().getValue().equals(SyntaxConstants.SELECT)
- || getName().getValue().equals(SyntaxConstants.REJECT)
- ) {
+ }
+ else if (getName().getValue().equals(SyntaxConstants.SELECT)
+ || getName().getValue().equals(SyntaxConstants.REJECT))
return targetType;
- } else if (getName().getValue().equals(SyntaxConstants.SELECTFIRST)) {
+ else if (getName().getValue().equals(SyntaxConstants.SELECTFIRST))
return innerType;
- } else if (getName().getValue().equals(SyntaxConstants.SORT_BY)) {
+ else if (getName().getValue().equals(SyntaxConstants.SORT_BY))
return ctx.getListType(innerType);
- }else if (getName().getValue().equals(SyntaxConstants.TYPE_SELECT)) {
+ else if (getName().getValue().equals(SyntaxConstants.TYPE_SELECT)) {
if (closureType == null)
return null;
return ctx.getListType(closureType);
- } else if (getName().getValue().equals(SyntaxConstants.EXISTS)
+ }
+ else if (getName().getValue().equals(SyntaxConstants.EXISTS)
|| getName().getValue().equals(SyntaxConstants.NOT_EXISTS)
|| getName().getValue().equals(SyntaxConstants.FOR_ALL)) {
if (!ctx.getBooleanType().isAssignableFrom(closureType)) {
@@ -249,7 +254,8 @@ public class CollectionExpression extends FeatureCall {
+ closureType, closure));
}
result = ctx.getBooleanType();
- } else {
+ }
+ else {
issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR, "Unknown operation : "
+ getName().getValue(), this));
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/ConstructorCallExpression.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/ConstructorCallExpression.java
index 175198f..01252c2 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/ConstructorCallExpression.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/ConstructorCallExpression.java
@@ -29,7 +29,11 @@ public class ConstructorCallExpression extends Expression {
this.type = type;
}
- public String getTypeName () {
+ public Identifier getType() {
+ return type;
+ }
+
+ public String getTypeName() {
return type.getValue();
}
@@ -42,6 +46,7 @@ public class ConstructorCallExpression extends Expression {
throw new EvaluationException("Couldn't find type " + type, this, ctx);
}
+ @Override
public Type analyzeInternal(final ExecutionContext ctx, final Set<AnalysationIssue> issues) {
final Type t = ctx.getTypeForName(type.getValue());
if (t == null) {
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/IntegerLiteral.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/IntegerLiteral.java
index d766302..00ff932 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/IntegerLiteral.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/IntegerLiteral.java
@@ -31,7 +31,7 @@ public class IntegerLiteral extends Literal {
@Override
public Object evaluateInternal(final ExecutionContext ctx) {
- return new Long(getLiteralValue().getValue());
+ return new BigInteger(getLiteralValue().getValue());
}
public Type analyzeInternal(final ExecutionContext ctx, final Set<AnalysationIssue> issues) {
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/OperationCall.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/OperationCall.java
index fd92af4..fdc7f99 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/OperationCall.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/OperationCall.java
@@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -35,7 +36,7 @@ import org.eclipse.xtend.typesystem.Type;
*/
public class OperationCall extends FeatureCall {
- private final Expression[] params;
+ private Expression[] params;
public OperationCall(final Identifier name, final Expression target, final Expression... params) {
super(name, target);
@@ -55,7 +56,7 @@ public class OperationCall extends FeatureCall {
// evaluate from left to right
// first the target
Object targetObj = null;
- if (getTarget() != null) {
+ if (getTarget()!=null) {
targetObj = getTarget().evaluate(ctx);
}
// then the parameters in the defined order
@@ -65,7 +66,7 @@ public class OperationCall extends FeatureCall {
evaluatedParams[i] = getParams()[i].evaluate(ctx);
}
}
-
+
if (getTarget() == null) {
// extension
final Extension f = ctx.getExtension(getName().getValue(), evaluatedParams);
@@ -73,12 +74,10 @@ public class OperationCall extends FeatureCall {
ProfileCollector.getInstance().enter(f.toString());
try {
return evaluate(f, evaluatedParams, ctx);
- }
- catch (final EvaluationException e) {
+ } catch (EvaluationException e) {
e.addStackElement(this, ctx);
throw e;
- }
- finally {
+ } finally {
ProfileCollector.getInstance().leave();
}
}
@@ -86,11 +85,10 @@ public class OperationCall extends FeatureCall {
// implicite
final Variable var = ctx.getVariable(ExecutionContext.IMPLICIT_VARIABLE);
if (var == null)
- throw new EvaluationException("Couldn't find extension '" + getName().getValue()
- + getParamTypes(evaluatedParams, ctx) + "'!", this, ctx);
+ throw new EvaluationException("Couldn't find extension '" + getName().getValue() + getParamTypes(evaluatedParams, ctx) + "'!", this, ctx);
targetObj = var.getValue();
- }
-
+ }
+
// operation
Operation op = ctx.findOperation(getName().getValue(), targetObj, evaluatedParams);
if (op != null)
@@ -104,12 +102,10 @@ public class OperationCall extends FeatureCall {
try {
ProfileCollector.getInstance().enter(f.toString());
return evaluate(f, ps, ctx);
- }
- catch (final EvaluationException e) {
+ } catch (EvaluationException e) {
e.addStackElement(this, ctx);
throw e;
- }
- finally {
+ } finally {
ProfileCollector.getInstance().leave();
}
}
@@ -117,19 +113,18 @@ public class OperationCall extends FeatureCall {
if (targetObj instanceof Collection) {
final List<Object> result = new ArrayList<Object>();
final Collection<?> col = (Collection<?>) targetObj;
- for (final Object element : col) {
+ for (final Iterator<?> iter = col.iterator(); iter.hasNext();) {
+ final Object element = iter.next();
// operation
op = ctx.findOperation(getName().getValue(), element, evaluatedParams);
if (op != null) {
final Object r = evaluate(op, element, evaluatedParams, ctx);
if (r instanceof Collection) {
result.addAll((Collection<?>) r);
- }
- else {
+ } else {
result.add(r);
}
- }
- else {
+ } else {
// extension as members
ps = new Object[evaluatedParams.length + 1];
ps[0] = element;
@@ -139,31 +134,26 @@ public class OperationCall extends FeatureCall {
Object r = null;
try {
r = evaluate(f, ps, ctx);
- }
- catch (final EvaluationException e) {
+ } catch (EvaluationException e) {
e.addStackElement(this, ctx);
throw e;
}
if (r instanceof Collection) {
result.addAll((Collection<?>) r);
- }
- else {
+ } else {
result.add(r);
}
- }
- else
- throw new EvaluationException("Couldn't find operation '" + getName().getValue()
- + getParamTypes(evaluatedParams, ctx) + "' for " + ctx.getType(targetObj).getName()
- + "!", this, ctx);
+ } else
+ throw new EvaluationException("Couldn't find operation '" + getName().getValue() + getParamTypes(evaluatedParams, ctx) + "' for "
+ + ctx.getType(targetObj).getName() + "!", this, ctx);
}
}
return result;
}
if (targetObj != null && f == null && op == null)
- throw new EvaluationException("Couldn't find operation '" + getName().getValue()
- + getParamTypes(evaluatedParams, ctx) + "' for " + ctx.getType(targetObj).getName() + ".", this,
- ctx);
+ throw new EvaluationException("Couldn't find operation '" + getName().getValue() + getParamTypes(evaluatedParams, ctx) + "' for "
+ + ctx.getType(targetObj).getName() + ".", this, ctx);
return ctx.handleNullEvaluation(this);
}
@@ -197,23 +187,18 @@ public class OperationCall extends FeatureCall {
Extension f = null;
try {
f = ctx.getExtensionForTypes(getName().getValue(), paramTypes);
- }
- catch (final Exception e) {
- issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR, "Error parsing extensions : "
- + e.getMessage(), this));
+ } catch (final Exception e) {
+ issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR, "Error parsing extensions : " + e.getMessage(), this));
}
if (f != null)
return f.getReturnType(paramTypes, ctx, issues);
final Variable var = ctx.getVariable(ExecutionContext.IMPLICIT_VARIABLE);
if (var != null) {
targetType = (Type) var.getValue();
+ } else {
+ issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, "Couldn't find extensions : " + toString(), this));
}
- else {
- issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, "Couldn't find extensions : "
- + toString(), this));
- }
- }
- else {
+ } else {
targetType = getTarget().analyze(ctx, issues);
}
if (targetType == null)
@@ -250,49 +235,43 @@ public class OperationCall extends FeatureCall {
additionalMsg = " or type '" + innerType + "'";
}
- issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, "Couldn't find operation '"
- + getName().getValue() + getParamsString(paramTypes) + "' for type '" + targetType.getName() + "'"
- + additionalMsg, this));
+ issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, "Couldn't find operation '" + getName().getValue()
+ + getParamsString(paramTypes) + "' for type '" + targetType.getName() + "'" + additionalMsg, this));
return null;
}
- private Type getExtensionsReturnType(final ExecutionContext ctx, final Set<AnalysationIssue> issues,
- final Type[] paramTypes, final Type targetType) {
+ private Type getExtensionsReturnType(final ExecutionContext ctx, final Set<AnalysationIssue> issues, final Type[] paramTypes,
+ final Type targetType) {
final Type[] pts = new Type[paramTypes.length + 1];
pts[0] = targetType;
System.arraycopy(paramTypes, 0, pts, 1, paramTypes.length);
Extension f = null;
try {
f = ctx.getExtensionForTypes(getName().getValue(), pts);
- }
- catch (final Exception e) {
- issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR, "Error parsing extensions : "
- + e.getMessage(), this));
+ } catch (final Exception e) {
+ issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR, "Error parsing extensions : " + e.getMessage(), this));
}
if (f != null) {
final Set<AnalysationIssue> temp = new HashSet<AnalysationIssue>();
final Type rt = f.getReturnType(pts, ctx, temp);
if (rt == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR,
- "couldn't resolve return type for extension " + f + "! Errors : " + temp.toString(), this));
+ issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR, "couldn't resolve return type for extension " + f + "! Errors : "
+ + temp.toString(), this));
}
return rt;
- }
- else if (getTarget() == null) { // try without implicite this
+ } else if (getTarget() == null) { // try without implicite this
try {
f = ctx.getExtensionForTypes(getName().getValue(), paramTypes);
- }
- catch (final Exception e) {
- issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR, "Error parsing extensions : "
- + e.getMessage(), this));
+ } catch (final Exception e) {
+ issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR, "Error parsing extensions : " + e.getMessage(), this));
}
if (f != null) {
final Set<AnalysationIssue> temp = new HashSet<AnalysationIssue>();
final Type rt = f.getReturnType(pts, ctx, temp);
if (rt == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR,
- "couldn't resolve return type for extension " + f + "! Errors : " + temp.toString(), this));
+ issues.add(new AnalysationIssue(AnalysationIssue.INTERNAL_ERROR, "couldn't resolve return type for extension " + f
+ + "! Errors : " + temp.toString(), this));
}
return rt;
}
@@ -314,43 +293,36 @@ public class OperationCall extends FeatureCall {
@Override
protected String toStringInternal() {
- return (getTarget() != null ? getTarget().toStringInternal() + "." : "") + getName()
- + getParamsExpressionString(getParams());
+ return (getTarget() != null ? getTarget().toStringInternal() + "." : "") + getName() + getParamsExpressionString(getParams());
}
@Override
- public String getNameString(final ExecutionContext context) {
+ public String getNameString(ExecutionContext context) {
final StringBuffer buff = new StringBuffer();
buff.append(getName().getValue());
buff.append("(");
if (params.length > 0)
- if (context != null) {
+ if (context != null)
buff.append(getParamTypesString(context));
- }
- else {
- // TODO: CK low: Get parameter types from XtendXpandModelManager
- // for Breakpoints
+ else
+ // TODO: CK low: Get parameter types from OawModelManager for Breakpoints
buff.append("..");
- }
return buff.append(")").toString();
}
- private String getParamTypesString(final ExecutionContext context) {
+ private String getParamTypesString(ExecutionContext context) {
final ExecutionContext ctx = context.cloneWithoutMonitor();
final StringBuffer buff = new StringBuffer();
for (int i = 0; i < getParams().length; i++) {
- final Type type = ctx.getType(params[i].evaluate(ctx));
- final String name = type.getName();
- final int pos = name.lastIndexOf("::");
- if (pos < 0) {
+ Type type = ctx.getType(params[i].evaluate(ctx));
+ String name = type.getName();
+ int pos = name.lastIndexOf("::");
+ if (pos < 0)
buff.append(name);
- }
- else {
+ else
buff.append(name.substring(pos + 2));
- }
- if (i + 1 < params.length) {
+ if (i + 1 < params.length)
buff.append(",");
- }
}
return buff.toString();
}
@@ -366,17 +338,16 @@ public class OperationCall extends FeatureCall {
return buff.append(")").toString();
}
- private Object evaluate(final Extension ext, final Object[] params, final ExecutionContext ctx) {
+ private Object evaluate(Extension ext, Object[] params, ExecutionContext ctx) {
ctx.preTask(this);
- final Object result = ext.evaluate(params, ctx);
+ Object result = ext.evaluate(params, ctx);
ctx.postTask(this);
return result;
}
- private Object evaluate(final Operation op, final Object targetObj, final Object[] params,
- final ExecutionContext ctx) {
+ private Object evaluate(Operation op, Object targetObj, Object[] params, ExecutionContext ctx) {
ctx.preTask(this);
- final Object result = op.evaluate(targetObj, params);
+ Object result = op.evaluate(targetObj, params);
ctx.postTask(this);
return result;
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/SwitchExpression.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/SwitchExpression.java
index 4b318f0..464d7e4 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/SwitchExpression.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/SwitchExpression.java
@@ -35,8 +35,7 @@ public class SwitchExpression extends Expression {
private List<Case> cases = null;
- public SwitchExpression(final Expression switchExpr,
- final List<Case> cases, final Expression defaultExpr) {
+ public SwitchExpression(final Expression switchExpr, final List<Case> cases, final Expression defaultExpr) {
this.switchExpr = switchExpr;
this.cases = cases;
this.defaultExpr = defaultExpr;
@@ -45,8 +44,9 @@ public class SwitchExpression extends Expression {
@Override
protected Object evaluateInternal(final ExecutionContext ctx) {
Object switchVal = Boolean.TRUE;
- if (switchExpr != null)
+ if (switchExpr != null) {
switchVal = switchExpr.evaluate(ctx);
+ }
for (final Iterator<Case> iter = cases.iterator(); iter.hasNext();) {
final Case c = iter.next();
final Object caseCondVal = c.getCondition().evaluate(ctx);
@@ -64,10 +64,12 @@ public class SwitchExpression extends Expression {
return (Boolean) new ExpressionFacade(ctx).evaluate("swtch==cse", props);
}
+ @Override
public Type analyzeInternal(final ExecutionContext ctx, final Set<AnalysationIssue> issues) {
Type condType = ctx.getBooleanType();
- if (switchExpr != null)
+ if (switchExpr != null) {
condType = switchExpr.analyze(ctx, issues);
+ }
if (condType == null)
return null;
Type returnType = defaultExpr.analyze(ctx, issues);
@@ -87,7 +89,8 @@ public class SwitchExpression extends Expression {
if (!returnType.isAssignableFrom(caseThenType)) {
if (caseThenType.isAssignableFrom(returnType)) {
returnType = caseThenType;
- } else {
+ }
+ else {
returnType = ctx.getObjectType();
}
}
@@ -110,6 +113,6 @@ public class SwitchExpression extends Expression {
@Override
protected String toStringInternal() {
- return "switch " + switchExpr.toStringInternal() ;
+ return "switch " + switchExpr.toStringInternal();
}
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ExpressionProposalComputer.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ExpressionProposalComputer.java
index 50cb2b5..50de562 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ExpressionProposalComputer.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ExpressionProposalComputer.java
@@ -99,8 +99,8 @@ public class ExpressionProposalComputer implements ProposalComputer {
private final static Map<String, String> blockTokens = new HashMap<String, String>();
static {
- blockTokens.put("(", ")");
- blockTokens.put("{", "}");
+ blockTokens.put("(",")");
+ blockTokens.put("{","}");
}
private static final Pattern QUALIFIED_NAME = Pattern.compile("\\W*(.*)(?:::\\w*)$");
@@ -179,7 +179,7 @@ public class ExpressionProposalComputer implements ProposalComputer {
if (m.matches()) {
String typeName = m.group(1);
implicitVariableType = ctx.getTypeForName(typeName);
- if (implicitVariableType != null) {
+ if (implicitVariableType!=null) {
for (StaticProperty p : implicitVariableType.getAllStaticProperties()) {
if (p.getName().startsWith(prefix)) {
proposals.add(factory.createStaticPropertyProposal(p, prefix, false));
@@ -506,7 +506,7 @@ public class ExpressionProposalComputer implements ProposalComputer {
private final static boolean isOpposite(final CommonToken left, final CommonToken right) {
final String temp = blockTokens.get(left.getText());
- if (temp == null)
+ if (temp==null)
return false;
return temp != null && right.getText().equals(temp);
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactory.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactory.java
index c802850..b095e54 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactory.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactory.java
@@ -24,9 +24,13 @@ public interface ProposalFactory {
/**
* Creates an proposal for a static property
- * @param p The property for which a proposal should be created
- * @param prefix Current evaluation text prefix
- * @param onCollection <code>true</code>: Proposal is computed on a collection
+ *
+ * @param p
+ * The property for which a proposal should be created
+ * @param prefix
+ * Current evaluation text prefix
+ * @param onCollection
+ * <code>true</code>: Proposal is computed on a collection
* @return A proposal for the content assist
*/
public Object createStaticPropertyProposal(StaticProperty p, String prefix, boolean onCollection);
@@ -61,5 +65,4 @@ public interface ProposalFactory {
public boolean isDuplicate(Set<String> nameCache, Object proposal);
public void addToCache(Set<String> nameCache, Object proposal);
-
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactoryDefaultImpl.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactoryDefaultImpl.java
index 758631c..fd8aa5a 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactoryDefaultImpl.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/codeassist/ProposalFactoryDefaultImpl.java
@@ -86,7 +86,6 @@ public class ProposalFactoryDefaultImpl implements ProposalFactory {
if (nameCache == null || proposal == null)
throw new IllegalArgumentException();
-
ProposalImpl p = castToProposal(proposal);
if (p != null) {
if (nameCache.contains(p.getDisplayString()))
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/BaseSpecialTreatment.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/BaseSpecialTreatment.java
index 5af8344..b8e953d 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/BaseSpecialTreatment.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/BaseSpecialTreatment.java
@@ -21,33 +21,29 @@ import org.eclipse.xtend.expression.ExecutionContext;
*/
public abstract class BaseSpecialTreatment {
- public boolean shallNotSuspend(final Object element, final int flag, final ExecutionContext context) {
+ public boolean shallNotSuspend(Object element, int flag, ExecutionContext context) {
return false;
}
- public void adaptSyntaxElement(final SyntaxElement to, final Object element) {
+ public void adaptSyntaxElement(SyntaxElement to, Object element) {
// empty implementation
}
/**
- * add syntax element specific content to the element name that will be
- * shown in Launch view
- *
- * @param se
- * the syntax element
- * @param context
- * the execution context
+ * add syntax element specific content to the element name that will be shown in Launch view
+ * @param se the syntax element
+ * @param context the execution context
* @return the special text to add to the name
*/
- public String adaptElementName(final ISyntaxElement se, final ExecutionContext context) {
+ public String adaptElementName(ISyntaxElement se, ExecutionContext context){
return "";
}
- public ISyntaxElement getSpecialEndSyntaxElement(final ISyntaxElement se) {
+ public ISyntaxElement getSpecialEndSyntaxElement(ISyntaxElement se){
return null;
}
- public int getElementNameLength(final ISyntaxElement se) {
+ public int getElementNameLength(ISyntaxElement se) {
return -1;
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/ExpressionModelPresentation.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/ExpressionModelPresentation.java
index 3ad2082..00b3fa5 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/ExpressionModelPresentation.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/debug/ExpressionModelPresentation.java
@@ -20,8 +20,7 @@ import org.eclipse.xtend.expression.ExpressionFacade;
import org.eclipse.xtend.expression.Variable;
/**
- * This class is responsible for all presentation topics for expressions in the
- * debugger views.
+ * This class is responsible for all presentation topics for expressions in the debugger views.
*
* @author Clemens Kadura (zAJKa)
*/
@@ -31,14 +30,14 @@ public class ExpressionModelPresentation {
// -------------------------------------------------------------------------
- public ExpressionModelPresentation(final Set<BaseSpecialTreatment> specials) {
+ public ExpressionModelPresentation(Set<BaseSpecialTreatment> specials) {
this.specials = specials;
}
// -------------------------------------------------------------------------
- public SyntaxElement getStartPresentation(final ISyntaxElement se, final ExecutionContext context) {
- final SyntaxElement to = new SyntaxElement();
+ public SyntaxElement getStartPresentation(ISyntaxElement se, ExecutionContext context) {
+ SyntaxElement to = new SyntaxElement();
to.containerName = getContainerName(se);
to.elementName = se.getNameString(context);
@@ -49,51 +48,50 @@ public class ExpressionModelPresentation {
return to;
}
- public SyntaxElement getEndPresentation(final ISyntaxElement se, final ExecutionContext context) {
+ public SyntaxElement getEndPresentation(ISyntaxElement se, ExecutionContext context) {
return getStartPresentation(se, context);
}
- public String getVariableSimpleRep(final Object element, final ExecutionContext context) {
+ public String getVariableSimpleRep(Object element, ExecutionContext context) {
if (element == null)
return "null";
if (element instanceof String)
return (String) element;
- return (String) new ExpressionFacade(context.cloneWithVariable(new Variable("this", element)))
- .evaluate("metaType.name");
+ return (String) new ExpressionFacade(context.cloneWithVariable(new Variable("this", element))).evaluate("metaType.name");
}
// -------------------------------------------------------------------------
- public int getStart(final ISyntaxElement se) {
+ public int getStart(ISyntaxElement se) {
if (se instanceof FeatureCall)
return ((FeatureCall) se).getName().getStart();
return se.getStart();
}
- public int getStartingEndPosition(final ISyntaxElement se) {
+ public int getStartingEndPosition(ISyntaxElement se) {
return se.getEnd();
}
// -------------------------------------------------------------------------
- protected String getContainerName(final ISyntaxElement se) {
+ protected String getContainerName(ISyntaxElement se) {
return getTemplateName(se);
}
- protected String getTemplateName(final ISyntaxElement se) {
- final String fileName = se.getFileName();
+ protected String getTemplateName(ISyntaxElement se) {
+ String fileName = se.getFileName();
if (fileName == null)
return "";
return fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length() - 4);
}
- protected String getResource(final ISyntaxElement se) {
+ protected String getResource(ISyntaxElement se) {
if (se.getFileName() == null)
return "";
return se.getFileName();
}
- public String getStringRep(final Object element) {
+ public String getStringRep(Object element) {
if (element == null)
return "null";
return element.toString();
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java
index 37685f4..e8c51cd 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/BuiltinMetaModel.java
@@ -34,7 +34,7 @@ import org.eclipse.xtend.typesystem.Type;
*/
/**
* @author Patrick Schoenbach - Initial API and implementation
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
*/
public final class BuiltinMetaModel implements MetaModel {
@@ -302,15 +302,15 @@ public final class BuiltinMetaModel implements MetaModel {
private final Cache<Object, Type> typeCache = new Cache<Object, Type>() {
@Override
- protected Type createNew(final Object obj) {
+ protected Type createNew(Object obj) {
if (obj == null)
return getVoidType();
if (obj instanceof Set)
- return getSetType(null);
+ return getSetType(getObjectType());
if (obj instanceof List)
- return getListType(null);
+ return getListType(getObjectType());
if (obj instanceof Collection)
- return getCollectionType(null);
+ return getCollectionType(getObjectType());
// datatypes
if (stringType.isInstance(obj))
return stringType;
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/IntegerTypeImpl.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/IntegerTypeImpl.java
index 2e2d8f5..538b590 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/IntegerTypeImpl.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/IntegerTypeImpl.java
@@ -34,12 +34,12 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
}
public boolean isInstance(final Object o) {
- return o instanceof Integer || o instanceof BigInteger || o instanceof Byte || o instanceof Long
+ return o instanceof BigInteger || o instanceof Integer || o instanceof Byte || o instanceof Long
|| o instanceof Short;
}
public Object newInstance() {
- return new Long(-1);
+ return new BigInteger("-1");
}
@Override
@@ -50,7 +50,7 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
public Object evaluateInternal(final Object target, final Object[] params) {
if (params[0] == null)
return null;
- return new Long(((Number) target).longValue() + ((Number) params[0]).longValue());
+ return toInt(target).add(toInt(params[0]));
}
},
new OperationImpl(this, "-", IntegerTypeImpl.this, new Type[] { IntegerTypeImpl.this }) {
@@ -58,13 +58,13 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
public Object evaluateInternal(final Object target, final Object[] params) {
if (params[0] == null)
return null;
- return new Long(((Number) target).longValue() - ((Number) params[0]).longValue());
+ return toInt(target).subtract(toInt(params[0]));
}
},
new OperationImpl(this, "-", IntegerTypeImpl.this, new Type[] {}) {
@Override
public Object evaluateInternal(final Object target, final Object[] params) {
- return new Long(((Number) target).longValue() * -1l);
+ return toInt(target).negate();
}
},
new OperationImpl(this, "*", IntegerTypeImpl.this, new Type[] { IntegerTypeImpl.this }) {
@@ -73,7 +73,7 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
if (params[0] == null)
return null;
- return new Long(((Number) target).longValue() * ((Number) params[0]).longValue());
+ return toInt(target).multiply(toInt(params[0]));
}
},
new OperationImpl(this, "/", IntegerTypeImpl.this, new Type[] { IntegerTypeImpl.this }) {
@@ -82,48 +82,38 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
if (params[0] == null)
return null;
- return new Long(((Number) target).longValue() / ((Number) params[0]).longValue());
+ return toInt(target).divide(toInt(params[0]));
}
},
- new OperationImpl(this, "==", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getObjectType() }) {
+ new OperationImpl(this, "==", getTypeSystem().getBooleanType(), new Type[] { IntegerTypeImpl.this }) {
@Override
public Object evaluateInternal(final Object target, final Object[] params) {
if (target == null)
return new Boolean(target == params[0]);
-
try {
- return toLong(target).equals(toLong(params[0]));
+ return toInt(target).equals(toInt(params[0]));
}
catch (Exception exc) {
- if (target instanceof Number && params[0] instanceof Number)
- return ((Number) target).doubleValue() == ((Number) params[0]).doubleValue();
-
return false;
}
}
},
- new OperationImpl(this, "!=", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getObjectType() }) {
+ new OperationImpl(this, "!=", getTypeSystem().getBooleanType(), new Type[] { IntegerTypeImpl.this }) {
@Override
public Object evaluateInternal(final Object target, final Object[] params) {
if (target == null)
return params[0] != null;
try {
- return ! toLong(target).equals(toLong(params[0]));
+ return ! toInt(target).equals(toInt(params[0]));
}
catch (Exception exc) {
- if (target instanceof Number && params[0] instanceof Number)
- return ((Number) target).doubleValue() != ((Number) params[0]).doubleValue();
-
return true;
}
}
},
- new OperationImpl(this, ">", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getObjectType() }) {
+ new OperationImpl(this, ">", getTypeSystem().getBooleanType(), new Type[] { IntegerTypeImpl.this }) {
@Override
public Object evaluateInternal(final Object target, final Object[] params) {
if (target == null)
@@ -132,15 +122,14 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
return Boolean.FALSE;
try {
- return ((Comparable<Long>) toLong(target)).compareTo(toLong(params[0])) > 0;
+ return toInt(target).compareTo(toInt(params[0])) > 0;
}
catch (Exception exc) {
- return ((Number) target).doubleValue() > ((Number) params[0]).doubleValue();
+ return Boolean.FALSE;
}
}
},
- new OperationImpl(this, ">=", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getObjectType() }) {
+ new OperationImpl(this, ">=", getTypeSystem().getBooleanType(), new Type[] { IntegerTypeImpl.this }) {
@Override
public Object evaluateInternal(final Object target, final Object[] params) {
if (target == null)
@@ -149,15 +138,14 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
return Boolean.FALSE;
try {
- return ((Comparable<Long>) toLong(target)).compareTo(toLong(params[0])) >= 0;
+ return toInt(target).compareTo(toInt(params[0])) >= 0;
}
catch (Exception exc) {
- return ((Number) target).doubleValue() >= ((Number) params[0]).doubleValue();
+ return Boolean.FALSE;
}
}
},
- new OperationImpl(this, "<", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getObjectType() }) {
+ new OperationImpl(this, "<", getTypeSystem().getBooleanType(), new Type[] { IntegerTypeImpl.this }) {
@Override
public Object evaluateInternal(final Object target, final Object[] params) {
if (target == null)
@@ -166,15 +154,14 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
return Boolean.FALSE;
try {
- return ((Comparable<Long>) toLong(target)).compareTo(toLong(params[0])) < 0;
+ return toInt(target).compareTo(toInt(params[0])) < 0;
}
catch (Exception exc) {
- return ((Number) target).doubleValue() < ((Number) params[0]).doubleValue();
+ return Boolean.FALSE;
}
}
},
- new OperationImpl(this, "<=", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getObjectType() }) {
+ new OperationImpl(this, "<=", getTypeSystem().getBooleanType(), new Type[] { IntegerTypeImpl.this }) {
@Override
public Object evaluateInternal(final Object target, final Object[] params) {
if (target == null)
@@ -183,30 +170,30 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
return Boolean.FALSE;
try {
- return ((Comparable<Long>) toLong(target)).compareTo(toLong(params[0])) <= 0;
+ return toInt(target).compareTo(toInt(params[0])) <= 0;
}
catch (Exception exc) {
- return ((Number) target).doubleValue() <= ((Number) params[0]).doubleValue();
+ return Boolean.FALSE;
}
}
}, new OperationImpl(this, "upTo", getTypeSystem().getListType(this), new Type[] { this }) {
@Override
public String getDocumentation() {
- return "returns a List of Integers starting with the value of the target expression, up to"
+ return "returns a List of Integers starting with the value of the target expression, up to "
+ "the value of the specified Integer, incremented by one.<br/>"
+ "e.g. '1.upTo(5)' evaluates to {1,2,3,4,5}";
}
@Override
public Object evaluateInternal(final Object target, final Object[] params) {
- final List<Long> result = new ArrayList<Long>();
- long l1 = toLong(target).longValue();
- final long l2 = toLong(params[0]).longValue();
+ final List<BigInteger> result = new ArrayList<BigInteger>();
+ BigInteger l1 = toInt(target);
+ final BigInteger l2 = toInt(params[0]);
- while (l1 <= l2) {
- result.add(new Long(l1));
- l1++;
+ while (l1.compareTo(l2) <= 0) {
+ result.add(l1);
+ l1 = l1.add(BigInteger.ONE);
}
return result;
}
@@ -214,21 +201,21 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
@Override
public String getDocumentation() {
- return "returns a List of Integers starting with the value of the target expression, up to"
+ return "returns a List of Integers starting with the value of the target expression, up to "
+ "the value of the first paramter, incremented by the second parameter.<br/>"
+ "e.g. '1.upTo(10, 2)' evaluates to {1,3,5,7,9}";
}
@Override
public Object evaluateInternal(final Object target, final Object[] params) {
- final List<Long> result = new ArrayList<Long>();
- long l1 = toLong(target).longValue();
- final long l2 = toLong(params[0]).longValue();
- final long l3 = toLong(params[1]).longValue();
+ final List<BigInteger> result = new ArrayList<BigInteger>();
+ BigInteger l1 = toInt(target);
+ final BigInteger l2 = toInt(params[0]);
+ final BigInteger l3 = toInt(params[1]);
- while (l1 <= l2) {
- result.add(new Long(l1));
- l1 = l1 + l3;
+ while (l1.compareTo(l2) <= 0) {
+ result.add(l1);
+ l1 = l1.add(l3);
}
return result;
}
@@ -240,36 +227,39 @@ public final class IntegerTypeImpl extends BuiltinBaseType implements Type {
return Collections.singleton(getTypeSystem().getRealType());
}
- Long toLong(final Object o) {
- if (o == null)
+ protected BigInteger toInt(final Object o) {
+ if(o == null)
return null;
+ if (o instanceof BigInteger)
+ return (BigInteger) o;
+
if (o instanceof Integer)
- return new Long(((Integer) o).longValue());
- else if (o instanceof BigInteger)
- return new Long(((BigInteger) o).longValue());
+ return BigInteger.valueOf(((Integer)o).longValue());
else if (o instanceof Byte)
- return new Long(((Byte) o).longValue());
+ return BigInteger.valueOf(((Byte)o).longValue());
else if (o instanceof Long)
- return (Long) o;
+ return BigInteger.valueOf((Long)o);
else if (o instanceof Short)
- return new Long(((Short) o).longValue());
+ return BigInteger.valueOf(((Short) o).longValue());
+
throw new IllegalArgumentException(o.getClass().getName() + " not supported");
}
@Override
public Object convert(final Object src, final Class<?> targetType) {
- final Long l = toLong(src);
- if (targetType.isAssignableFrom(Integer.class) || targetType.isAssignableFrom(Integer.TYPE))
- return new Integer(l.intValue());
- else if (targetType.isAssignableFrom(BigInteger.class))
- return BigInteger.valueOf(l.longValue());
- else if (targetType.isAssignableFrom(Byte.class) || targetType.isAssignableFrom(Byte.TYPE))
- return new Byte(l.byteValue());
+ final BigInteger value = toInt(src);
+
+ if (targetType.isAssignableFrom(BigInteger.class))
+ return value;
else if (targetType.isAssignableFrom(Long.class) || targetType.isAssignableFrom(Long.TYPE))
- return src;
+ return value.longValue();
+ else if (targetType.isAssignableFrom(Integer.class) || targetType.isAssignableFrom(Integer.TYPE))
+ return value.intValue();
+ else if (targetType.isAssignableFrom(Byte.class) || targetType.isAssignableFrom(Byte.TYPE))
+ return value.byteValue();
else if (targetType.isAssignableFrom(Short.class) || targetType.isAssignableFrom(Short.TYPE))
- return new Short(l.shortValue());
+ return value.shortValue();
return super.convert(src, targetType);
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/StringTypeImpl.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/StringTypeImpl.java
index 1f6e9f0..4619161 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/StringTypeImpl.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/type/baseimpl/types/StringTypeImpl.java
@@ -33,300 +33,302 @@ import org.eclipse.xtend.typesystem.Type;
*/
@SuppressWarnings("unchecked")
public class StringTypeImpl extends BuiltinBaseType implements Type {
- final Log log = LogFactory.getLog(getClass());
-
- public StringTypeImpl(final TypeSystem ts, final String name) {
- super(ts, name);
- }
-
- public boolean isInstance(final Object o) {
- return o instanceof String || o instanceof StringBuffer || o instanceof Character;
- }
-
- public Object newInstance() {
- return "";
- }
-
- @Override
- public Feature[] getContributedFeatures() {
- return new Feature[] {
- new PropertyImpl(this, "length", getTypeSystem().getIntegerType()) {
-
- @Override
- public String getDocumentation() {
- return "the length of this string";
- }
-
- public Object get(final Object target) {
- return new Long(target.toString().length());
- }
- },
-
- new OperationImpl(this, "+", getTypeSystem().getStringType(), new Type[] { getTypeSystem()
- .getObjectType() }) {
-
- @Override
- public String getDocumentation() {
- return "concatenates two strings";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return target.toString() + params[0];
- }
- },
-
- new OperationImpl(this, "startsWith", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getStringType() }) {
-
- @Override
- public String getDocumentation() {
- return "Tests if this string starts with the specified prefix.";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- final String token = (String) params[0];
- return new Boolean(target.toString().startsWith(token));
- }
- },
- new OperationImpl(this, "contains", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getStringType() }) {
-
- @Override
- public String getDocumentation() {
- return "Tests if this string contains substring.";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- final String token = (String) params[0];
- return new Boolean(target.toString().indexOf(token) >= 0);
- }
- },
- new OperationImpl(this, "endsWith", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getStringType() }) {
-
- @Override
- public String getDocumentation() {
- return "Tests if this string ends with the specified prefix.";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- final String token = (String) params[0];
- return new Boolean(target.toString().endsWith(token));
- }
- },
- new OperationImpl(this, "subString", getTypeSystem().getStringType(), new Type[] { getTypeSystem()
- .getIntegerType(),getTypeSystem().getIntegerType() }) {
-
- @Override
- public String getDocumentation() {
- return "Tests if this string ends with the specified prefix.";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- final Number from = (Number) params[0];
- final Number to = (Number) params[1];
- return target.toString().substring(from.intValue(),to.intValue());
- }
- },
-
- new OperationImpl(this, "toUpperCase", getTypeSystem().getStringType(), new Type[] {}) {
-
- @Override
- public String getDocumentation() {
- return "Converts all of the characters in this String to upper"
- + " case using the rules of the default locale (from Java)";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return target.toString().toUpperCase();
- }
- },
-
- new OperationImpl(this, "toLowerCase", getTypeSystem().getStringType(), new Type[] {}) {
- @Override
- public String getDocumentation() {
- return "Converts all of the characters in this String to lower"
- + " case using the rules of the default locale (from Java)";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return target.toString().toLowerCase();
- }
- },
-
- new OperationImpl(this, "toFirstUpper", getTypeSystem().getStringType(), new Type[] {}) {
- @Override
- public String getDocumentation() {
- return "Converts the first character in this String to upper"
- + " case using the rules of the default locale (from Java)";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return StringHelper.firstUpper(target.toString());
- }
- },
-
- new OperationImpl(this, "toFirstLower", getTypeSystem().getStringType(), new Type[] {}) {
- @Override
- public String getDocumentation() {
- return "Converts the first character in this String to lower"
- + " case using the rules of the default locale (from Java)";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return StringHelper.firstLower(target.toString());
- }
- },
-
- new OperationImpl(this, "toCharList", getTypeSystem().getListType(getTypeSystem().getStringType()),
- new Type[] {}) {
-
- @Override
- public String getDocumentation() {
- return "splits this String into a List[String] containing Strings of length 1";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- final String txt = target.toString();
- final List<String> result = new ArrayList<String>();
- final char[] chars = txt.toCharArray();
- for (int i = 0; i < chars.length; i++) {
- result.add(String.valueOf(chars[i]));
- }
- return result;
- }
- },
-
- new OperationImpl(this, "replaceAll", getTypeSystem().getStringType(), new Type[] {
- getTypeSystem().getStringType(), getTypeSystem().getStringType() }) {
-
- @Override
- public String getDocumentation() {
- return "Replaces each substring of this string that matches the given "
- + "regular expression with the given replacement.";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return target.toString().replaceAll(params[0].toString(), params[1].toString());
- }
- },
-
- new OperationImpl(this, "replaceFirst", getTypeSystem().getStringType(), new Type[] {
- getTypeSystem().getStringType(), getTypeSystem().getStringType() }) {
-
- @Override
- public String getDocumentation() {
- return "Replaces the first substring of this string that matches the given"
- + " regular expression with the given replacement.";
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return target.toString().replaceFirst(params[0].toString(), params[1].toString());
- }
- },
-
- new OperationImpl(this, "split", getTypeSystem().getListType(getTypeSystem().getStringType()),
- new Type[] { getTypeSystem().getStringType() }) {
-
- @Override
- public String getDocumentation() {
- return "Splits this string around matches of the given regular expression (from Java 1.4)";
-
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return new ArrayList<String>(Arrays.asList(target.toString().split(params[0].toString())));
- }
- },
-
- new OperationImpl(this, "matches", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
- .getStringType() }) {
-
- @Override
- public String getDocumentation() {
- return "Tells whether or not this string matches the given regular expression. (from Java 1.4)";
-
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return Boolean.valueOf(((String) target).matches((String) params[0]));
- }
- },
-
- new OperationImpl(this, "trim", getTypeSystem().getStringType(), new Type[] {}) {
-
- @Override
- public String getDocumentation() {
- return "Returns a copy of the string, with leading and trailing whitespace omitted. (from Java 1.4)";
-
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- return ((String) target).trim();
- }
- },
-
- new OperationImpl(this, "asInteger", getTypeSystem().getIntegerType(), new Type[] {}) {
-
- @Override
- public String getDocumentation() {
- return "Returns an Integer object holding the value of the specified String (from Java 1.5)";
-
- }
-
- @Override
- public Object evaluateInternal(final Object target, final Object[] params) {
- try {
- return Integer.valueOf((String) target);
- } catch (NumberFormatException nfe) {
- log.error("'asInteger' on '"+target+"' returned null!");
- return null;
- }
- }
- }
-
- };
- }
-
- @Override
- public Set<Type> getSuperTypes() {
- return Collections.singleton(getTypeSystem().getObjectType());
- }
-
- private String toString(final Object o) {
- if (o == null)
- return null;
- if (isInstance(o))
- return o.toString();
- throw new IllegalArgumentException(o.getClass().getName() + " not supported");
- }
-
- @Override
- public Object convert(final Object src, final Class targetType) {
- final String s = toString(src);
- if (targetType.isAssignableFrom(String.class))
- return s;
- else if (targetType.isAssignableFrom(Character.class) || targetType.isAssignableFrom(Character.TYPE)) {
- if (s.length() == 1)
- return new Character(s.charAt(0));
- } else if (targetType.isAssignableFrom(StringBuffer.class))
- return new StringBuffer(s);
- return super.convert(src, targetType);
- }
+ final Log log = LogFactory.getLog(getClass());
+
+ public StringTypeImpl(final TypeSystem ts, final String name) {
+ super(ts, name);
+ }
+
+ public boolean isInstance(final Object o) {
+ return o instanceof String || o instanceof StringBuffer || o instanceof Character;
+ }
+
+ public Object newInstance() {
+ return "";
+ }
+
+ @Override
+ public Feature[] getContributedFeatures() {
+ return new Feature[] {
+ new PropertyImpl(this, "length", getTypeSystem().getIntegerType()) {
+
+ @Override
+ public String getDocumentation() {
+ return "the length of this string";
+ }
+
+ public Object get(final Object target) {
+ return new Long(target.toString().length());
+ }
+ },
+
+ new OperationImpl(this, "+", getTypeSystem().getStringType(), new Type[] { getTypeSystem()
+ .getObjectType() }) {
+
+ @Override
+ public String getDocumentation() {
+ return "concatenates two strings";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return target.toString() + params[0];
+ }
+ },
+
+ new OperationImpl(this, "startsWith", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
+ .getStringType() }) {
+
+ @Override
+ public String getDocumentation() {
+ return "Tests if this string starts with the specified prefix.";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ final String token = (String) params[0];
+ return new Boolean(target.toString().startsWith(token));
+ }
+ },
+ new OperationImpl(this, "contains", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
+ .getStringType() }) {
+
+ @Override
+ public String getDocumentation() {
+ return "Tests if this string contains substring.";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ final String token = (String) params[0];
+ return new Boolean(target.toString().indexOf(token) >= 0);
+ }
+ },
+ new OperationImpl(this, "endsWith", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
+ .getStringType() }) {
+
+ @Override
+ public String getDocumentation() {
+ return "Tests if this string ends with the specified prefix.";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ final String token = (String) params[0];
+ return new Boolean(target.toString().endsWith(token));
+ }
+ },
+ new OperationImpl(this, "subString", getTypeSystem().getStringType(), new Type[] {
+ getTypeSystem().getIntegerType(), getTypeSystem().getIntegerType() }) {
+
+ @Override
+ public String getDocumentation() {
+ return "Returns a new string that is a substring of this string.";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ final Number from = (Number) params[0];
+ final Number to = (Number) params[1];
+ return target.toString().substring(from.intValue(), to.intValue());
+ }
+ },
+
+ new OperationImpl(this, "toUpperCase", getTypeSystem().getStringType(), new Type[] {}) {
+
+ @Override
+ public String getDocumentation() {
+ return "Converts all of the characters in this String to upper"
+ + " case using the rules of the default locale (from Java)";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return target.toString().toUpperCase();
+ }
+ },
+
+ new OperationImpl(this, "toLowerCase", getTypeSystem().getStringType(), new Type[] {}) {
+ @Override
+ public String getDocumentation() {
+ return "Converts all of the characters in this String to lower"
+ + " case using the rules of the default locale (from Java)";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return target.toString().toLowerCase();
+ }
+ },
+
+ new OperationImpl(this, "toFirstUpper", getTypeSystem().getStringType(), new Type[] {}) {
+ @Override
+ public String getDocumentation() {
+ return "Converts the first character in this String to upper"
+ + " case using the rules of the default locale (from Java)";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return StringHelper.firstUpper(target.toString());
+ }
+ },
+
+ new OperationImpl(this, "toFirstLower", getTypeSystem().getStringType(), new Type[] {}) {
+ @Override
+ public String getDocumentation() {
+ return "Converts the first character in this String to lower"
+ + " case using the rules of the default locale (from Java)";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return StringHelper.firstLower(target.toString());
+ }
+ },
+
+ new OperationImpl(this, "toCharList", getTypeSystem().getListType(getTypeSystem().getStringType()),
+ new Type[] {}) {
+
+ @Override
+ public String getDocumentation() {
+ return "splits this String into a List[String] containing Strings of length 1";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ final String txt = target.toString();
+ final List<String> result = new ArrayList<String>();
+ final char[] chars = txt.toCharArray();
+ for (int i = 0; i < chars.length; i++) {
+ result.add(String.valueOf(chars[i]));
+ }
+ return result;
+ }
+ },
+
+ new OperationImpl(this, "replaceAll", getTypeSystem().getStringType(), new Type[] {
+ getTypeSystem().getStringType(), getTypeSystem().getStringType() }) {
+
+ @Override
+ public String getDocumentation() {
+ return "Replaces each substring of this string that matches the given "
+ + "regular expression with the given replacement.";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return target.toString().replaceAll(params[0].toString(), params[1].toString());
+ }
+ },
+
+ new OperationImpl(this, "replaceFirst", getTypeSystem().getStringType(), new Type[] {
+ getTypeSystem().getStringType(), getTypeSystem().getStringType() }) {
+
+ @Override
+ public String getDocumentation() {
+ return "Replaces the first substring of this string that matches the given"
+ + " regular expression with the given replacement.";
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return target.toString().replaceFirst(params[0].toString(), params[1].toString());
+ }
+ },
+
+ new OperationImpl(this, "split", getTypeSystem().getListType(getTypeSystem().getStringType()),
+ new Type[] { getTypeSystem().getStringType() }) {
+
+ @Override
+ public String getDocumentation() {
+ return "Splits this string around matches of the given regular expression (from Java 1.4)";
+
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return new ArrayList<String>(Arrays.asList(target.toString().split(params[0].toString())));
+ }
+ },
+
+ new OperationImpl(this, "matches", getTypeSystem().getBooleanType(), new Type[] { getTypeSystem()
+ .getStringType() }) {
+
+ @Override
+ public String getDocumentation() {
+ return "Tells whether or not this string matches the given regular expression. (from Java 1.4)";
+
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return Boolean.valueOf(((String) target).matches((String) params[0]));
+ }
+ },
+
+ new OperationImpl(this, "trim", getTypeSystem().getStringType(), new Type[] {}) {
+
+ @Override
+ public String getDocumentation() {
+ return "Returns a copy of the string, with leading and trailing whitespace omitted. (from Java 1.4)";
+
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ return ((String) target).trim();
+ }
+ },
+
+ new OperationImpl(this, "asInteger", getTypeSystem().getIntegerType(), new Type[] {}) {
+
+ @Override
+ public String getDocumentation() {
+ return "Returns an Integer object holding the value of the specified String (from Java 1.5)";
+
+ }
+
+ @Override
+ public Object evaluateInternal(final Object target, final Object[] params) {
+ try {
+ return new BigInteger((String) target);
+ }
+ catch (NumberFormatException nfe) {
+ log.error("'asInteger' on '" + target + "' returned null!");
+ return null;
+ }
+ }
+ }
+
+ };
+ }
+
+ @Override
+ public Set<Type> getSuperTypes() {
+ return Collections.singleton(getTypeSystem().getObjectType());
+ }
+
+ private String toString(final Object o) {
+ if (o == null)
+ return null;
+ if (isInstance(o))
+ return o.toString();
+ throw new IllegalArgumentException(o.getClass().getName() + " not supported");
+ }
+
+ @Override
+ public Object convert(final Object src, final Class targetType) {
+ final String s = toString(src);
+ if (targetType.isAssignableFrom(String.class))
+ return s;
+ else if (targetType.isAssignableFrom(Character.class) || targetType.isAssignableFrom(Character.TYPE)) {
+ if (s.length() == 1)
+ return new Character(s.charAt(0));
+ }
+ else if (targetType.isAssignableFrom(StringBuffer.class))
+ return new StringBuffer(s);
+ return super.convert(src, targetType);
+ }
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/AbstractExtension.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/AbstractExtension.java
index 92e2eb1..0d1fc3a 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/AbstractExtension.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/AbstractExtension.java
@@ -31,24 +31,24 @@ import org.eclipse.xtend.typesystem.Type;
public abstract class AbstractExtension extends SyntaxElement implements Extension {
- private Identifier name;
+ private Identifier name;
- private List<DeclaredParameter> formalParameters;
+ private List<DeclaredParameter> formalParameters;
- protected ExtensionFile file;
+ protected ExtensionFile file;
- protected boolean cached = false;
+ protected boolean cached = false;
- private boolean isPrivate = false;
+ private boolean isPrivate = false;
public AbstractExtension(final Identifier name, final Identifier returnType,
final List<DeclaredParameter> formalParameters, final boolean cached, final boolean isPrivate) {
- this.name = name;
- this.formalParameters = formalParameters;
- this.returnType = returnType;
- this.cached = cached;
- this.isPrivate = isPrivate;
- }
+ this.name = name;
+ this.formalParameters = formalParameters;
+ this.returnType = returnType;
+ this.cached = cached;
+ this.isPrivate = isPrivate;
+ }
/*
* (non-Javadoc)
@@ -56,19 +56,19 @@ public abstract class AbstractExtension extends SyntaxElement implements Extensi
* @see org.eclipse.xtend.ast.Extension#getFormalParameters()
*/
public List<DeclaredParameter> getFormalParameters() {
- return formalParameters;
- }
+ return formalParameters;
+ }
/*
* (non-Javadoc)
*
* @see org.eclipse.xtend.ast.Extension#getName()
*/
- public String getName() {
- return name.getValue();
- }
-
- public Identifier getNameIdentifier() {
+ public String getName() {
+ return name.getValue();
+ }
+
+ public Identifier getNameIdentifier() {
return name;
}
@@ -79,54 +79,53 @@ public abstract class AbstractExtension extends SyntaxElement implements Extensi
* openarchitectureware.type.Type[],
* org.eclipse.expression.ExecutionContext, java.util.Set)
*/
- public final Type getReturnType(final Type[] parameters, ExecutionContext ctx, final Set<AnalysationIssue> issues) {
- ctx = ctx.cloneWithResource(getExtensionFile());
- return internalGetReturnType(parameters, ctx, issues);
- }
+ public final Type getReturnType(final Type[] parameters, ExecutionContext ctx, final Set<AnalysationIssue> issues) {
+ ctx = ctx.cloneWithResource(getExtensionFile());
+ return internalGetReturnType(parameters, ctx, issues);
+ }
- protected abstract Type internalGetReturnType(Type[] parameters, ExecutionContext ctx, Set<AnalysationIssue> issues);
+ protected abstract Type internalGetReturnType(Type[] parameters, ExecutionContext ctx, Set<AnalysationIssue> issues);
/*
* (non-Javadoc)
*
- * @see
- * org.eclipse.xtend.ast.Extension#analyze(org.eclipse
+ * @see org.eclipse.xtend.ast.Extension#analyze(org.eclipse
* .expression.ExecutionContext, java.util.Set)
*/
- public final void analyze(ExecutionContext ctx, final Set<AnalysationIssue> issues) {
+ public final void analyze(ExecutionContext ctx, final Set<AnalysationIssue> issues) {
try {
if (ctx.getCallback() != null) {
ctx.getCallback().pre(this, ctx);
}
- final List<DeclaredParameter> params = getFormalParameters();
- final Set<String> usedNames = new HashSet<String>();
- for (final Iterator<DeclaredParameter> iter = params.iterator(); iter.hasNext();) {
- final DeclaredParameter p = iter.next();
- final Type pt = ctx.getTypeForName(p.getType().getValue());
- if (pt == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Type not found: "
- + p.getType().getValue(), p.getType()));
- }
- if (!usedNames.add(p.getName().getValue())) {
- issues.add(new AnalysationIssue(AnalysationIssue.SYNTAX_ERROR, "Duplicate parameter name: "
- + p.getName().getValue(), p.getName()));
- }
- ctx = ctx.cloneWithVariable(new Variable(p.getName().getValue(), pt));
- }
- if (returnType != null) {
- final Type pt = ctx.getTypeForName(returnType.getValue());
- if (pt == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Type not found: "
- + returnType.getValue(), returnType));
- }
- }
- try {
- analyzeInternal(ctx, issues);
+ final List<DeclaredParameter> params = getFormalParameters();
+ final Set<String> usedNames = new HashSet<String>();
+ for (final Iterator<DeclaredParameter> iter = params.iterator(); iter.hasNext();) {
+ final DeclaredParameter p = iter.next();
+ final Type pt = ctx.getTypeForName(p.getType().getValue());
+ if (pt == null) {
+ issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Type not found: "
+ + p.getType().getValue(), p.getType()));
+ }
+ if (!usedNames.add(p.getName().getValue())) {
+ issues.add(new AnalysationIssue(AnalysationIssue.SYNTAX_ERROR, "Duplicate parameter name: "
+ + p.getName().getValue(), p.getName()));
+ }
+ ctx = ctx.cloneWithVariable(new Variable(p.getName().getValue(), pt));
+ }
+ if (returnType != null) {
+ final Type pt = ctx.getTypeForName(returnType.getValue());
+ if (pt == null) {
+ issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Type not found: "
+ + returnType.getValue(), returnType));
+ }
+ }
+ try {
+ analyzeInternal(ctx, issues);
}
catch (RuntimeException ex) {
- ctx.handleRuntimeException(ex, this, null);
- }
- }
+ ctx.handleRuntimeException(ex, this, null);
+ }
+ }
finally {
if (ctx.getCallback() != null) {
ctx.getCallback().post(null);
@@ -138,196 +137,193 @@ public abstract class AbstractExtension extends SyntaxElement implements Extensi
checkForAmbiguousDefinitions(ctx, issues);
}
- private final Map<List<Object>, Object> cache = new HashMap<List<Object>, Object>();
+ private final Map<List<Object>, Object> cache = new HashMap<List<Object>, Object>();
/*
* (non-Javadoc)
*
- * @see
- * org.eclipse.xtend.ast.Extension#evaluate(java.lang.Object[],
+ * @see org.eclipse.xtend.ast.Extension#evaluate(java.lang.Object[],
* org.eclipse.expression.ExecutionContext)
*/
- public Object evaluate(final Object[] parameters, ExecutionContext ctx) {
- try {
+ public Object evaluate(final Object[] parameters, ExecutionContext ctx) {
+ try {
if (ctx.getCallback() != null) {
ctx.getCallback().pre(this, ctx);
}
- if (cached) {
- final List<Object> l = Arrays.asList(parameters);
- if (cache.containsKey(l))
- return cache.get(l);
- }
- if (getExtensionFile() == null)
- throw new IllegalStateException("No containing file!");
- ctx = ctx.cloneWithResource(getExtensionFile());
- final Object result = evaluateInternal(parameters, ctx);
- if (cached) {
- cache.put(Arrays.asList(parameters), result);
- }
- return result;
+ if (cached) {
+ final List<Object> l = Arrays.asList(parameters);
+ if (cache.containsKey(l))
+ return cache.get(l);
+ }
+ if (getExtensionFile() == null)
+ throw new IllegalStateException("No containing file!");
+ ctx = ctx.cloneWithResource(getExtensionFile());
+ final Object result = evaluateInternal(parameters, ctx);
+ if (cached) {
+ cache.put(Arrays.asList(parameters), result);
+ }
+ return result;
}
catch (RuntimeException ex) {
- ctx.handleRuntimeException(ex, this, null);
- }
+ ctx.handleRuntimeException(ex, this, null);
+ }
finally {
if (ctx.getCallback() != null) {
ctx.getCallback().post(null);
}
}
- return null;
- }
+ return null;
+ }
- public final void setExtensionFile(final ExtensionFile f) {
- file = f;
- }
+ public final void setExtensionFile(final ExtensionFile f) {
+ file = f;
+ }
/*
* (non-Javadoc)
*
* @see org.eclipse.xtend.ast.Extension#getExtensionFile()
*/
- public ExtensionFile getExtensionFile() {
- return file;
- }
+ public ExtensionFile getExtensionFile() {
+ return file;
+ }
- protected abstract Object evaluateInternal(Object[] parameters, ExecutionContext ctx);
+ protected abstract Object evaluateInternal(Object[] parameters, ExecutionContext ctx);
/*
* (non-Javadoc)
*
* @see org.eclipse.xtend.ast.Extension#getParameterNames()
*/
- public List<String> getParameterNames() {
- final List<String> names = new ArrayList<String>();
- for (final Iterator<DeclaredParameter> iter = getFormalParameters().iterator(); iter.hasNext();) {
- names.add(iter.next().getName().getValue());
- }
- return names;
- }
+ public List<String> getParameterNames() {
+ final List<String> names = new ArrayList<String>();
+ for (final Iterator<DeclaredParameter> iter = getFormalParameters().iterator(); iter.hasNext();) {
+ names.add(iter.next().getName().getValue());
+ }
+ return names;
+ }
/*
* (non-Javadoc)
*
- * @see
- * org.eclipse.xtend.ast.Extension#init(org.eclipse
+ * @see org.eclipse.xtend.ast.Extension#init(org.eclipse
* .expression.ExecutionContext)
*/
- public void init(final ExecutionContext ctx) {
- if (parameterTypes == null) {
- try {
- parameterTypes = new ArrayList<Type>();
- for (final Iterator<DeclaredParameter> iter = getFormalParameters().iterator(); iter.hasNext();) {
- final String name = iter.next().getType().getValue();
- final Type t = ctx.getTypeForName(name);
- if (t == null)
- throw new EvaluationException("Couldn't resolve type for '" + name
- + "'. Did you forget to configure the corresponding metamodel?", this, ctx);
- parameterTypes.add(t);
- }
+ public void init(final ExecutionContext ctx) {
+ if (parameterTypes == null) {
+ try {
+ parameterTypes = new ArrayList<Type>();
+ for (final Iterator<DeclaredParameter> iter = getFormalParameters().iterator(); iter.hasNext();) {
+ final String name = iter.next().getType().getValue();
+ final Type t = ctx.getTypeForName(name);
+ if (t == null)
+ throw new EvaluationException("Couldn't resolve type for '" + name
+ + "'. Did you forget to configure the corresponding metamodel?", this, ctx);
+ parameterTypes.add(t);
+ }
}
catch (final RuntimeException e) {
- parameterTypes = null;
- throw e;
- }
- }
- }
+ parameterTypes = null;
+ throw e;
+ }
+ }
+ }
/*
* (non-Javadoc)
*
* @see org.eclipse.xtend.ast.Extension#getReturnType()
*/
- public Type getReturnType() {
- throw new UnsupportedOperationException();
- }
+ public Type getReturnType() {
+ throw new UnsupportedOperationException();
+ }
- private List<Type> parameterTypes = null;
+ private List<Type> parameterTypes = null;
- protected Identifier returnType;
+ protected Identifier returnType;
/*
* (non-Javadoc)
*
* @see org.eclipse.xtend.ast.Extension#getParameterTypes()
*/
- public List<Type> getParameterTypes() {
- return parameterTypes;
- }
+ public List<Type> getParameterTypes() {
+ return parameterTypes;
+ }
/*
* (non-Javadoc)
*
- * @see
- * org.eclipse.xtend.ast.Extension#getReturnTypeIdentifier()
+ * @see org.eclipse.xtend.ast.Extension#getReturnTypeIdentifier()
*/
- public Identifier getReturnTypeIdentifier() {
- return returnType;
- }
+ public Identifier getReturnTypeIdentifier() {
+ return returnType;
+ }
- private String _stringRepresentation = null;
+ private String _stringRepresentation = null;
/*
* (non-Javadoc)
*
* @see org.eclipse.xtend.ast.Extension#toString()
*/
- @Override
- public String toString() {
- if (_stringRepresentation == null) {
+ @Override
+ public String toString() {
+ if (_stringRepresentation == null) {
_stringRepresentation = (returnType != null ? returnType.getValue() + " " : "") + getName() + "("
+ paramsToString() + ")";
- }
+ }
+
+ return _stringRepresentation;
+ }
+
+ private String _outlineRepresentation = null;
- return _stringRepresentation;
- }
-
- private String _outlineRepresentation = null;
-
/*
* (non-Javadoc)
*
* @see org.eclipse.xtend.ast.Extension#toOutlineString()
*/
- public String toOutlineString() {
- if (_outlineRepresentation == null) {
+ public String toOutlineString() {
+ if (_outlineRepresentation == null) {
_outlineRepresentation = getName() + "(" + paramsToOutlineString() + ")"
+ (returnType != null ? ": " + returnType.getValue() : "");
- }
- return _outlineRepresentation;
- }
-
- private String paramsToString() {
- final StringBuffer buff = new StringBuffer();
- for (final Iterator<DeclaredParameter> iter = getFormalParameters().iterator(); iter.hasNext();) {
- final DeclaredParameter element = iter.next();
- buff.append(element.getType() + " " + element.getName());
- if (iter.hasNext()) {
- buff.append(",");
- }
- }
- return buff.toString();
- }
-
- private String paramsToOutlineString() {
- final StringBuffer buff = new StringBuffer();
- for (final Iterator<DeclaredParameter> iter = getFormalParameters().iterator(); iter.hasNext();) {
- final DeclaredParameter element = iter.next();
+ }
+ return _outlineRepresentation;
+ }
+
+ private String paramsToString() {
+ final StringBuffer buff = new StringBuffer();
+ for (final Iterator<DeclaredParameter> iter = getFormalParameters().iterator(); iter.hasNext();) {
+ final DeclaredParameter element = iter.next();
+ buff.append(element.getType() + " " + element.getName());
+ if (iter.hasNext()) {
+ buff.append(",");
+ }
+ }
+ return buff.toString();
+ }
+
+ private String paramsToOutlineString() {
+ final StringBuffer buff = new StringBuffer();
+ for (final Iterator<DeclaredParameter> iter = getFormalParameters().iterator(); iter.hasNext();) {
+ final DeclaredParameter element = iter.next();
buff.append(element.getType());
- if (iter.hasNext()) {
- buff.append(", ");
- }
- }
- return buff.toString();
- }
+ if (iter.hasNext()) {
+ buff.append(", ");
+ }
+ }
+ return buff.toString();
+ }
/*
* (non-Javadoc)
*
* @see org.eclipse.xtend.ast.Extension#isPrivate()
*/
- public boolean isPrivate() {
- return isPrivate;
- }
+ public boolean isPrivate() {
+ return isPrivate;
+ }
/*
* (non-Javadoc)
@@ -335,12 +331,12 @@ public abstract class AbstractExtension extends SyntaxElement implements Extensi
* @see org.eclipse.xtend.ast.Extension#isCached()
*/
public boolean isCached() {
- return cached;
- }
-
- public String getQualifiedName() {
+ return cached;
+ }
+
+ public String getQualifiedName() {
return getExtensionFile().getFullyQualifiedName() + "::" + getName();
- }
+ }
@Override
public int hashCode() {
@@ -374,7 +370,7 @@ public abstract class AbstractExtension extends SyntaxElement implements Extensi
return false;
return true;
}
-
+
protected void checkForAmbiguousDefinitions(final ExecutionContext ctx, final Set<AnalysationIssue> issues) {
String name = getName();
for (Extension ext : ctx.getAllExtensions()) {
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/Check.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/Check.java
index 534fd8d..60cd887 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/Check.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/Check.java
@@ -53,50 +53,66 @@ public class Check extends SyntaxElement {
public final void analyze(ExecutionContext ctx, final Set<AnalysationIssue> issues) {
try {
- if (ctx.getCallback() != null)
- ctx.getCallback().pre(this,ctx);
- final Type toCheck = ctx.getTypeForName(type.getValue());
- if (toCheck == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Type not found: " + type.getValue(), this));
+ if (ctx.getCallback() != null) {
+ ctx.getCallback().pre(this, ctx);
+ }
+ final Type toCheck = ctx.getTypeForName(type.getValue());
+ if (toCheck == null) {
+ issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Type not found: " + type.getValue(),
+ this));
return;
}
- ctx = ctx.cloneWithVariable(new Variable(ExecutionContext.IMPLICIT_VARIABLE, toCheck));
- if (guard != null) {
- Type guardType = null;
+ if (feature != null) {
+ Property property = toCheck.getProperty(feature.getValue());
+ if (property == null) {
+ issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, "Couldn't find property '"
+ + feature.getValue() + "' for type '" + type.getValue() + "'", this));
+ return;
+ }
+ }
+
+ ctx = ctx.cloneWithVariable(new Variable(ExecutionContext.IMPLICIT_VARIABLE, toCheck));
+ if (guard != null) {
+ Type guardType = null;
+ try {
+ guardType = guard.analyze(ctx, issues);
+ }
+ catch (RuntimeException ex) {
+ ctx.handleRuntimeException(ex, this, null);
+ }
+ if (guardType == null)
+ return;
+ if (!guardType.equals(ctx.getBooleanType())) {
+ issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Boolean expected! (is "
+ + guardType.getName() + ")", guard));
+ }
+ }
+
+ Type constraintType = null;
try {
- guardType = guard.analyze(ctx, issues);
- } catch (RuntimeException ex) {
+ constraintType = constraint.analyze(ctx, issues);
+ }
+ catch (RuntimeException ex) {
ctx.handleRuntimeException(ex, this, null);
}
- if (guardType == null)
+ if (constraintType == null)
return;
- if (!guardType.equals(ctx.getBooleanType())) {
+ if (!constraintType.equals(ctx.getBooleanType())) {
issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Boolean expected! (is "
- + guardType.getName() + ")", guard));
+ + constraintType.getName() + ")", constraint));
}
- }
-
- Type constraintType = null;
- try {
- constraintType = constraint.analyze(ctx, issues);
- } catch (RuntimeException ex) {
- ctx.handleRuntimeException(ex, this, null);
- }
- if (constraintType == null)
- return;
- if (!constraintType.equals(ctx.getBooleanType())) {
- issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Boolean expected! (is "
- + constraintType.getName() + ")", constraint));
- }
- try {
- msg.analyze(ctx, issues);
- } catch (RuntimeException ex) {
- ctx.handleRuntimeException(ex, this, null);
+ try {
+ msg.analyze(ctx, issues);
+ }
+ catch (RuntimeException ex) {
+ ctx.handleRuntimeException(ex, this, null);
+ }
}
- } finally {
- if (ctx.getCallback() != null)
+ finally {
+ if (ctx.getCallback() != null) {
ctx.getCallback().post(null);
+ }
}
}
@@ -113,87 +129,109 @@ public class Check extends SyntaxElement {
* <code>true</code>: If this check is not evaluated for any
* elements an warning will be added to <tt>issues</tt>
*/
- public void validate(ExecutionContext ctx, final Collection<?> colToCheck, final Issues issues, boolean warnIfNothingChecked) {
+ public void validate(ExecutionContext ctx, final Collection<?> colToCheck, final Issues issues,
+ boolean warnIfNothingChecked) {
try {
- if (ctx.getCallback() != null)
+ if (ctx.getCallback() != null) {
ctx.getCallback().pre(this, ctx);
- // get the type for which the check should be evaluated
- final Type typeToCheck = ctx.getTypeForName(type.getValue());
- // The type is unknown => exit with exception
- if (typeToCheck == null)
- throw new EvaluationException("Type not found : " + type.getValue(), this, ctx);
-
- // will be set to true when check is evaluated for any object
- boolean someObjectFound = false;
- for (final Iterator<?> iter = colToCheck.iterator(); iter.hasNext();) {
- final Object o = iter.next();
- // Object matches the type the check is declared for
- if (typeToCheck.isInstance(o)) {
- someObjectFound = true;
- try {
- // create a new execution context for evaluation
- ctx = ctx.cloneWithVariable(new Variable(ExecutionContext.IMPLICIT_VARIABLE, o));
+ }
+ // get the type for which the check should be evaluated
+ final Type typeToCheck = ctx.getTypeForName(type.getValue());
+ // The type is unknown => exit with exception
+ if (typeToCheck == null)
+ throw new EvaluationException("Type not found : " + type.getValue(), this, ctx);
+
+ // will be set to true when check is evaluated for any object
+ boolean someObjectFound = false;
+ for (final Iterator<?> iter = colToCheck.iterator(); iter.hasNext();) {
+ final Object o = iter.next();
+ // Object matches the type the check is declared for
+ if (typeToCheck.isInstance(o)) {
+ someObjectFound = true;
+ try {
+ // create a new execution context for evaluation
+ ctx = ctx.cloneWithVariable(new Variable(ExecutionContext.IMPLICIT_VARIABLE, o));
// check the guard condition; do not evaluate if guard
// is
- // evaluated to false
- if (process(ctx)) {
+ // evaluated to false
+ if (process(ctx)) {
Object result = null;
try {
result = constraint.evaluate(ctx);
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e) {
final String msg = e.getMessage();
issues.addError(msg, e);
}
- // check result must be of Boolean type
- if (result != null && !(result instanceof Boolean))
- throw new EvaluationException("Boolean expected! ( was " + result.getClass().getName() + ")",
- this, ctx);
+ // check result must be of Boolean type
+ if (result != null && !(result instanceof Boolean))
+ throw new EvaluationException("Boolean expected! ( was " + result.getClass().getName()
+ + ")", this, ctx);
- // add issue if result of the check is false
- final Boolean r = (Boolean) result;
- if (Boolean.FALSE.equals(r)) {
- // get the error message
+ // add issue if result of the check is false
+ final Boolean r = (Boolean) result;
+ if (Boolean.FALSE.equals(r)) {
+ // get the error message
Object msgResult = null;
try {
msgResult = msg.evaluate(ctx);
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException e) {
final String msg = e.getMessage();
issues.addError(msg, e);
}
-
- String stringResult = "Message evaluation returned null";
- if (msgResult != null) {
- stringResult = msgResult.toString();
- }
- if (errorSeverity) {
- issues.addError(stringResult, o);
- } else {
- issues.addWarning(stringResult, o);
+
+ String stringResult = "Message evaluation returned null";
+ if (msgResult != null) {
+ stringResult = msgResult.toString();
+ }
+ // Involved property e.g. test::Bean#property
+ String propertyName = null;
+ if (feature != null) {
+ String featureValue = feature.getValue();
+ Property property = typeToCheck.getProperty(featureValue);
+ if (property == null)
+ throw new EvaluationException("Property " + featureValue + " for Type "
+ + typeToCheck + " not found!", this, ctx);
+ else {
+ propertyName = property.getName();
+ }
+ }
+ if (errorSeverity) {
+ issues.addError(null, stringResult, o, propertyName, null, Collections.emptyList());
+ }
+ else {
+ issues.addWarning(null, stringResult, o, propertyName, null, Collections
+ .emptyList());
+ }
}
}
}
- } catch (final NullPointerException npe) {
- final Object msgResult = msg.evaluate(ctx);
- String stringResult = "Message evaluation returned null";
- if (msgResult != null) {
- stringResult = msgResult.toString();
- }
- if (errorSeverity) {
- issues.addError(stringResult + " (NPE in constraint evaluation)", o);
- } else {
- issues.addWarning(stringResult + " (NPE in constraint evaluation)", o);
+ catch (final NullPointerException npe) {
+ final Object msgResult = msg.evaluate(ctx);
+ String stringResult = "Message evaluation returned null";
+ if (msgResult != null) {
+ stringResult = msgResult.toString();
+ }
+ if (errorSeverity) {
+ issues.addError(stringResult + " (NPE in constraint evaluation)", o);
+ }
+ else {
+ issues.addWarning(stringResult + " (NPE in constraint evaluation)", o);
+ }
}
}
}
- }
- if (warnIfNothingChecked && (!someObjectFound)) {
- issues.addWarning("The constraint did not match any model elements. Context: " + type.toString() + ", message: "
- + msg);
+ if (warnIfNothingChecked && (!someObjectFound)) {
+ issues.addWarning("The constraint did not match any model elements. Context: " + type.toString()
+ + ", message: " + msg);
}
- } finally {
- if (ctx.getCallback() != null)
+ }
+ finally {
+ if (ctx.getCallback() != null) {
ctx.getCallback().post(null);
+ }
}
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/JavaExtensionStatement.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/JavaExtensionStatement.java
index 0770e5a..30dc5d8 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/JavaExtensionStatement.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/xtend/ast/JavaExtensionStatement.java
@@ -40,9 +40,9 @@ public class JavaExtensionStatement extends AbstractExtension {
protected List<Identifier> javaParamTypes;
- public JavaExtensionStatement(final Identifier name, final List<DeclaredParameter> formalParameters,
- final Identifier returnType, final Identifier javaType, final Identifier javaMethod,
- final List<Identifier> javaParamTypes, final boolean cached, final boolean isPrivate) {
+ public JavaExtensionStatement(final Identifier name,
+ final List<DeclaredParameter> formalParameters, final Identifier returnType, final Identifier javaType,
+ final Identifier javaMethod, final List<Identifier> javaParamTypes, final boolean cached, final boolean isPrivate) {
super(name, returnType, formalParameters, cached, isPrivate);
this.javaType = javaType;
this.javaMethod = javaMethod;
@@ -53,7 +53,7 @@ public class JavaExtensionStatement extends AbstractExtension {
return javaType;
}
- public String getJavaMethodName() {
+ public String getJavaMethodName () {
return javaMethod.getValue();
}
@@ -70,13 +70,20 @@ public class JavaExtensionStatement extends AbstractExtension {
}
throw new EvaluationException(javaMethodToString() + " not found, problems were: \n" + b, this, ctx);
}
+ convertTypesToMethodSignature(ctx, method, parameters);
return method.invoke(null, parameters);
+ } catch (final InvocationTargetException ite) {
+ throw new RuntimeException(ite.getCause());
+ } catch (final Exception e) {
+ throw new EvaluationException(e, this, ctx);
}
- catch (final InvocationTargetException ite) {
- throw new RuntimeException(ite.getCause());
}
- catch (final Exception e) {
- throw new EvaluationException(e, this, ctx);
+
+ private void convertTypesToMethodSignature(ExecutionContext ctx, Method method, Object[] parameters) {
+ Class<?>[] paramTypes = method.getParameterTypes();
+ for(int i = 0; i < parameters.length; i++) {
+ Object param = parameters[i];
+ parameters[i] = ctx.getType(param).convert(param, paramTypes[i]);
}
}
@@ -92,14 +99,12 @@ public class JavaExtensionStatement extends AbstractExtension {
return javaType + "." + javaMethod + "(" + buff + ")";
}
- @SuppressWarnings("unchecked")
public Method getJavaMethod(final ExecutionContext ctx, final Set<AnalysationIssue> issues) {
try {
Class clazz = null;
clazz = ResourceLoaderFactory.createResourceLoader().loadClass(javaType.getValue());
if (clazz == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Couldn't find Java type "
- + javaType.getValue(), javaType));
+ issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, "Couldn't find Java type "+javaType.getValue(), javaType));
return null;
}
final Class[] paramTypes = new Class[javaParamTypes.size()];
@@ -108,24 +113,20 @@ public class JavaExtensionStatement extends AbstractExtension {
paramTypes[i] = ResourceLoaderFactory.createResourceLoader().loadClass(javaParamType.getValue());
if (paramTypes[i] == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, javaParamType.getValue(),
- javaParamType));
+ issues.add(new AnalysationIssue(AnalysationIssue.TYPE_NOT_FOUND, javaParamType.getValue(), javaParamType));
return null;
}
}
final Method m = clazz.getMethod(javaMethod.getValue(), paramTypes);
if (!Modifier.isStatic(m.getModifiers())) {
- issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, javaMethod.getValue()
- + " must be static!", javaMethod));
+ issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, javaMethod.getValue() + " must be static!", javaMethod));
}
if (!Modifier.isPublic(m.getModifiers())) {
- issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, javaMethod.getValue()
- + " must be public!", javaMethod));
+ issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, javaMethod.getValue() + " must be public!", javaMethod));
}
return m;
- }
- catch (final NoSuchMethodException e) {
+ } catch (final NoSuchMethodException e) {
issues.add(new AnalysationIssue(AnalysationIssue.FEATURE_NOT_FOUND, javaMethod.getValue(), javaMethod));
}
return null;
@@ -133,23 +134,18 @@ public class JavaExtensionStatement extends AbstractExtension {
@Override
public void analyzeInternal(final ExecutionContext ctx, final Set<AnalysationIssue> issues) {
- super.analyzeInternal(ctx, issues);
if (returnType == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.SYNTAX_ERROR,
- "A return type must be specified for java extensions!", this));
+ issues.add(new AnalysationIssue(AnalysationIssue.SYNTAX_ERROR, "A return type must be specified for java extensions!", this));
}
getJavaMethod(ctx, issues);
}
@Override
- protected Type internalGetReturnType(final Type[] parameters, final ExecutionContext ctx,
- final Set<AnalysationIssue> issues) {
+ protected Type internalGetReturnType(final Type[] parameters, final ExecutionContext ctx, final Set<AnalysationIssue> issues) {
if (returnType == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.SYNTAX_ERROR,
- "A return type must be specified for java extensions!", this));
+ issues.add(new AnalysationIssue(AnalysationIssue.SYNTAX_ERROR, "A return type must be specified for java extensions!", this));
return null;
- }
- else
+ } else
return ctx.getTypeForName(returnType.getValue());
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java
index 8be3acf..c08e0b0 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/xtend/XtendComponent.java
@@ -45,9 +45,11 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
private String invokeExpression;
private String expression = null;
+
private String collectProfileSummary = null;
private String verboseProfileFilename = null;
+
private String outputSlot = WorkflowContext.DEFAULT_SLOT;
/**
@@ -56,6 +58,7 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
* @param extensionAdvice
* the advice
*/
+ @Override
public void addExtensionAdvice(final String extensionAdvice) {
if (!extensionAdvices.contains(extensionAdvice)) {
extensionAdvices.add(extensionAdvice);
@@ -63,7 +66,7 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
}
/**
- * @see org.eclipse.expression.AbstractExpressionsUsingWorkflowComponent#checkConfigurationInternal(org.eclipse.workflow.issues.Issues)
+ * @see org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent#checkConfigurationInternal(org.eclipse.emf.mwe.core.issues.Issues)
*/
@Override
public void checkConfigurationInternal(final Issues issues) {
@@ -106,7 +109,7 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
}
/**
- * @see org.eclipse.workflow.lib.AbstractWorkflowComponent#getLogMessage()
+ * @see org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent#getLogMessage()
*/
@Override
public String getLogMessage() {
@@ -114,9 +117,9 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
}
/**
- * @see org.eclipse.expression.AbstractExpressionsUsingWorkflowComponent#invokeInternal2(org.eclipse.workflow.WorkflowContext,
- * org.eclipse.workflow.monitor.ProgressMonitor,
- * org.eclipse.workflow.issues.Issues)
+ * @see org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent#invokeInternal2(org.eclipse.emf.mwe.core.WorkflowContext,
+ * org.eclipse.emf.mwe.core.monitor.ProgressMonitor,
+ * org.eclipse.emf.mwe.core.issues.Issues)
*/
@Override
public void invokeInternal2(final WorkflowContext ctx, final ProgressMonitor monitor, final Issues issues) {
@@ -250,6 +253,7 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
verboseProfileFilename = fileName;
}
+ @Override
public String getComponentName() {
return COMPONENT_NAME;
}
@@ -259,4 +263,5 @@ public class XtendComponent extends AbstractExpressionsUsingWorkflowComponent {
extensionFile.replace("::", "/") + ".ext");
return in;
}
+
}