use of com.facebook.buck.intellij.ideabuck.lang.BuckFile 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.facebook.buck.intellij.ideabuck.lang.BuckFile in project buck by facebook.
the class BuckCopyPasteProcessor method preprocessOnPaste.
@Override
public String preprocessOnPaste(Project project, PsiFile psiFile, Editor editor, String text, RawText rawText) {
if (!(psiFile instanceof BuckFile)) {
return text;
}
final Document document = editor.getDocument();
PsiDocumentManager.getInstance(project).commitDocument(document);
final SelectionModel selectionModel = editor.getSelectionModel();
// Pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor.
final int selectionStart = selectionModel.getSelectionStart();
final PsiElement element = psiFile.findElementAt(selectionStart);
if (element == null) {
return text;
}
if (BuckPsiUtils.hasElementType(element.getNode(), TokenType.WHITE_SPACE, BuckTypes.SINGLE_QUOTED_STRING, BuckTypes.DOUBLE_QUOTED_STRING)) {
PsiElement property = BuckPsiUtils.findAncestorWithType(element, BuckTypes.PROPERTY);
if (checkPropertyName(property)) {
return formatPasteText(text, element, project);
}
}
return text;
}
Aggregations