Java Code Examples for com.intellij.openapi.util.text.StringUtil.unquoteString()

The following are Jave code examples for showing how to use unquoteString() of the com.intellij.openapi.util.text.StringUtil class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: magento2-phpstorm-plugin   File: PhpServiceMethodReferenceProvider.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    if (!(element instanceof XmlElement)) {
        return PsiReference.EMPTY_ARRAY;
    }

    List<PsiReference> psiReferences = new ArrayList<>();

    String methodName = StringUtil.unquoteString(element.getText());

    PhpClass phpClass = DiIndex.getPhpClassOfServiceMethod((XmlElement) element);
    if (phpClass != null) {
        Collection<Method> methods = phpClass.getMethods();
        methods.removeIf(m -> !m.getName().equalsIgnoreCase(methodName));
        psiReferences.add(new PolyVariantReferenceBase(element, methods));
    }

    return psiReferences.toArray(new PsiReference[psiReferences.size()]);
}
 
Example 2
Project: magento2-phpstorm-plugin   File: VirtualTypeReferenceProvider.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {

    String value = StringUtil.unquoteString(element.getText());

    DiIndex index = DiIndex.getInstance(element.getProject());
    Collection<PsiElement> targets = index.getVirtualTypeElements(value, element.getResolveScope());

    if (!(targets.size() > 0)) {
        return PsiReference.EMPTY_ARRAY;
    }

    return new PsiReference[] {
            new PolyVariantReferenceBase(element, targets)
    };
}
 
Example 3
Project: magento2-phpstorm-plugin   File: EventDispatchReferenceProvider.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    String value = StringUtil.unquoteString(element.getText());
    Collection<PsiElement> targets = EventIndex.getInstance(element.getProject())
            .getEventElements(
                    value,
                    GlobalSearchScope.getScopeRestrictedByFileTypes(
                            GlobalSearchScope.allScope(element.getProject()),
                            XmlFileType.INSTANCE
                    )
    );

    if (targets.size() > 0) {
        return new PsiReference[] {new PolyVariantReferenceBase(element, targets)};
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 4
Project: magento2-phpstorm-plugin   File: PhpConstructorArgumentReferenceProvider.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {

    String parameterName = StringUtil.unquoteString(element.getText());
    if (parameterName.isEmpty() || !(element instanceof XmlElement)) {
        return PsiReference.EMPTY_ARRAY;
    }


    DiIndex diIndex = DiIndex.getInstance(element.getProject());
    PhpClass phpClass = diIndex.getPhpClassOfArgument((XmlElement) element);
    if (phpClass != null) {
        Method constructor = phpClass.getConstructor();
        if (constructor != null) {
            Collection<Parameter> parameterList = new THashSet<>(Arrays.asList(constructor.getParameters()));
            parameterList.removeIf(p -> !p.getName().contains(parameterName));
            if (parameterList.size() > 0) {
                return new PsiReference[] {new PolyVariantReferenceBase(element, parameterList)};
            }
        }
    }

    return PsiReference.EMPTY_ARRAY;
}
 
Example 5
Project: magento2-phpstorm-plugin   File: EventNameReferenceProvider.java   Source Code and License Vote up 6 votes
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    String value = StringUtil.unquoteString(element.getText());
    Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance()
        .getContainingFiles(EventNameIndex.KEY, value,
                GlobalSearchScope.getScopeRestrictedByFileTypes(
                        GlobalSearchScope.allScope(element.getProject()),
                        PhpFileType.INSTANCE
                )
        );

    PsiManager psiManager = PsiManager.getInstance(element.getProject());
    for (VirtualFile virtualFile: containingFiles) {
        PhpFile phpFile = (PhpFile) psiManager.findFile(virtualFile);
        if (phpFile != null) {
            List<PsiElement> psiElements = new ArrayList<>();
            recursiveFill(psiElements, phpFile, value);
            if (psiElements.size() > 0) {
                return new PsiReference[] {new PolyVariantReferenceBase(element, psiElements)};
            }
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 6
Project: magento2-phpstorm-plugin   File: EventNameIndex.java   Source Code and License Vote up 5 votes
private void recursiveFill(List<String> results, PsiElement psiElement) {
    if (PhpPatternsHelper.STRING_METHOD_ARGUMENT.accepts(psiElement) && isInContextOfDispatchMethod(psiElement)) {
        String eventName= StringUtil.unquoteString(psiElement.getText());
        if (eventName.length() > 0) {
            results.add(eventName);
        }
        return;
    }
    for(PsiElement child: psiElement.getChildren()) {
        recursiveFill(results, child);
    }
}
 
Example 7
Project: magento2-phpstorm-plugin   File: PhpClassMemberReferenceProvider.java   Source Code and License Vote up 5 votes
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    List<PsiReference> psiReferences = new ArrayList<>();
    final Collection<PhpClassMember> members = new THashSet<>();

    String origValue = element.getText();
    String value = StringUtil.unquoteString(element.getText());

    Matcher matcher = Pattern.compile(PhpRegex.Xml.CLASS_MEMBER_NAME).matcher(value);
    if (!matcher.find()) {
        return PsiReference.EMPTY_ARRAY;
    }

    String elementName = matcher.group(1);
    String classFQN = value.substring(0, value.lastIndexOf("::"));

    PhpIndex phpIndex = PhpIndex.getInstance(element.getProject());
    for (final PhpClass phpClass : phpIndex.getAnyByFQN(classFQN)) {
        members.addAll(phpClass.getFields());
        members.addAll(phpClass.getMethods());
        members.removeIf(c -> !c.getName().equals(elementName));
    }

    if (members.size() > 0) {
        TextRange range = new TextRange(
                origValue.indexOf(elementName),
                origValue.indexOf(elementName) + elementName.length()
        );
        psiReferences.add(new PolyVariantReferenceBase(element, range, members));
    }
    return psiReferences.toArray(new PsiReference[psiReferences.size()]);
}
 
Example 8
Project: magento2-phpstorm-plugin   File: LayoutContainerReferenceProvider.java   Source Code and License Vote up 5 votes
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    String value = StringUtil.unquoteString(element.getText());
    List<XmlTag> targets = LayoutIndex.getContainerDeclarations(value, element.getProject());
    if (targets.size() > 0) {
        return new PsiReference[] {new PolyVariantReferenceBase(element, targets)};
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 9
Project: magento2-phpstorm-plugin   File: LayoutUpdateReferenceProvider.java   Source Code and License Vote up 5 votes
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    String value = StringUtil.unquoteString(element.getText());
    List<XmlFile> targets = LayoutIndex.getLayoutFiles(element.getProject(), value);
    if (targets.size() > 0) {
        return new PsiReference[] {new PolyVariantReferenceBase(element, targets)};
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 10
Project: magento2-phpstorm-plugin   File: LayoutBlockReferenceProvider.java   Source Code and License Vote up 5 votes
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    String value = StringUtil.unquoteString(element.getText());
    List<XmlTag> targets = LayoutIndex.getBlockDeclarations(value, element.getProject());
    if (targets.size() > 0) {
        return new PsiReference[] {new PolyVariantReferenceBase(element, targets)};
    }
    return PsiReference.EMPTY_ARRAY;
}
 
Example 11
Project: manifold-ij   File: ManGotoDeclarationHandler.java   Source Code and License Vote up 5 votes
private static PsiElement findTargetFeature( PsiAnnotation psiAnnotation, ManifoldPsiClass facade )
  {
    PsiAnnotationMemberValue value = psiAnnotation.findAttributeValue( SourcePosition.FEATURE );
    String featureName = StringUtil.unquoteString( value.getText() );
//    value = psiAnnotation.findAttributeValue( SourcePosition.TYPE );
//    if( value != null )
//    {
//      String ownersType = StringUtil.unquoteString( value.getText() );
//      if( ownersType != null )
//      {
//        PsiElement target = findIndirectTarget( ownersType, featureName, facade.getRawFile().getProject() );
//        if( target != null )
//        {
//          return target;
//        }
//      }
//    }

    int iOffset = Integer.parseInt( psiAnnotation.findAttributeValue( SourcePosition.OFFSET ).getText() );
    int iLength = Integer.parseInt( psiAnnotation.findAttributeValue( SourcePosition.LENGTH ).getText() );

    List<PsiFile> sourceFiles = facade.getRawFiles();
    if( iOffset >= 0 )
    {
      //PsiElement target = sourceFile.findElementAt( iOffset );
      //## todo: handle multiple files
      return new FakeTargetElement( sourceFiles.get( 0 ), iOffset, iLength >= 0 ? iLength : 1, featureName );
    }
    return facade;
  }
 
Example 12
Project: magento2-phpstorm-plugin   File: ModuleNameIndex.java   Source Code and License Vote up 4 votes
@NotNull
@Override
public DataIndexer<String, String, FileContent> getIndexer() {
    return inputData -> {
        Map<String, String> map = new HashMap<>();
        PsiFile psiFile = inputData.getPsiFile();

        if (!Settings.isEnabled(psiFile.getProject())) {
            return map;
        }

        if (psiFile instanceof PhpFile) {
            MethodReference  method = PsiTreeUtil.findChildOfAnyType(psiFile, MethodReference.class);
            if (method != null) {
                ParameterList parameterList = method.getParameterList();
                if (parameterList != null) {
                    PsiElement firstParameter = parameterList.getFirstPsiChild();
                    if (firstParameter != null && firstParameter instanceof ClassConstantReference) {
                        String constantName = ((ClassConstantReference) firstParameter).getName();
                        if (constantName != null) {
                            PsiElement moduleNameEl = ((ClassConstantReference) firstParameter).getNextPsiSibling();
                            if (moduleNameEl != null && moduleNameEl instanceof StringLiteralExpression) {
                                String moduleName = StringUtil.unquoteString(moduleNameEl.getText());

                                PsiElement modulePathEl =
                                        ((StringLiteralExpression) moduleNameEl).getNextPsiSibling();
                                if (modulePathEl != null) {
                                    Pattern pattern = Pattern.compile(
                                            "__DIR__(\\s*[.,]\\s*[\\'\\\"]((/[\\w-]+)+)/?[\\'\\\"])?"
                                    );
                                    Matcher matcher = pattern.matcher(modulePathEl.getText());
                                    if (matcher.find()) {
                                        String modulePath = matcher.group(2);
                                        map.put(
                                                moduleName,
                                                modulePath == null ? "" : modulePath
                                        );
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        return map;
    };
}