com.jetbrains.php.lang.psi.elements.Variable Java Examples

The following examples show how to use com.jetbrains.php.lang.psi.elements.Variable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocTagNameAnnotationReferenceContributor.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Override
public boolean isReferenceTo(@NotNull PsiElement element) {

    // use Doctrine\ORM\Mapping as "ORM";
    if (element instanceof PhpUse) {
        String useName = ((PhpUse) element).getName();
        String docUseName = getDocBlockName();

        if(useName.equals(docUseName)) {
            return true;
        }

    }

    // eg for "Optimize Imports"
    // attach reference to @Template()
    // reference can also point to a namespace e.g. @Annotation\Exclude()
    if (element instanceof PhpNamedElement && !(element instanceof Variable)) {
        if(((PhpNamedElement) element).getName().equals(getDocBlockName())) {
            return true;
        }
    }

    return false;
}
 
Example #2
Source File: BxSuperglobalsProvider.java    From bxfs with MIT License 5 votes vote down vote up
@Nullable
@Override
public String getType(PsiElement e) {
	if (e instanceof Variable) {
		BxSuperglobal superglobal = bxSuperglobals.get(((Variable) e).getName()); if (superglobal != null) {
			if (superglobal.scopeFileNames == null || superglobal.scopeFileNames.contains(e.getContainingFile().getName()))
				return superglobal.className;
		}
	}

	return null;
}
 
Example #3
Source File: BladeInjectTypeProvider.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement element) {
    if(!(element instanceof Variable) || !LaravelSettings.getInstance(element.getProject()).pluginEnabled){
        return null;
    }

    String name = ((Variable) element).getName();

    PsiFile bladeFile = getHostBladeFileForInjectionIfExists(element);
    if(bladeFile == null) {
        return null;
    }

    PhpType phpType = new PhpType();

    PsiTreeUtil.findChildrenOfType(bladeFile, BladePsiDirective.class).stream()
        .filter(bladePsiDirective -> "@inject".equals(bladePsiDirective.getName()))
        .forEach(bladePsiDirective -> {
            BladePsiDirectiveParameter parameter = PsiTreeUtil.findChildOfType(bladePsiDirective, BladePsiDirectiveParameter.class);
            if(parameter == null) {
                return;
            }

            List<String> strings = ContainerUtil.map(BladePsiUtil.extractParameters(parameter.getText()), PsiElementUtils::trimQuote);
            if(strings.size() > 1 && name.equals(strings.get(0))) {
                phpType.add("\\" + StringUtils.stripStart(strings.get(1), "\\"));
            }
        });

    return !phpType.isEmpty() ? phpType : null;
}
 
Example #4
Source File: PhpVariableInsertHandler.java    From intellij-latte with MIT License 5 votes vote down vote up
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) {
	PsiElement element = context.getFile().findElementAt(context.getStartOffset());
	if (element != null && element.getLanguage() == LatteLanguage.INSTANCE) {
		PsiElement parent = element.getParent();
		if (!(parent instanceof Variable) && !element.getText().startsWith("$")) {
			Editor editor = context.getEditor();
			CaretModel caretModel = editor.getCaretModel();
			int offset = caretModel.getOffset();
			caretModel.moveToOffset(element.getTextOffset() + (PhpPsiUtil.isOfType(parent, PhpElementTypes.CAST_EXPRESSION) ? 1 : 0));
			EditorModificationUtil.insertStringAtCaret(editor, "$");
			caretModel.moveToOffset(offset + 1);
			PsiDocumentManager.getInstance(context.getProject()).commitDocument(editor.getDocument());
		}
	}
}