use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class BuildElementGenerator method createKeywordArgument.
public Argument.Keyword createKeywordArgument(String keyword, String value) {
String dummyText = String.format("foo(%s = \"%s\")", keyword, value);
FuncallExpression funcall = (FuncallExpression) createExpressionFromText(dummyText);
return (Argument.Keyword) funcall.getArguments()[0];
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class BuildFileFoldingBuilder method getPlaceholderText.
@Override
@Nullable
public String getPlaceholderText(ASTNode node) {
PsiElement psi = node.getPsi();
if (psi instanceof FuncallExpression) {
FuncallExpression expr = (FuncallExpression) psi;
String name = expr.getNameArgumentValue();
if (name != null) {
return "name = \"" + name + "\"...";
}
}
if (psi instanceof LoadStatement) {
String fileName = ((LoadStatement) psi).getImportedPath();
if (fileName != null) {
return "\"" + fileName + "\"...";
}
}
return "...";
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class BuiltInRuleAnnotator method visitFuncallExpression.
@Override
public void visitFuncallExpression(FuncallExpression node) {
BuildLanguageSpec spec = BuildLanguageSpecProvider.getInstance().getLanguageSpec(node.getProject());
if (spec == null) {
return;
}
String ruleName = node.getFunctionName();
RuleDefinition rule = spec.getRule(ruleName);
if (rule == null) {
return;
}
if (node.getReferencedElement() != null) {
// this has been locally overridden, so don't attempt validation
return;
}
Set<String> missingAttributes = new TreeSet<>(rule.mandatoryAttributes.keySet());
for (Argument arg : node.getArguments()) {
if (arg instanceof Argument.StarStar) {
missingAttributes.clear();
continue;
}
String name = arg.getName();
if (name == null) {
continue;
}
AttributeDefinition attribute = rule.getAttribute(name);
if (attribute == null) {
markError(arg, String.format("Unrecognized attribute '%s' for rule type '%s'", name, ruleName));
continue;
}
missingAttributes.remove(name);
Expression argValue = arg.getValue();
if (argValue == null) {
continue;
}
PsiElement rootElement = PsiUtils.getReferencedTargetValue(argValue);
if (!BuildElementValidation.possiblyValidType(rootElement, attribute.type)) {
markError(arg, String.format("Invalid value for attribute '%s'. Expected a value of type '%s'", name, attribute.type));
}
}
if (!missingAttributes.isEmpty()) {
markError(node, String.format("Target missing required attribute(s): %s", Joiner.on(',').join(missingAttributes)));
}
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class RenameRefactoringTest method testRenameExternalWorkspaceTarget.
@Test
public void testRenameExternalWorkspaceTarget() {
BuildFile workspaceFile = createBuildFile(new WorkspacePath("WORKSPACE"), "maven_jar(", " name = \"javax\",", " artifact = \"javax.inject:javax.inject:1\",", " sha1 = \"6975da39a7040257bd51d21a231b76c915872d38\",", ")");
BuildFile referencingFile = createBuildFile(new WorkspacePath("java/com/foo/BUILD"), "java_library(name = \"javax_inject\", exports = [\"@javax//jar\"])");
FuncallExpression targetRule = PsiUtils.findFirstChildOfClassRecursive(workspaceFile, FuncallExpression.class);
testFixture.renameElement(targetRule, "v2_lib");
assertFileContents(workspaceFile, "maven_jar(", " name = \"v2_lib\",", " artifact = \"javax.inject:javax.inject:1\",", " sha1 = \"6975da39a7040257bd51d21a231b76c915872d38\",", ")");
assertFileContents(referencingFile, "java_library(name = \"javax_inject\", exports = [\"@v2_lib//jar\"])");
}
use of com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression in project intellij by bazelbuild.
the class RenameRefactoringTest method testTargetRenameValidation.
@Test
public void testTargetRenameValidation() {
BuildFile file = createBuildFile(new WorkspacePath("com/google/foo/BUILD"), "rule_type(name = \"target\")");
FuncallExpression target = PsiUtils.findFirstChildOfClassRecursive(file, FuncallExpression.class);
assertThat(RenameUtil.isValidName(getProject(), target, "name-with_allowed,meta=chars+-./@~")).isTrue();
assertThat(RenameUtil.isValidName(getProject(), target, "name:withColon")).isFalse();
assertThat(RenameUtil.isValidName(getProject(), target, "/start-with-slash")).isFalse();
assertThat(RenameUtil.isValidName(getProject(), target, "up-level-ref/../etc")).isFalse();
}
Aggregations