use of com.intellij.psi.PsiElement 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;
}
use of com.intellij.psi.PsiElement in project buck by facebook.
the class BuckBuildUtil method extractBuckTarget.
/**
* Get the buck target from a buck file.
* TODO(#7908675): We should use Buck's own classes for it.
*/
public static String extractBuckTarget(Project project, VirtualFile file) {
BuckFile buckFile = (BuckFile) PsiManager.getInstance(project).findFile(file);
if (buckFile == null) {
return null;
}
PsiElement[] children = buckFile.getChildren();
for (PsiElement child : children) {
if (child.getNode().getElementType() == BuckTypes.RULE_BLOCK) {
PsiElement ruleName = child.getFirstChild();
// Find rule "project_config"
if (ruleName != null && BuckPsiUtils.testType(ruleName, BuckTypes.RULE_NAME) && ruleName.getText().equals(PROJECT_CONFIG_RULE_NAME)) {
// Find property "src_target"
PsiElement bodyElement = BuckPsiUtils.findChildWithType(child, BuckTypes.RULE_BODY);
return getPropertyValue((BuckRuleBody) bodyElement, SRC_TARGET_PROPERTY_NAME);
}
}
}
return null;
}
use of com.intellij.psi.PsiElement in project buck by facebook.
the class BuckFormattingModelBuilder method getRangeAffectingIndent.
@Nullable
@Override
public TextRange getRangeAffectingIndent(PsiFile file, int offset, ASTNode elementAtOffset) {
final PsiElement element = elementAtOffset.getPsi();
final PsiElement container = element.getParent();
return container != null ? container.getTextRange() : null;
}
use of com.intellij.psi.PsiElement in project buck by facebook.
the class DependenciesOptimizer method optimzeDeps.
public static void optimzeDeps(@NotNull PsiFile file) {
final PropertyVisitor visitor = new PropertyVisitor();
file.accept(new BuckVisitor() {
@Override
public void visitElement(PsiElement node) {
node.acceptChildren(this);
node.accept(visitor);
}
});
// Commit modifications.
final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject());
manager.doPostponedOperationsAndUnblockDocument(manager.getDocument(file));
}
use of com.intellij.psi.PsiElement in project qi4j-sdk by Qi4j.
the class AbstractIntention method invoke.
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
if (isFileReadOnly(project, file)) {
return;
}
final PsiElement element = findMatchingElement(file, editor);
if (element == null) {
return;
}
processIntention(project, editor, element);
}
Aggregations