use of com.perl5.lang.perl.psi.PsiPerlCommaSequenceExpr in project Perl5-IDEA by Camelcade.
the class PerlMooseExtendsStatementImpl method getParentsList.
@NotNull
protected List<String> getParentsList() {
List<String> result = new ArrayList<>();
PsiElement expr = getExpr();
if (expr != null) {
if (expr instanceof PerlString) {
String content = ElementManipulators.getValueText(expr);
if (!content.isEmpty()) {
result.add(content);
}
} else if (expr instanceof PsiPerlCommaSequenceExpr) {
PsiElement element = expr.getFirstChild();
while (element != null) {
if (element instanceof PerlString) {
String content = ElementManipulators.getValueText(element);
if (!content.isEmpty()) {
result.add(content);
}
}
element = element.getNextSibling();
}
} else if (expr instanceof PsiPerlStringList) {
for (PsiElement element : PerlPsiUtil.collectStringElements(expr.getFirstChild())) {
String content = element.getText();
if (!content.isEmpty()) {
result.add(content);
}
}
} else {
// todo we need to somehow mark statement as bad
}
}
return result;
}
use of com.perl5.lang.perl.psi.PsiPerlCommaSequenceExpr in project Perl5-IDEA by Camelcade.
the class MasonFlagsStatementImpl method getExtendsFlagValue.
@Nullable
private String getExtendsFlagValue() {
PsiElement expr = getExpr();
// fixme this can be a prototype for scanning a hash to map
if (expr instanceof PsiPerlCommaSequenceExpr) {
PsiElement currentElement = expr.getFirstChild();
while (currentElement != null) {
PsiElement keyElement = currentElement;
// comma between key and val
if (isNullOrNotComma(currentElement = PerlPsiUtil.getNextSignificantSibling(currentElement))) {
break;
}
PsiElement valElement = PerlPsiUtil.getNextSignificantSibling(currentElement);
if (valElement != null && StringUtil.equals("extends", ElementManipulators.getValueText(keyElement))) {
return ElementManipulators.getValueText(valElement);
}
// comma between pairs
if (isNullOrNotComma(currentElement = PerlPsiUtil.getNextSignificantSibling(currentElement))) {
break;
}
currentElement = PerlPsiUtil.getNextSignificantSibling(currentElement);
}
}
return null;
}
use of com.perl5.lang.perl.psi.PsiPerlCommaSequenceExpr in project Perl5-IDEA by Camelcade.
the class PerlStringCompletionUtil method fillWithHashIndexes.
public static void fillWithHashIndexes(@NotNull final PsiElement element, @NotNull final CompletionResultSet result) {
for (String text : HASH_INDEXES_CACHE) {
addElement(text, result);
}
PsiFile file = element.getContainingFile();
file.accept(new PerlRecursiveVisitor() {
@Override
public void visitStringContentElement(@NotNull PerlStringContentElementImpl o) {
if (o != element && SIMPLE_HASH_INDEX.accepts(o)) {
processStringElement(o);
}
super.visitStringContentElement(o);
}
@Override
public void visitCommaSequenceExpr(@NotNull PsiPerlCommaSequenceExpr o) {
if (o.getParent() instanceof PsiPerlAnonHash) {
PsiElement sequenceElement = o.getFirstChild();
boolean isKey = true;
while (sequenceElement != null) {
ProgressManager.checkCanceled();
IElementType elementType = sequenceElement.getNode().getElementType();
if (isKey && sequenceElement instanceof PerlString) {
for (PerlStringContentElement stringElement : PerlPsiUtil.collectStringElements(sequenceElement)) {
processStringElement(stringElement);
}
} else if (elementType == COMMA || elementType == FAT_COMMA) {
isKey = !isKey;
}
sequenceElement = PerlPsiUtil.getNextSignificantSibling(sequenceElement);
}
}
super.visitCommaSequenceExpr(o);
}
protected void processStringElement(PerlStringContentElement stringContentElement) {
String text = stringContentElement.getText();
if (StringUtil.isNotEmpty(text) && !HASH_INDEXES_CACHE.contains(text) && PerlLexer.IDENTIFIER_PATTERN.matcher(text).matches()) {
HASH_INDEXES_CACHE.add(text);
addElement(text, result);
}
}
});
}
use of com.perl5.lang.perl.psi.PsiPerlCommaSequenceExpr in project Perl5-IDEA by Camelcade.
the class PerlTypedHandler method tryToAddFatComma.
@Nullable
private Result tryToAddFatComma(@NotNull Editor editor, @NotNull PsiFile file, int offset) {
if (!Perl5CodeInsightSettings.getInstance().SMART_COMMA_SEQUENCE_TYPING) {
return null;
}
PsiElement elementAtCaret = file.findElementAt(offset);
if (!(elementAtCaret instanceof PsiWhiteSpace)) {
return null;
}
PsiElement commaSequence = elementAtCaret.getPrevSibling();
if (!(commaSequence instanceof PsiPerlCommaSequenceExpr)) {
return null;
}
PsiElement lastChild = commaSequence.getLastChild();
IElementType lastChildElementType = PsiUtilCore.getElementType(lastChild);
if (lastChildElementType == COMMA || lastChildElementType == FAT_COMMA) {
return null;
}
PsiElement commaElement = PerlPsiUtil.getPrevSignificantSibling(lastChild);
if (PsiUtilCore.getElementType(commaElement) != COMMA) {
return null;
}
PsiElement fatCommaElement = PerlPsiUtil.getPrevSignificantSibling(PerlPsiUtil.getPrevSignificantSibling(commaElement));
if (PsiUtilCore.getElementType(fatCommaElement) != FAT_COMMA) {
return null;
}
int reformatFrom = commaSequence.getNode().getStartOffset();
Document document = editor.getDocument();
document.insertString(offset, "=>");
editor.getCaretModel().moveToOffset(offset + 2);
Project project = file.getProject();
PsiDocumentManager.getInstance(project).commitDocument(document);
CodeStyleManager.getInstance(project).reformatText(file, reformatFrom, offset + 2);
AutoPopupController.getInstance(project).scheduleAutoPopup(editor);
return Result.CONTINUE;
}
use of com.perl5.lang.perl.psi.PsiPerlCommaSequenceExpr in project Perl5-IDEA by Camelcade.
the class HTMLMasonFlagsStatementImpl method getParentComponentPath.
@Nullable
@Override
public String getParentComponentPath() {
HTMLMasonFlagsStatementStub stub = getStub();
if (stub != null) {
return stub.getParentComponentPath();
}
PsiPerlCommaSequenceExpr expr = PsiTreeUtil.findChildOfType(this, PsiPerlCommaSequenceExpr.class);
if (expr != null) {
PsiElement firstChild = expr.getFirstChild();
PsiElement lastChild = expr.getLastChild();
if (firstChild instanceof PerlString && StringUtil.equals("inherit", ElementManipulators.getValueText(firstChild)) && lastChild instanceof PerlString) {
return ElementManipulators.getValueText(lastChild);
}
}
return UNDEF_RESULT;
}
Aggregations