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

The following examples show how to use com.jetbrains.php.lang.psi.elements.Field. 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: DoctrineYamlAnnotationLookupBuilder.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static Set<String> getAnnotations(Project project, String className) {

        HashSet<String> map = new HashSet<>();

        PhpClass phpClass = PhpElementsUtil.getClass(project, className);
        if(phpClass == null) {
            return map;
        }

        for(Field field: phpClass.getFields()) {
            if(!field.isConstant()) {
                map.add(field.getName());
            }
        }

        return map;
    }
 
Example #2
Source File: AnnotationGoToDeclarationHandlerTest.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
public void testNavigationForPropertyInsideAnnotationAttributes() {
    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n" +
            "namespace Bar;\n" +
            "\n" +
            "use Foo\\Bar;\n" +
            "\n" +
            "class Foo\n" +
            "{\n" +
            "  /** @Bar(fo<caret>o=\"test\") */" +
            "}\n",
        PlatformPatterns.psiElement(Field.class).withName("foo")
    );

    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n" +
            "namespace Bar;\n" +
            "\n" +
            "use Foo\\Bar;\n" +
            "\n" +
            "class Foo\n" +
            "{\n" +
            "  /** @Bar(access<caret>Control=\"test\") */" +
            "}\n",
        PlatformPatterns.psiElement(PhpDocTag.class)
    );
}
 
Example #3
Source File: AnnotationGoToDeclarationHandlerTest.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
public void testThatPropertyProvidesNavigation() {
    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n" +
            "namespace Bar;\n" +
            "use Foo\\Bar;\n" +
            "\n" +
            "class Foo\n" +
            "{\n" +
            "  /** @Bar(f<caret>oo=\"bar\") */" +
            "}\n",
        PlatformPatterns.psiElement(Field.class).withName("foo")
    );

    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n" +
            "namespace Bar;\n" +
            "use Foo\\Bar;\n" +
            "\n" +
            "class Foo\n" +
            "{\n" +
            "  /** @Foo(bla=\"\", foo={@Bar(f<caret>oo=\"bar\")}) */" +
            "}\n",
        PlatformPatterns.psiElement(Field.class).withName("foo")
    );
}
 
Example #4
Source File: AnnotationGoToDeclarationHandler.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
/**
 * Add static field targets for @Route(name=ClassName::<FOO>)
 *
 * @param psiElement DOC_IDENTIFIER after DOC_STATIC
 * @param targets Goto targets
 */
private void addStaticClassConstTargets(PsiElement psiElement, List<PsiElement> targets) {
    PhpClass phpClass = AnnotationUtil.getClassFromConstant(psiElement);
    if(phpClass != null) {
        String constName = psiElement.getText();

        if ("class".equals(constName)) {
            targets.add(phpClass);
        } else {
            Field field = phpClass.findFieldByName(constName, true);
            if(field != null) {
                targets.add(field);
            }
        }
    }
}
 
Example #5
Source File: ColumnNameCompletionProvider.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Override
public void getPropertyValueCompletions(AnnotationPropertyParameter annotationPropertyParameter, AnnotationCompletionProviderParameter completionParameter) {

    String propertyName = annotationPropertyParameter.getPropertyName();
    if(propertyName == null) {
        return;
    }

    if(propertyName.equals("name") && PhpLangUtil.equalsClassNames(annotationPropertyParameter.getPhpClass().getPresentableFQN(), "Doctrine\\ORM\\Mapping\\Column")) {
        PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(annotationPropertyParameter.getElement(), PhpDocComment.class);
        if(phpDocComment != null) {
            PhpPsiElement classField = phpDocComment.getNextPsiSibling();
            if(classField != null && classField.getNode().getElementType() == PhpElementTypes.CLASS_FIELDS) {
                Field field = PsiTreeUtil.getChildOfType(classField, Field.class);
                if(field != null) {
                    String name = field.getName();
                    if(StringUtils.isNotBlank(name)) {
                        completionParameter.getResult().addElement(LookupElementBuilder.create(underscore(name)));
                    }
                }
            }
        }
    }

}
 
Example #6
Source File: FormTypeReferenceContributorTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void testFormDataFieldPropertyPathReferencesForProperty() {
    for (String s : new String[]{"var", "varBar", "var_bar", "var_Bar"}) {
        assertReferenceMatchOnParent(PhpFileType.INSTANCE, "<?php\n" +
            "\n" +
            "class FormType\n" +
            "{\n" +
            "    protected $foo = 'DateTime';\n" +
            "    public function buildForm(\\Symfony\\Component\\Form\\FormBuilderInterface $builder, array $options) {\n" +
            "        $builder->add('" + s + "<caret>');\n" +
            "    }\n" +
            "    public function setDefaultOptions(OptionsResolverInterface $resolver)\n" +
            "    {\n" +
            "        $resolver->setDefaults(array(\n" +
            "            'data_class' => \\Form\\DataClass\\Model::class,\n" +
            "        ));\n" +
            "    }\n" +
            "}", PlatformPatterns.psiElement(Field.class)
        );
    }
}
 
Example #7
Source File: TwigTypeResolveUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 *
 * "phpNamedElement.variableName", "phpNamedElement.getVariableName" will resolve php type eg method
 *
 * @param phpNamedElement php class method or field
 * @param variableName variable name shortcut property possible
 * @return matched php types
 */
public static Collection<? extends PhpNamedElement> getTwigPhpNameTargets(PhpNamedElement phpNamedElement, String variableName) {

    Collection<PhpNamedElement> targets = new ArrayList<>();
    if(phpNamedElement instanceof PhpClass) {

        for(Method method: ((PhpClass) phpNamedElement).getMethods()) {
            String methodName = method.getName();
            if(method.getModifier().isPublic() && (methodName.equalsIgnoreCase(variableName) || isPropertyShortcutMethodEqual(methodName, variableName))) {
                targets.add(method);
            }
        }

        for(Field field: ((PhpClass) phpNamedElement).getFields()) {
            String fieldName = field.getName();
            if(field.getModifier().isPublic() && fieldName.equalsIgnoreCase(variableName)) {
                targets.add(field);
            }
        }

    }

    return targets;
}
 
Example #8
Source File: ConstraintPropertyReference.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Object[] getVariants() {

    List<LookupElement> lookupElements = new ArrayList<>();

    for(Field field: constraintPhpClass.getFields()) {
        if(!field.isConstant() && field.getModifier().isPublic()) {

            LookupElementBuilder lookupElement = LookupElementBuilder.create(field.getName()).withIcon(Symfony2Icons.SYMFONY);

            String defaultValue = PhpElementsUtil.getStringValue(field.getDefaultValue());
            if(defaultValue != null) {
                lookupElement = lookupElement.withTypeText(defaultValue, true);
            }

            lookupElements.add(lookupElement);
        }
    }

    return lookupElements.toArray();
}
 
Example #9
Source File: ConstraintPropertyReference.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {

    List<PsiElement> psiElements = new ArrayList<>();

    String content = ((StringLiteralExpression) getElement()).getContents();
    for(Field field: constraintPhpClass.getFields()) {
        String name = field.getName();
        if(!field.isConstant() && field.getModifier().isPublic() && content.equals(name)) {
            psiElements.add(field);
        }
    }

    return PsiElementResolveResult.createResults(psiElements);
}
 
Example #10
Source File: DoctrineTypeGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Collection<LookupElement> getLookupElements() {
    String modelNameInScope = DoctrineMetadataUtil.findModelNameInScope(getElement());
    if(modelNameInScope == null) {
        return Collections.emptyList();
    }

    Set<String> unique = new HashSet<>();

    Collection<LookupElement> lookupElements = new ArrayList<>();
    for (PhpClass phpClass : PhpElementsUtil.getClassesInterface(getProject(), modelNameInScope)) {
        for (Field field : phpClass.getFields()) {
            if(field.isConstant() || unique.contains(field.getName())) {
                continue;
            }

            String name = field.getName();
            unique.add(name);
            lookupElements.add(LookupElementBuilder.create(name).withIcon(field.getIcon()).withTypeText(phpClass.getPresentableFQN(), true));
        }
    }

    return lookupElements;
}
 
Example #11
Source File: LattePhpStaticVariableReference.java    From intellij-latte with MIT License 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {
    if (phpClasses.size() == 0) {
        return new ResolveResult[0];
    }

    final Collection<LattePhpStaticVariable> methods = LatteUtil.findStaticVariables(getElement().getProject(), variableName, phpClasses);
    List<ResolveResult> results = new ArrayList<ResolveResult>();
    for (BaseLattePhpElement method : methods) {
        results.add(new PsiElementResolveResult(method));
    }

    List<Field> fields = LattePhpUtil.getFieldsForPhpElement((BaseLattePhpElement) getElement());
    String name = ((BaseLattePhpElement) getElement()).getPhpElementName();
    for (Field field : fields) {
        if (field.getName().equals(name)) {
            results.add(new PsiElementResolveResult(field));
        }
    }

    return results.toArray(new ResolveResult[results.size()]);
}
 
Example #12
Source File: LattePhpPropertyReference.java    From intellij-latte with MIT License 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {
    if (phpClasses.size() == 0) {
        return new ResolveResult[0];
    }

    final Collection<LattePhpProperty> methods = LatteUtil.findProperties(getElement().getProject(), key, phpClasses);
    List<ResolveResult> results = new ArrayList<ResolveResult>();
    for (BaseLattePhpElement method : methods) {
        results.add(new PsiElementResolveResult(method));
    }

    List<Field> fields = LattePhpUtil.getFieldsForPhpElement((BaseLattePhpElement) getElement());
    String name = ((BaseLattePhpElement) getElement()).getPhpElementName();
    for (Field field : fields) {
        if (field.getName().equals(name)) {
            results.add(new PsiElementResolveResult(field));
        }
    }

    return results.toArray(new ResolveResult[results.size()]);
}
 
Example #13
Source File: LattePhpConstantReference.java    From intellij-latte with MIT License 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {
    if (phpClasses.size() == 0) {
        return new ResolveResult[0];
    }

    final Collection<LattePhpConstant> methods = LatteUtil.findConstants(getElement().getProject(), key, phpClasses);
    List<ResolveResult> results = new ArrayList<ResolveResult>();
    for (BaseLattePhpElement method : methods) {
        results.add(new PsiElementResolveResult(method));
    }

    List<Field> fields = LattePhpUtil.getFieldsForPhpElement((BaseLattePhpElement) getElement());
    String name = ((BaseLattePhpElement) getElement()).getPhpElementName();
    for (Field field : fields) {
        if (field.getName().equals(name)) {
            results.add(new PsiElementResolveResult(field));
        }
    }

    return results.toArray(new ResolveResult[results.size()]);
}
 
Example #14
Source File: LattePsiImplUtil.java    From intellij-latte with MIT License 6 votes vote down vote up
public static @NotNull LattePhpType getReturnType(@NotNull BaseLattePhpElement element) {
	Collection<PhpClass> phpClasses = element.getPhpType().getPhpClasses(element.getProject());
	if (phpClasses.size() == 0) {
		return LattePhpType.MIXED;
	}

	List<PhpType> types = new ArrayList<>();
	for (PhpClass phpClass : phpClasses) {
		for (Field field : phpClass.getFields()) {
			if (field.getName().equals(LattePhpUtil.normalizePhpVariable(element.getPhpElementName()))) {
				types.add(field.getType());
			}
		}
	}
	return types.size() > 0 ? LattePhpType.create(types).withDepth(element.getPhpArrayLevel()) : LattePhpType.MIXED;
}
 
Example #15
Source File: FluidTypeResolver.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
/**
 * "phpNamedElement.variableName", "phpNamedElement.getVariableName" will resolve php type eg method
 *
 * @param phpNamedElement php class method or field
 * @param variableName    variable name shortcut property possible
 * @return matched php types
 */
public static Collection<? extends PhpNamedElement> getFluidPhpNameTargets(PhpNamedElement phpNamedElement, String variableName) {

    Collection<PhpNamedElement> targets = new ArrayList<>();
    if (phpNamedElement instanceof PhpClass) {

        for (Method method : ((PhpClass) phpNamedElement).getMethods()) {
            String methodName = method.getName();
            if (method.getModifier().isPublic() && (methodName.equalsIgnoreCase(variableName) || isPropertyShortcutMethodEqual(methodName, variableName))) {
                targets.add(method);
            }
        }

        for (Field field : ((PhpClass) phpNamedElement).getFields()) {
            String fieldName = field.getName();
            if (field.getModifier().isPublic() && fieldName.equalsIgnoreCase(variableName)) {
                targets.add(field);
            }
        }

    }

    return targets;
}
 
Example #16
Source File: LattePhpVariableUtil.java    From intellij-latte with MIT License 6 votes vote down vote up
public static List<Field> findPhpFiledListFromTemplateTypeTag(@NotNull PsiElement element, @NotNull String variableName) {
    if (!(element.getContainingFile() instanceof LatteFile)) {
        return Collections.emptyList();
    }

    LattePhpType templateType = LatteUtil.findFirstLatteTemplateType(element.getContainingFile());
    if (templateType == null) {
        return Collections.emptyList();
    }

    Collection<PhpClass> classes = templateType.getPhpClasses(element.getProject());
    if (classes == null) {
        return Collections.emptyList();
    }

    List<Field> out = new ArrayList<>();
    for (PhpClass phpClass : classes) {
        for (Field field : phpClass.getFields()) {
            if (!field.isConstant() && field.getModifier().isPublic() && variableName.equals(field.getName())) {
                out.add(field);
            }
        }
    }
    return out;
}
 
Example #17
Source File: LatteVariableCompletionProvider.java    From intellij-latte with MIT License 6 votes vote down vote up
private void attachTemplateTypeCompletions(@NotNull CompletionResultSet result, @NotNull Project project, @NotNull LatteFile file) {
	LattePhpType type = LatteUtil.findFirstLatteTemplateType(file);
	if (type == null) {
		return;
	}

	Collection<PhpClass> phpClasses = type.getPhpClasses(project);
	if (phpClasses != null) {
		for (PhpClass phpClass : phpClasses) {
			for (Field field : phpClass.getFields()) {
				if (!field.isConstant() && field.getModifier().isPublic()) {
					LookupElementBuilder builder = LookupElementBuilder.create(field, "$" + field.getName());
					builder = builder.withInsertHandler(PhpVariableInsertHandler.getInstance());
					builder = builder.withTypeText(LattePhpType.create(field.getType()).toString());
					builder = builder.withIcon(PhpIcons.VARIABLE);
					if (field.isDeprecated() || field.isInternal()) {
						builder = builder.withStrikeoutness(true);
					}
					result.addElement(builder);
				}
			}
		}
	}
}
 
Example #18
Source File: ThemeUtil.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
public static PsiElementPattern.Capture<PsiElement> getThemeExtendsPattern() {
    return PlatformPatterns.psiElement().withParent(
        PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
            PlatformPatterns.psiElement(Field.class).withName("extend")
        )
    );
}
 
Example #19
Source File: DoctrineOrmFieldIntention.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
    if(!DoctrineUtil.isDoctrineOrmInVendor(project)) {
        return false;
    }

    Field context = getFieldContext(element);
    return context != null && !DoctrineUtil.isOrmColumnProperty(context);
}
 
Example #20
Source File: DoctrinePropertyOrmAnnotationGenerateAction.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
protected PhpAccessorMethodData[] createAccessors(PhpClass phpClass, PsiElement field)
{
    if(field instanceof Field) {
        DoctrineUtil.importOrmUseAliasIfNotExists((Field) field);
        PhpDocUtil.addPropertyOrmDocs((Field) field, this.editor.getDocument(), file);
    }

    return new PhpAccessorMethodData[0];
}
 
Example #21
Source File: XmlReferenceContributorTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void testThatArgumentConstantProvidesReferences() {
    // skip for 2019.x build
    // reference XmlText:null was created for XmlToken:XML_DATA_CHARACTERS but target XmlText, provider
    if(true) {
        return;
    }

    assertReferenceMatch(XmlFileType.INSTANCE, "" +
            "<?xml version=\"1.0\"?>\n" +
            "<container>\n" +
            "    <services>\n" +
            "        <service>\n" +
            "            <argument type=\"constant\">Foo\\Bar::FO<caret>O</argument>\n" +
            "        </service>\n" +
            "    </services>\n" +
            "</container>\n",
        PlatformPatterns.psiElement(Field.class).withName("FOO")
    );

    assertReferenceMatch(XmlFileType.INSTANCE, "" +
            "<?xml version=\"1.0\"?>\n" +
            "<container>\n" +
            "    <services>\n" +
            "        <service>\n" +
            "            <argument type=\"constant\">CONS<caret>T_FOO</argument>\n" +
            "        </service>\n" +
            "    </services>\n" +
            "</container>\n",
        PlatformPatterns.psiElement()
    );
}
 
Example #22
Source File: TwigTemplateGoToDeclarationHandlerTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void testThatConstantProvidesNavigation() {
    assertNavigationMatch(TwigFileType.INSTANCE, "{{ constant('\\Foo\\ConstantBar\\Foo::F<caret>OO') }}", PlatformPatterns.psiElement(Field.class).withName("FOO"));
    assertNavigationMatch(TwigFileType.INSTANCE, "{{ constant('\\\\Foo\\\\ConstantBar\\\\Foo::F<caret>OO') }}", PlatformPatterns.psiElement(Field.class).withName("FOO"));

    assertNavigationMatch(TwigFileType.INSTANCE, "{% if foo == constant('\\Foo\\ConstantBar\\Foo::F<caret>OO') %}", PlatformPatterns.psiElement(Field.class).withName("FOO"));
    assertNavigationMatch(TwigFileType.INSTANCE, "{% set foo == constant('\\Foo\\ConstantBar\\Foo::F<caret>OO') %}", PlatformPatterns.psiElement(Field.class).withName("FOO"));

    assertNavigationMatch(TwigFileType.INSTANCE, "{{ constant('CONST<caret>_FOO') }}", PlatformPatterns.psiElement());
}
 
Example #23
Source File: LaravelControllerNamespaceCutter.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
@NotNull
private Collection<String> getDefaultNamespaces(@NotNull Project project) {

    Collection<String> result = new HashSet<>();

    String controllerNamespace = LaravelSettings.getInstance(project).routerNamespace;
    if(controllerNamespace != null && StringUtils.isNotBlank(controllerNamespace)) {
        result.add(StringUtils.stripStart(controllerNamespace, "\\") + "\\");
        return result;
    }

    for(PhpClass providerPhpClass: PhpIndex.getInstance(project).getAllSubclasses("\\Illuminate\\Foundation\\Support\\Providers\\RouteServiceProvider")) {

        Field namespace = providerPhpClass.findOwnFieldByName("namespace", false);
        if(namespace == null) {
            continue;
        }

        PsiElement defaultValue = namespace.getDefaultValue();
        if(defaultValue == null) {
            continue;
        }

        String stringValue = PhpElementsUtil.getStringValue(defaultValue);
        if(stringValue != null) {
            result.add(StringUtils.stripStart(stringValue, "\\") + "\\");
        }
    }

    if(result.isEmpty()) {
        result.add("App\\Http\\Controllers\\");
    }

    return result;
}
 
Example #24
Source File: SymfonyUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
public static Set<String> getVersions(@NotNull Project project) {
    Set<String> versions = new HashSet<>();

    for (PhpClass phpClass : PhpElementsUtil.getClassesInterface(project, "Symfony\\Component\\HttpKernel\\Kernel")) {
        Field versionField = phpClass.findFieldByName("VERSION", true);
        if(versionField == null) {
            continue;
        }

        PsiElement defaultValue = versionField.getDefaultValue();
        if(!(defaultValue instanceof StringLiteralExpression)) {
            continue;
        }

        String contents = ((StringLiteralExpression) defaultValue).getContents();
        if(isBlank(contents)) {
            continue;
        }

        // 3.2.0-DEV, 3.2.0-RC1
        contents = contents.toLowerCase().replaceAll("(.*)-([\\w]+)$", "$1");
        versions.add(contents);
    }

    return versions;
}
 
Example #25
Source File: PhpConstGotoCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void addAllClassConstants(Collection<LookupElement> elements, Collection<PhpClass> classes) {
    for (PhpClass phpClass : classes) {
        // All class constants
        List<Field> fields = Arrays.stream(phpClass.getOwnFields()).filter(Field::isConstant).collect(Collectors.toList());
        for (PhpNamedElement field : fields) {
            // Foo::BAR
            String lookupString = phpClass.getName() + SCOPE_OPERATOR + field.getName();
            elements.add(wrapClassConstInsertHandler(new MyPhpLookupElement(field, lookupString)));
        }
    }
}
 
Example #26
Source File: ThemeUtil.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
public static void collectThemeJsFieldReferences(@NotNull StringLiteralExpression element, @NotNull ThemeAssetVisitor visitor) {

        PsiElement arrayValue = element.getParent();
        if(arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) {
            return;
        }

        PsiElement arrayCreation = arrayValue.getParent();
        if(!(arrayCreation instanceof ArrayCreationExpression)) {
            return;
        }

        PsiElement classField = arrayCreation.getParent();
        if(!(classField instanceof Field)) {
            return;
        }

        if(!"javascript".equals(((Field) classField).getName())) {
            return;
        }


        PhpClass phpClass = PsiTreeUtil.getParentOfType(classField, PhpClass.class);
        if(phpClass == null || !PhpElementsUtil.isInstanceOf(phpClass, "\\Shopware\\Components\\Theme")) {
            return;
        }

        visitThemeAssetsFile(phpClass, visitor);
    }
 
Example #27
Source File: TwigTemplateCompletionContributor.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext paramProcessingContext, @NotNull CompletionResultSet resultSet) {
    PsiElement psiElement = parameters.getOriginalPosition();
    if(psiElement == null || !Symfony2ProjectComponent.isEnabled(psiElement)) {
        return;
    }

    Collection<String> possibleTypes = TwigTypeResolveUtil.formatPsiTypeName(psiElement);

    // find core function for that
    for(TwigTypeContainer twigTypeContainer: TwigTypeResolveUtil.resolveTwigMethodName(psiElement, possibleTypes)) {
        if(twigTypeContainer.getPhpNamedElement() instanceof PhpClass) {

            for(Method method: ((PhpClass) twigTypeContainer.getPhpNamedElement()).getMethods()) {
                if(!(!method.getModifier().isPublic() || method.getName().startsWith("set") || method.getName().startsWith("__"))) {
                    resultSet.addElement(new PhpTwigMethodLookupElement(method));
                }
            }

            for(Field field: ((PhpClass) twigTypeContainer.getPhpNamedElement()).getFields()) {
                if(field.getModifier().isPublic()) {
                    resultSet.addElement(new PhpTwigMethodLookupElement(field));
                }
            }
        }

        if(twigTypeContainer.getStringElement() != null) {
            resultSet.addElement(LookupElementBuilder.create(twigTypeContainer.getStringElement()));
        }
    }
}
 
Example #28
Source File: TwigTemplateGoToDeclarationHandler.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
private Collection<PsiElement> getConstantGoto(@NotNull PsiElement psiElement) {
    Collection<PsiElement> targetPsiElements = new ArrayList<>();

    String contents = psiElement.getText();
    if(StringUtils.isBlank(contents)) {
        return targetPsiElements;
    }

    // global constant
    if(!contents.contains(":")) {
        targetPsiElements.addAll(PhpIndex.getInstance(psiElement.getProject()).getConstantsByName(contents));
        return targetPsiElements;
    }

    // resolve class constants
    String[] parts = contents.split("::");
    if(parts.length != 2) {
        return targetPsiElements;
    }

    PhpClass phpClass = PhpElementsUtil.getClassInterface(psiElement.getProject(), parts[0].replace("\\\\", "\\"));
    if(phpClass == null) {
        return targetPsiElements;
    }

    Field field = phpClass.findFieldByName(parts[1], true);
    if(field != null) {
        targetPsiElements.add(field);
    }

    return targetPsiElements;
}
 
Example #29
Source File: DoctrineOrmFieldIntention.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement psiElement) throws IncorrectOperationException {
    Field context = getFieldContext(psiElement);
    if (context != null) {
        DoctrineUtil.importOrmUseAliasIfNotExists(context);
        PhpDocUtil.addPropertyOrmDocs(context, editor.getDocument(), psiElement.getContainingFile());
    }
}
 
Example #30
Source File: ThemeUtil.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@NotNull
public static PsiElementPattern.Capture<PsiElement> getJavascriptClassFieldPattern() {
    return PlatformPatterns.psiElement().withParent(
        PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
            PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE).withParent(
                PlatformPatterns.psiElement(ArrayCreationExpression.class).withParent(
                    PlatformPatterns.psiElement(Field.class).withName("javascript")
                )
            )
        )
    );

}