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

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

        Collection<PhpClass> classFromPhpTypeSet = getClassFromPhpTypeSet(project, types);
        if (classFromPhpTypeSet.size() > 0) {
            return classFromPhpTypeSet.iterator().next().getPresentableFQN();
        }

        PhpType phpType = new PhpType();
        for (String type : types) {
            phpType.add(type);
        }
        PhpType phpTypeFormatted = PhpIndex.getInstance(project).completeType(project, phpType, new HashSet<>());

        if (phpTypeFormatted.getTypes().size() > 0) {
            return StringUtils.join(phpTypeFormatted.getTypes(), "|");
        }

        if (types.size() > 0) {
            return types.iterator().next();
        }

        return "";
    }
 
Example #2
Source File: ServiceBuilder.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void serviceTagCallback(String className, TagCallbackInterface callback) {

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

        List<ServiceTag> serviceTags = new ArrayList<>();
        for (String tag : ServiceUtil.getPhpClassServiceTags(phpClass)) {
            ServiceTag serviceTag = new ServiceTag(phpClass, tag);
            ServiceUtil.decorateServiceTag(serviceTag);
            serviceTags.add(serviceTag);
        }

        if(serviceTags.size() == 0) {
            return;
        }

        callback.onTags(serviceTags);
    }
 
Example #3
Source File: EventMethodCallInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public StringBuilder getStringBuilder(@NotNull ProblemDescriptor problemDescriptor, @NotNull PhpClass phpClass, @NotNull String functionName) {
    String taggedEventMethodParameter = getEventTypeHint(problemDescriptor, phpClass);

    String parameter = "";
    if(taggedEventMethodParameter != null) {
        parameter = taggedEventMethodParameter + " $event";
    }

    return new StringBuilder()
        .append("public function ")
        .append(functionName)
        .append("(")
        .append(parameter)
        .append(")\n {\n}\n\n");
}
 
Example #4
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
public boolean isInstanceOf(@NotNull PhpClass subjectClass, @NotNull PhpClass expectedClass) {

        // we have equal class instance, on non multiple classes with same name fallback to namespace and classname
        if (subjectClass == expectedClass || PhpElementsUtil.isEqualClassName(subjectClass, expectedClass)) {
            return true;
        }

        if (expectedClass.isInterface()) {
            return isImplementationOfInterface(subjectClass, expectedClass);
        }

        if (null == subjectClass.getSuperClass()) {
            return false;
        }

        return isInstanceOf(subjectClass.getSuperClass(), expectedClass);
    }
 
Example #5
Source File: PhpIndexAbstractProviderAbstract.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@NotNull
public Collection<LookupElement> getLookupElements(@NotNull PhpToolboxCompletionContributorParameter parameter) {
    PhpIndex instance = PhpIndex.getInstance(parameter.getProject());

    Collection<LookupElement> lookupElements = new ArrayList<>();
    for (String className : getClasses(parameter)) {
        // strip double backslash
        className = className.replaceAll("\\\\+", "\\\\");

        for (PhpClass phpClass : getPhpClassesForLookup(instance, className)) {
            lookupElements.add(
                LookupElementBuilder.create(phpClass.getPresentableFQN()).withIcon(phpClass.getIcon())
            );
        }
    }

    return lookupElements;
}
 
Example #6
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 #7
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
protected boolean isCallTo(Method e, Method[] expectedMethods) {

        PhpClass methodClass = e.getContainingClass();
        if(methodClass == null) {
            return false;
        }

        for (Method expectedMethod : expectedMethods) {

            // @TODO: its stuff from beginning times :)
            if(expectedMethod == null) {
                continue;
            }

            PhpClass containingClass = expectedMethod.getContainingClass();
            if (containingClass != null && expectedMethod.getName().equalsIgnoreCase(e.getName()) && isInstanceOf(methodClass, containingClass)) {
                return true;
            }
        }

        return false;
    }
 
Example #8
Source File: ServiceGenerateAction.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private boolean isValidForPhpClass(Editor editor, PsiFile file) {

        if(!(file instanceof PhpFile)) {
            return false;
        }

        int offset = editor.getCaretModel().getOffset();
        if(offset <= 0) {
            return false;
        }

        PsiElement psiElement = file.findElementAt(offset);
        if(psiElement == null) {
            return false;
        }

        return PlatformPatterns.psiElement().inside(PhpClass.class).accepts(psiElement);
    }
 
Example #9
Source File: LatteUtil.java    From intellij-latte with MIT License 6 votes vote down vote up
private static <T extends BaseLattePhpElement> void attachResults(@NotNull List<T> result, String key, List<PsiElement> elements, @Nullable Collection<PhpClass> phpClasses)
{
    for (PsiElement element : elements) {
        if (!(element instanceof BaseLattePhpElement)) {
            continue;
        }

        if ((phpClasses != null && phpClasses.size() > 0 && !((BaseLattePhpElement) element).getPhpType().hasClass(phpClasses))) {
            continue;
        }

        String varName = ((BaseLattePhpElement) element).getPhpElementName();
        if (key.equals(varName)) {
            result.add((T) element);
        }
    }
}
 
Example #10
Source File: XmlGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Collection<LookupElement> getLookupElements() {
    PsiElement parent = getElement().getParent();
    if(!(parent instanceof XmlAttributeValue)) {
        return Collections.emptyList();
    }

    Collection<PhpClass> phpClasses = new ArrayList<>();

    ContainerUtil.addIfNotNull(phpClasses, XmlHelper.getPhpClassForClassFactory((XmlAttributeValue) parent));
    ContainerUtil.addIfNotNull(phpClasses, XmlHelper.getPhpClassForServiceFactory((XmlAttributeValue) parent));

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

    for (PhpClass phpClass : phpClasses) {
        lookupElements.addAll(PhpElementsUtil.getClassPublicMethod(phpClass).stream()
            .map(PhpLookupElement::new)
            .collect(Collectors.toList())
        );
    }

    return lookupElements;
}
 
Example #11
Source File: AnnotationCompletionContributor.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement psiElement = parameters.getOriginalPosition();
    if(psiElement == null) {
        return;
    }

    PhpDocTag phpDocTag = PsiTreeUtil.getParentOfType(parameters.getOriginalPosition(), PhpDocTag.class);
    PhpClass phpClass = AnnotationUtil.getAnnotationReference(phpDocTag);
    if(phpClass == null) {
        return;
    }

    AnnotationPropertyParameter annotationPropertyParameter = new AnnotationPropertyParameter(parameters.getOriginalPosition(), phpClass, AnnotationPropertyParameter.Type.DEFAULT);
    providerWalker(parameters, context, result, annotationPropertyParameter);

}
 
Example #12
Source File: PhpClassReferenceInsertHandler.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) {
    Object object = lookupElement.getObject();

    if (!(object instanceof PhpClass)) {
        return;
    }

    StringBuilder textToInsertBuilder = new StringBuilder();
    PhpClass aClass = (PhpClass)object;
    String fqn = aClass.getNamespaceName();

    if(fqn.startsWith("\\")) {
        fqn = fqn.substring(1);
    }

    textToInsertBuilder.append(fqn);
    context.getDocument().insertString(context.getStartOffset(), textToInsertBuilder);

}
 
Example #13
Source File: YamlXmlServiceInstanceInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * class: FooClass
 * tags:
 *  - [ setFoo, [@args_bar] ]
 */
private void visitCall(PsiElement psiElement) {
    PsiElement yamlScalar = psiElement.getContext();
    if(!(yamlScalar instanceof YAMLScalar)) {
        return;
    }

    YamlHelper.visitServiceCallArgument((YAMLScalar) yamlScalar, visitor -> {
        PhpClass serviceClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), visitor.getClassName(), getLazyServiceCollector(psiElement.getProject()));
        if(serviceClass == null) {
            return;
        }

        Method method = serviceClass.findMethodByName(visitor.getMethod());
        if (method == null) {
            return;
        }

        YamlXmlServiceInstanceInspection.registerInstanceProblem(psiElement, holder, visitor.getParameterIndex(), method, getLazyServiceCollector(psiElement.getProject()));
    });
}
 
Example #14
Source File: Run.java    From phpstorm-plugin with MIT License 6 votes vote down vote up
protected void saveFiles(PhpClass currentTestClass, Project project) {
    FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();

    Document documentTestClass = fileDocumentManager.getDocument(currentTestClass.getContainingFile().getVirtualFile());
    if (documentTestClass != null) {
        fileDocumentManager.saveDocument(documentTestClass);
    }

    PhpClass currentTestedClass = Utils.locateTestedClass(project, currentTestClass);
    if (currentTestedClass != null) {
        Document documentTestedClass = fileDocumentManager.getDocument(currentTestedClass.getContainingFile().getVirtualFile());
        if (documentTestedClass != null) {
            fileDocumentManager.saveDocument(documentTestedClass);
        }
    }
}
 
Example #15
Source File: PhpEntityClassCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {

        if(!Symfony2ProjectComponent.isEnabled(parameters.getPosition())) {
            return;
        }

        PhpIndex phpIndex = PhpIndex.getInstance(parameters.getOriginalFile().getProject());
        Map<String, String> entityNamespaces = ServiceXmlParserFactory.getInstance(parameters.getOriginalFile().getProject(), EntityNamesServiceParser.class).getEntityNameMap();

        // copied from PhpCompletionUtil::addClassesInNamespace looks the official way to find classes in namespaces
        // its a really performance nightmare

        Collection<String> names = phpIndex.getAllClassNames(new CamelHumpMatcher(resultSet.getPrefixMatcher().getPrefix()));
        for (String name : names) {
            Collection<PhpClass> classes = phpIndex.getClassesByName(name);

            for(Map.Entry<String, String> entry: entityNamespaces.entrySet()) {
                String namespaceFqn = PhpLangUtil.toFQN(entry.getValue());
                Collection<PhpClass> filtered = PhpCompletionUtil.filterByNamespace(classes, namespaceFqn);
                for (PhpClass phpClass : filtered) {
                    resultSet.addElement(new PhpClassLookupElement(phpClass, true, PhpClassReferenceInsertHandler.getInstance()));
                }
            }
        }
    }
 
Example #16
Source File: PsiPhpHelper.java    From yiistorm with MIT License 6 votes vote down vote up
public static boolean isExtendsSuperclass(PsiElement child, String superclass) {
    if (child == null) {
        return false;
    }

    try {
        PhpClass[] supers = ((PhpClass) child).getSupers();
        String className = ((PhpClass) child).getName().toLowerCase();
        if (className.equals(superclass.toLowerCase())) {
            return true;
        }
        for (PhpClass cl : supers) {
            if (cl.getName().toLowerCase().equals(superclass.toLowerCase())) {
                return true;
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}
 
Example #17
Source File: ServiceLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Constraints in same namespace and validateBy service name
 */
private void validatorClassMarker(PsiElement psiElement, Collection<LineMarkerInfo> results) {
    PsiElement phpClassContext = psiElement.getContext();
    if(!(phpClassContext instanceof PhpClass) || !PhpElementsUtil.isInstanceOf((PhpClass) phpClassContext, "\\Symfony\\Component\\Validator\\Constraint")) {
        return;
    }

    // class in same namespace
    String className = ((PhpClass) phpClassContext).getFQN() + "Validator";
    Collection<PhpClass> phpClasses = new ArrayList<>(PhpElementsUtil.getClassesInterface(psiElement.getProject(), className));

    // @TODO: validateBy alias

    if(phpClasses.size() == 0) {
        return;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.SYMFONY_LINE_MARKER).
        setTargets(phpClasses).
        setTooltipText("Navigate to validator");

    results.add(builder.createLineMarkerInfo(psiElement));
}
 
Example #18
Source File: ControllerReferencesTest.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
public void testRouteGroups() {
    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n" +
            "Route::group(['namespace' => 'Group'], function() {\n" +
            "    Route::get('/', '<caret>');\n" +
            "});",
        "GroupController@foo"
    );

    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n" +
            "Route::group(['namespace' => 'Group'], function() {\n" +
            "    Route::get('/', 'GroupController@foo<caret>');\n" +
            "});",
        PlatformPatterns.psiElement(Method.class).withParent(
            PlatformPatterns.psiElement(PhpClass.class).withName("GroupController")
        )
    );
}
 
Example #19
Source File: InitResourceServiceIndex.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private void visitPhpReturn(@NotNull PhpReturn phpReturn) {
    PhpClass phpClass = method.getContainingClass();
    if (phpClass == null) {
        return;
    }

    HookSubscriberUtil.visitSubscriberEvents(phpReturn, (event, methodName, key) -> {
        SubscriberInfo subscriberInfo = SubscriberIndexUtil.getSubscriberInfo(event);
        if(subscriberInfo == null) {
            return;
        }

        ServiceResource serviceResource = new ServiceResource(event, subscriberInfo.getEvent().getText(), subscriberInfo.getService())
            .setSignature(StringUtils.strip(phpClass.getFQN(), "\\") + '.' + methodName);

        String resourceKey = subscriberInfo.getEvent().getText();
        if(!serviceMap.containsKey(resourceKey)) {
            serviceMap.put(resourceKey, new ArrayList<>());
        }

        serviceMap.get(resourceKey).add(serviceResource);
    });
}
 
Example #20
Source File: YamlGoToDeclarationHandler.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
private Collection<PsiElement> getTagMethodGoto(@NotNull PsiElement psiElement) {
    String methodName = PsiElementUtils.trimQuote(psiElement.getText());
    if(StringUtils.isBlank(methodName)) {
        return Collections.emptyList();
    }

    String classValue = YamlHelper.getServiceDefinitionClassFromTagMethod(psiElement);
    if(classValue == null) {
        return Collections.emptyList();
    }

    PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), classValue);
    if(phpClass == null) {
        return Collections.emptyList();
    }

    Method method = phpClass.findMethodByName(methodName);
    if(method != null) {
        return Collections.singletonList(method);
    }

    return Collections.emptyList();
}
 
Example #21
Source File: EventMethodCallInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
private String getEventTypeHint(@NotNull ProblemDescriptor problemDescriptor, @NotNull PhpClass phpClass) {
    String eventName = EventDispatcherSubscriberUtil.getEventNameFromScope(problemDescriptor.getPsiElement());
    if (eventName == null) {
        return null;
    }

    String taggedEventMethodParameter = EventSubscriberUtil.getTaggedEventMethodParameter(problemDescriptor.getPsiElement().getProject(), eventName);
    if (taggedEventMethodParameter == null) {
        return null;
    }

    String qualifiedName = AnnotationBackportUtil.getQualifiedName(phpClass, taggedEventMethodParameter);
    if (qualifiedName != null && !qualifiedName.equals(StringUtils.stripStart(taggedEventMethodParameter, "\\"))) {
        // class already imported
        return qualifiedName;
    }

    return PhpElementsUtil.insertUseIfNecessary(phpClass, taggedEventMethodParameter);
}
 
Example #22
Source File: ExtJsTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private void attachController(Project project, String[] namespaces, List<PsiElement> targets) {

        if(namespaces.length < 4) {
            return;
        }

        // only show on some context
        if(!Arrays.asList("controller", "store", "model", "view").contains(namespaces[3])) {
            return;
        }

        String controller = namespaces[2];

        // build class name
        String className = String.format("\\Shopware_Controllers_%s_%s", "Backend", controller);
        PhpClass phpClass = PhpElementsUtil.getClassInterface(project, className);
        if(phpClass != null) {
            targets.add(phpClass);
        }

    }
 
Example #23
Source File: LattePsiImplUtil.java    From intellij-latte with MIT License 6 votes vote down vote up
public static @NotNull LattePhpType getReturnType(@NotNull LattePhpMethod element) {
	LattePhpType type = element.getPhpType();
	Collection<PhpClass> phpClasses = type.getPhpClasses(element.getProject());
	String name = element.getMethodName();
	if (phpClasses.size() == 0) {
		LatteFunctionSettings customFunction = LatteConfiguration.getInstance(element.getProject()).getFunction(name);
		return customFunction == null ? LattePhpType.MIXED : LattePhpType.create(customFunction.getFunctionReturnType());
	}

	List<PhpType> types = new ArrayList<>();
	for (PhpClass phpClass : phpClasses) {
		for (Method phpMethod : phpClass.getMethods()) {
			if (phpMethod.getName().equals(name)) {
				types.add(phpMethod.getType());
			}
		}
	}
	return types.size() > 0 ? LattePhpType.create(types).withDepth(element.getPhpArrayLevel()) : LattePhpType.MIXED;
}
 
Example #24
Source File: GeneralUtilityServiceTypeProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Override
public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) {

    Collection<PhpNamedElement> phpNamedElementCollections = new ArrayList<>();
    PhpIndex phpIndex = PhpIndex.getInstance(project);
    CoreServiceParser serviceParser = new CoreServiceParser();
    serviceParser.collect(project);

    List<TYPO3ServiceDefinition> resolvedServices = serviceParser.resolve(project, expression);
    if (resolvedServices == null || resolvedServices.isEmpty()) {
        return phpNamedElementCollections;
    }

    resolvedServices.forEach(serviceDefinition -> {
        Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN(serviceDefinition.getClassName());
        phpNamedElementCollections.addAll(classesByFQN);
    });

    return phpNamedElementCollections;
}
 
Example #25
Source File: Run.java    From phpstorm-plugin with MIT License 6 votes vote down vote up
@Override
public void update(AnActionEvent event) {
    event.getPresentation().setEnabled(false);
    event.getPresentation().setVisible(true);
    event.getPresentation().setText("atoum - run test");

    PhpClass currentTestClass = getCurrentTestClass(event);
    if (currentTestClass != null) {
        event.getPresentation().setEnabled(true);
        Method currentTestMethod = getCurrentTestMethod(event);
        if (currentTestMethod != null) {
            event.getPresentation().setText("atoum - run " + currentTestClass.getName() + "::" + currentTestMethod.getName(), false);
        } else {
            event.getPresentation().setText("atoum - run test : " + currentTestClass.getName(), false);
        }
    } else {
        VirtualFile selectedDir = getCurrentTestDirectory(event);
        if (selectedDir != null) {
            event.getPresentation().setText("atoum - run dir : " + selectedDir.getName(), false);
            event.getPresentation().setEnabled(true);
        }
    }
}
 
Example #26
Source File: ClassLineMarkerProvider.java    From phpstorm-plugin with MIT License 6 votes vote down vote up
private void classNameMarker(PhpClass currentClass, Collection<? super RelatedItemLineMarkerInfo> result, Project project) {
    Collection<PhpClass> target;
    String tooltip;

    if (Utils.isClassAtoumTest(currentClass)) {
        target = Utils.locateTestedClasses(project, currentClass);
        tooltip = "Navigate to tested class";
    } else {
        target = Utils.locateTestClasses(project, currentClass);
        tooltip = "Navigate to test";
    }

    if (target.size() == 0) {
        return;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Icons.ATOUM).
            setTargets(target).
            setTooltipText(tooltip);
    result.add(builder.createLineMarkerInfo(currentClass));
}
 
Example #27
Source File: DoctrineRepositoryReference.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {

    PhpClass phpClass = PhpElementsUtil.getClassInsideAnnotation((StringLiteralExpression) getElement(), content);
    if(phpClass == null) {
        return new ResolveResult[0];
    }

    return new ResolveResult[] {
        new PsiElementResolveResult(phpClass)
    };
}
 
Example #28
Source File: FormUtilTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void testGetFormExtendedType() {
    PhpClass phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
        "class Foobar\n" +
        "{\n" +
        "   public function getExtendedType()\n" +
        "   {\n" +
        "       return true ? 'foobar' : Foobar::class;" +
        "   }\n" +
        "}\n"
    );

    assertContainsElements(FormUtil.getFormExtendedType(phpClass), "foobar", "Foobar");

    phpClass = PhpPsiElementFactory.createFromText(getProject(), PhpClass.class, "<?php\n" +
        "namespace Car {\n" +
        "   class Foo {}\n" +
        "}" +
        "" +
        "namespace Bar {\n" +
        "   use Car\n" +
        "   \n" +
        "   class Foobar\n" +
        "   {\n" +
        "       public function getExtendedType()\n" +
        "       {\n" +
        "           return Foo::class;" +
        "      }\n" +
        "   }\n" +
        "}"
    );

    assertContainsElements(FormUtil.getFormExtendedType(phpClass), "Bar\\Foo");
}
 
Example #29
Source File: FluidTypeContainer.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public static Collection<FluidTypeContainer> fromCollection(Project project, Collection<FluidVariable> fluidVariables) {

        List<FluidTypeContainer> fluidTypeContainerList = new ArrayList<>();
        for (FluidVariable variable : fluidVariables) {
            Collection<PhpClass> phpClass = getClassFromPhpTypeSet(project, variable.getTypes());
            if (phpClass.size() > 0) {
                fluidTypeContainerList.add(new FluidTypeContainer(phpClass.iterator().next()));
            }
        }

        return fluidTypeContainerList;
    }
 
Example #30
Source File: AnnotationCompletionContributor.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement psiElement = parameters.getOriginalPosition();
    if(psiElement == null) {
        return;
    }

    PhpClass phpClass = AnnotationUtil.getClassFromConstant(psiElement);
    if(phpClass != null) {
        phpClass.getFields().stream().filter(Field::isConstant).forEach(field ->
            result.addElement(LookupElementBuilder.create(field.getName()).withIcon(PhpIcons.FIELD).withTypeText(phpClass.getName(), true))
        );
    }
}