Java Code Examples for com.jetbrains.php.lang.psi.elements.PhpClass#getFields()
The following examples show how to use
com.jetbrains.php.lang.psi.elements.PhpClass#getFields() .
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: LatteVariableCompletionProvider.java From intellij-latte with MIT License | 6 votes |
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 2
Source File: LattePhpVariableUtil.java From intellij-latte with MIT License | 6 votes |
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 3
Source File: LattePsiImplUtil.java From intellij-latte with MIT License | 6 votes |
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 4
Source File: DoctrineYamlAnnotationLookupBuilder.java From idea-php-symfony2-plugin with MIT License | 6 votes |
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 5
Source File: DoctrineTypeGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@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 6
Source File: LattePhpVariableReference.java From intellij-latte with MIT License | 5 votes |
@NotNull @Override public ResolveResult[] multiResolve(boolean incompleteCode) { if (getElement().getContainingFile().getVirtualFile() == null) { return new ResolveResult[0]; } List<ResolveResult> results = new ArrayList<ResolveResult>(); LattePhpType fields = LatteUtil.findFirstLatteTemplateType(getElement().getContainingFile()); String name = ((BaseLattePhpElement) getElement()).getPhpElementName(); if (fields != null) { for (PhpClass phpClass : fields.getPhpClasses(getElement().getProject())) { for (Field field : phpClass.getFields()) { if (!field.isConstant() && field.getName().equals(name)) { results.add(new PsiElementResolveResult(field)); } } } } //todo: complete resolving for variables //final List<PsiPositionedElement> variables = LatteUtil.findVariablesInFileBeforeElement(getElement(), getElement().getContainingFile().getVirtualFile(), variableName); final List<PsiPositionedElement> variables = LatteUtil.findVariablesInFile(getElement().getProject(), getElement().getContainingFile().getVirtualFile(), variableName); /*if (!(getElement() instanceof LattePhpVariable)) { return new ResolveResult[0]; } final List<PsiPositionedElement> variables; if (((LattePhpVariable) getElement()).isVarTypeDefinition()) { variables = LatteUtil.findVariablesInFileAfterElement(getElement(), getElement().getContainingFile().getVirtualFile(), variableName); } else { variables = LatteUtil.findVariablesInFileBeforeElement(getElement(), getElement().getContainingFile().getVirtualFile(), variableName); }*/ for (PsiPositionedElement variable : variables) { results.add(new PsiElementResolveResult(variable.getElement())); } return results.toArray(new ResolveResult[results.size()]); }
Example 7
Source File: DoctrinePhpMappingDriver.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@Override public DoctrineMetadataModel getMetadata(@NotNull DoctrineMappingDriverArguments args) { PsiFile psiFile = args.getPsiFile(); if(!(psiFile instanceof PhpFile)) { return null; } Collection<DoctrineModelField> fields = new ArrayList<>(); DoctrineMetadataModel model = new DoctrineMetadataModel(fields); for (PhpClass phpClass : PhpElementsUtil.getClassesInterface(args.getProject(), args.getClassName())) { // remove duplicate code // @TODO: fr.adrienbrault.idea.symfony2plugin.doctrine.EntityHelper.getModelFields() PhpDocComment docComment = phpClass.getDocComment(); if(docComment == null) { continue; } // Doctrine ORM // @TODO: external split if(AnnotationBackportUtil.hasReference(docComment, "\\Doctrine\\ORM\\Mapping\\Entity", "\\TYPO3\\Flow\\Annotations\\Entity")) { // @TODO: reuse annotations plugin PhpDocTag phpDocTag = AnnotationBackportUtil.getReference(docComment, "\\Doctrine\\ORM\\Mapping\\Table"); if(phpDocTag != null) { Matcher matcher = Pattern.compile("name[\\s]*=[\\s]*[\"|']([\\w_\\\\]+)[\"|']").matcher(phpDocTag.getText()); if (matcher.find()) { model.setTable(matcher.group(1)); } } Map<String, Map<String, String>> maps = new HashMap<>(); for(Field field: phpClass.getFields()) { if (field.isConstant()) { continue; } if (!AnnotationBackportUtil.hasReference(field.getDocComment(), EntityHelper.ANNOTATION_FIELDS)) { continue; } // context change is case of "trait" or extends PhpClass containingClass = field.getContainingClass(); if (containingClass == null) { continue; } // collect import context based on the class name String fqn = containingClass.getFQN(); if (!maps.containsKey(fqn)) { maps.put(fqn, AnnotationUtil.getUseImportMap(field.getDocComment())); } DoctrineModelField modelField = new DoctrineModelField(field.getName()); EntityHelper.attachAnnotationInformation(containingClass, field, modelField.addTarget(field), maps.get(fqn)); fields.add(modelField); } } } if(fields.size() == 0) { return null; } return model; }