-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for issue #267: add pointcut for variable assignment
- Loading branch information
1 parent
d05fb6b
commit b43f93c
Showing
9 changed files
with
311 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ipse.dsl/src/org/codehaus/groovy/eclipse/dsl/pointcuts/impl/AssignedVariablePointcut.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2009-2017 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.codehaus.groovy.eclipse.dsl.pointcuts.impl; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import org.codehaus.groovy.ast.Variable; | ||
import org.codehaus.groovy.ast.expr.BinaryExpression; | ||
import org.codehaus.groovy.eclipse.dsl.pointcuts.AbstractPointcut; | ||
import org.codehaus.groovy.eclipse.dsl.pointcuts.GroovyDSLDContext; | ||
import org.codehaus.groovy.eclipse.dsl.pointcuts.IPointcut; | ||
import org.codehaus.groovy.eclipse.dsl.pointcuts.PointcutVerificationException; | ||
import org.eclipse.core.resources.IStorage; | ||
|
||
/** | ||
* Matches when current context is enclosed by a variable assignment that | ||
* satisfies the given name (string) or constraints (pointcut). | ||
*/ | ||
public class AssignedVariablePointcut extends AbstractPointcut { | ||
|
||
public AssignedVariablePointcut(IStorage containerIdentifier, String pointcutName) { | ||
super(containerIdentifier, pointcutName); | ||
} | ||
|
||
@Override | ||
public Collection<?> matches(GroovyDSLDContext pattern, Object toMatch) { | ||
BinaryExpression enclosing = (BinaryExpression) pattern.getCurrentScope().getWormhole().get("enclosingAssignment"); | ||
if (enclosing != null && enclosing.getLeftExpression() instanceof Variable) { | ||
Object argument = getFirstArgument(); | ||
if (argument instanceof String) { | ||
if (argument.equals(((Variable) enclosing.getLeftExpression()).getName())) { | ||
return Collections.singleton(enclosing); | ||
} | ||
} else { | ||
return matchOnPointcutArgument((IPointcut) argument, pattern, Collections.singleton(enclosing)); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void verify() throws PointcutVerificationException { | ||
String failure = oneStringOrOnePointcutArg(); | ||
if (failure != null) { | ||
throw new PointcutVerificationException(failure, this); | ||
} | ||
super.verify(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.