Search in sources :

Example 1 with BuckExpression

use of com.facebook.buck.intellij.ideabuck.lang.psi.BuckExpression in project buck by facebook.

the class BuckBuildUtil method getPropertyValue.

/**
   * Get the value of a property in a specific buck rule body.
   * TODO(#7908675): We should use Buck's own classes for it.
   */
public static String getPropertyValue(BuckRuleBody body, String name) {
    if (body == null) {
        return null;
    }
    PsiElement[] children = body.getChildren();
    for (PsiElement child : children) {
        if (BuckPsiUtils.testType(child, BuckTypes.PROPERTY)) {
            PsiElement lvalue = child.getFirstChild();
            PsiElement propertyName = lvalue.getFirstChild();
            if (propertyName != null && propertyName.getText().equals(name)) {
                BuckExpression expression = (BuckExpression) BuckPsiUtils.findChildWithType(child, BuckTypes.EXPRESSION);
                return expression != null ? BuckPsiUtils.getStringValueFromExpression(expression) : null;
            }
        }
    }
    return null;
}
Also used : BuckExpression(com.facebook.buck.intellij.ideabuck.lang.psi.BuckExpression) PsiElement(com.intellij.psi.PsiElement)

Aggregations

BuckExpression (com.facebook.buck.intellij.ideabuck.lang.psi.BuckExpression)1 PsiElement (com.intellij.psi.PsiElement)1