Java Code Examples for com.jetbrains.php.lang.psi.elements.Field#isConstant()
The following examples show how to use
com.jetbrains.php.lang.psi.elements.Field#isConstant() .
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: 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 4
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 5
Source File: ConstraintPropertyReference.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@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 6
Source File: ConstraintPropertyReference.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@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 7
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 8
Source File: DoctrinePhpClassFieldReference.java From idea-php-annotation-plugin with MIT License | 5 votes |
@NotNull @Override public Object[] getVariants() { List<LookupElement> lookupElements = new ArrayList<>(); for(Field field: this.phpClass.getFields()) { if(!field.isConstant()) { LookupElementBuilder lookupElement = LookupElementBuilder.createWithIcon(field); lookupElement = attachLookupInformation(field, lookupElement); lookupElements.add(lookupElement); } } return lookupElements.toArray(); }
Example 9
Source File: ExtbaseUtils.java From idea-php-typo3-plugin with MIT License | 4 votes |
public static boolean fieldHasMagicFinders(@NotNull Field field) { return !field.isConstant() && !field.isInternal() && !ExtbaseUtils.isNonQueryableField(field.getName()) && !ExtbaseUtils.isObjectStorage(field); }
Example 10
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; }
Example 11
Source File: AnnotationDocBlockConstantDeprecatedInspection.java From idea-php-annotation-plugin with MIT License | 4 votes |
private void visitAnnotationDocTag(@NotNull PhpDocTag phpDocTag, @NotNull ProblemsHolder holder, @NotNull AnnotationInspectionUtil.LazyNamespaceImportResolver lazyUseImporterCollector) { for (PsiElement element : PsiTreeUtil.collectElements(phpDocTag, psiElement -> psiElement.getNode().getElementType() == PhpDocTokenTypes.DOC_STATIC)) { PsiElement nextSibling = element.getNextSibling(); if (nextSibling == null || nextSibling.getNode().getElementType() != PhpDocTokenTypes.DOC_IDENTIFIER) { continue; } PsiElement prevSibling = element.getPrevSibling(); if (prevSibling == null) { return; } String namespaceForDocIdentifier = PhpDocUtil.getNamespaceForDocIdentifier(prevSibling); if (namespaceForDocIdentifier == null) { return; } String clazz = AnnotationInspectionUtil.getClassFqnString(namespaceForDocIdentifier, lazyUseImporterCollector); if (clazz == null) { return; } PhpClass phpClass = PhpElementsUtil.getClassInterface(phpDocTag.getProject(), clazz); if (phpClass == null) { return; } // ::class direct class access String text = nextSibling.getText(); if ("class".equals(text)) { if (phpClass.isDeprecated()) { holder.registerProblem( nextSibling, MESSAGE, ProblemHighlightType.LIKE_DEPRECATED ); } return; } // ::CONST fetch the field Field fieldByName = phpClass.findFieldByName(text, true); if (fieldByName != null && fieldByName.isConstant() && fieldByName.isDeprecated()) { holder.registerProblem( nextSibling, MESSAGE, ProblemHighlightType.LIKE_DEPRECATED ); } } }