use of com.perl5.lang.perl.psi.PerlString in project Perl5-IDEA by Camelcade.
the class PerlElementFactory method createString.
public static PerlString createString(Project project, String code) {
PerlFileImpl file = createFile(project, code + ";");
PerlString string = PsiTreeUtil.findChildOfType(file, PerlString.class);
assert string != null : "While creating bare string from: " + code;
return string;
}
use of com.perl5.lang.perl.psi.PerlString 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.PerlString in project Perl5-IDEA by Camelcade.
the class HTMLMasonComponentReferencesProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
if (element.getChildren().length == 0) {
assert element instanceof PerlString;
String content = ElementManipulators.getValueText(element);
if (StringUtil.isNotEmpty(content)) {
Matcher m;
TextRange range = ElementManipulators.getValueTextRange(element);
List<PsiReference> result = new ArrayList<>();
if (// method call
(m = METHOD_CALL_PATTERN.matcher(content)).matches()) {
String fileOrSlug = m.group(1);
String methodName = m.group(2);
if (methodName == null) {
methodName = "";
}
TextRange componentRange = new TextRange(range.getStartOffset(), range.getStartOffset() + fileOrSlug.length());
TextRange methodRange = new TextRange(range.getEndOffset() - methodName.length(), range.getEndOffset());
if (StringUtil.equals(fileOrSlug, COMPONENT_SLUG_SELF)) {
result.add(new HTMLMasonComponentSimpleReference((PerlString) element, componentRange));
} else if (StringUtil.equals(fileOrSlug, COMPONENT_SLUG_PARENT)) {
result.add(new HTMLMasonComponentParentReference((PerlString) element, componentRange));
} else if (StringUtil.equals(fileOrSlug, COMPONENT_SLUG_REQUEST)) {
result.add(new HTMLMasonComponentSimpleReference((PerlString) element, componentRange));
} else // component or subcomponent
{
result.add(new HTMLMasonComponentReference((PerlString) element, componentRange));
}
if (methodRange.getLength() > 0) {
result.add(new HTMLMasonMethodReference((PerlString) element, methodRange));
}
} else // it's subcomponent or other component
{
result.add(new HTMLMasonComponentReference((PerlString) element, range));
}
return result.toArray(new PsiReference[result.size()]);
}
}
return PsiReference.EMPTY_ARRAY;
}
use of com.perl5.lang.perl.psi.PerlString 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;
}
use of com.perl5.lang.perl.psi.PerlString in project Perl5-IDEA by Camelcade.
the class MasonComponentsCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement position = parameters.getPosition();
PsiElement parent = position.getParent();
if (parent instanceof PerlString) {
Project project = position.getProject();
MasonSettings masonSettings = MasonSettings.getInstance(project);
String fullPrefix = ElementManipulators.getValueText(parent).replace(CompletionInitializationContext.DUMMY_IDENTIFIER, "").replace(CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED, "");
result = result.withPrefixMatcher(new PlainPrefixMatcher(fullPrefix));
final CompletionResultSet finalResultSet = result;
PsiFile psiFile = position.getContainingFile();
if (psiFile instanceof MasonFileImpl) {
final VirtualFile containingFile = MasonCoreUtil.getContainingVirtualFile(psiFile);
VirtualFile containingDir;
if (containingFile != null && (containingDir = containingFile.getParent()) != null) {
VfsUtil.processFilesRecursively(containingDir, new MasonRootsProcessor(containingDir) {
@Override
public boolean process(VirtualFile virtualFile) {
FileType fileType = virtualFile.getFileType();
if (fileType instanceof MasonPurePerlComponentFileType && !containingFile.equals(virtualFile)) {
String relativePath = VfsUtil.getRelativePath(virtualFile, getRoot());
if (StringUtil.isNotEmpty(relativePath)) {
finalResultSet.addElement(LookupElementBuilder.create(relativePath).withIcon(fileType.getIcon()));
}
}
return true;
}
});
}
}
for (VirtualFile componentRoot : masonSettings.getComponentsRoots()) {
VfsUtil.processFilesRecursively(componentRoot, new MasonRootsProcessor(componentRoot) {
@Override
public boolean process(VirtualFile virtualFile) {
FileType fileType = virtualFile.getFileType();
if (fileType instanceof MasonPurePerlComponentFileType) {
String relativePath = VfsUtil.getRelativePath(virtualFile, getRoot());
if (StringUtil.isNotEmpty(relativePath)) {
finalResultSet.addElement(LookupElementBuilder.create("/" + relativePath).withIcon(fileType.getIcon()));
}
}
return true;
}
});
}
}
}
Aggregations