Add references to file-paths in BuildConfig.groovy.

This commit is contained in:
Sergey Evdokimov
2011-03-04 19:05:26 +03:00
parent 2d6f7dd44b
commit d7171e0589
2 changed files with 78 additions and 5 deletions
@@ -0,0 +1,54 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.lang.psi.patterns;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PatternCondition;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
public class GroovyAssignmentExpressionPattern extends GroovyExpressionPattern<GrAssignmentExpression, GroovyAssignmentExpressionPattern> {
protected GroovyAssignmentExpressionPattern() {
super(GrAssignmentExpression.class);
}
public GroovyAssignmentExpressionPattern left(@NotNull final ElementPattern pattern) {
return with(new PatternCondition<GrAssignmentExpression>("left") {
public boolean accepts(@NotNull final GrAssignmentExpression psiBinaryExpression, final ProcessingContext context) {
return pattern.getCondition().accepts(psiBinaryExpression.getLValue(), context);
}
});
}
public GroovyAssignmentExpressionPattern right(@NotNull final ElementPattern pattern) {
return with(new PatternCondition<GrAssignmentExpression>("right") {
public boolean accepts(@NotNull final GrAssignmentExpression psiBinaryExpression, final ProcessingContext context) {
return pattern.getCondition().accepts(psiBinaryExpression.getRValue(), context);
}
});
}
public GroovyAssignmentExpressionPattern operation(final ElementPattern pattern) {
return with(new PatternCondition<GrAssignmentExpression>("operation") {
public boolean accepts(@NotNull final GrAssignmentExpression psiBinaryExpression, final ProcessingContext context) {
return pattern.getCondition().accepts(psiBinaryExpression.getOperationToken(), context);
}
});
}
}
@@ -36,10 +36,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
@@ -58,6 +55,10 @@ public class GroovyPatterns extends PsiJavaPatterns {
return new GroovyBinaryExpressionPattern();
}
public static GroovyAssignmentExpressionPattern groovyAssignmentExpression() {
return new GroovyAssignmentExpressionPattern();
}
public static GroovyElementPattern.Capture<GrLiteral> groovyLiteralExpression() {
return groovyLiteralExpression(null);
}
@@ -71,6 +72,23 @@ public class GroovyPatterns extends PsiJavaPatterns {
});
}
public static GroovyElementPattern.Capture<GroovyPsiElement> rightOfAssignment(final ElementPattern<? extends GroovyPsiElement> value,
final GroovyAssignmentExpressionPattern assignment) {
return new GroovyElementPattern.Capture<GroovyPsiElement>(new InitialPatternCondition<GroovyPsiElement>(GroovyPsiElement.class) {
@Override
public boolean accepts(@Nullable Object o, ProcessingContext context) {
if (!(o instanceof GroovyPsiElement)) return false;
PsiElement parent = ((GroovyPsiElement)o).getParent();
if (!(parent instanceof GrAssignmentExpression)) return false;
if (((GrAssignmentExpression)parent).getRValue() != o) return false;
return assignment.getCondition().accepts(parent, context) && value.getCondition().accepts(o, context);
}
});
}
public static GroovyElementPattern.Capture<GrLiteralImpl> stringLiteral() {
return new GroovyElementPattern.Capture<GrLiteralImpl>(new InitialPatternCondition<GrLiteralImpl>(GrLiteralImpl.class) {
public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
@@ -91,7 +109,8 @@ public class GroovyPatterns extends PsiJavaPatterns {
PsiElement nameElement = ((GrArgumentLabel)o).getNameElement();
if (nameElement instanceof LeafPsiElement) {
IElementType elementType = ((LeafPsiElement)nameElement).getElementType();
if (elementType == GroovyElementTypes.mIDENT || CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getPsiTypeName(elementType))) {
if (elementType == GroovyElementTypes.mIDENT ||
CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getPsiTypeName(elementType))) {
return namePattern.accepts(((GrArgumentLabel)o).getName());
}
}