类com.intellij.psi.PsiRecursiveElementWalkingVisitor源码实例Demo

下面列出了怎么用com.intellij.psi.PsiRecursiveElementWalkingVisitor的API类实例代码及写法,或者点击链接到github查看源代码。

@Nullable
public static <T extends PsiElement> T createFromText(@NotNull Project p, final Class<T> aClass, String text) {
    final PsiElement[] ret = new PsiElement[]{null};

    createDummyFile(p, text).accept(new PsiRecursiveElementWalkingVisitor() {
        public void visitElement(PsiElement element) {
            if(ret[0] == null && aClass.isInstance(element)) {
                ret[0] = element;
            }

            super.visitElement(element);
        }
    });

    return (T) ret[0];
}
 
@Nullable
public static <T extends PsiElement> T createFromText(@NotNull Project p, @NotNull final IElementType elementType, @NotNull String text) {
    final PsiElement[] ret = new PsiElement[]{null};

    createDummyFile(p, text).accept(new PsiRecursiveElementWalkingVisitor() {
        public void visitElement(PsiElement element) {
            if(ret[0] == null && element.getNode().getElementType() == elementType) {
                ret[0] = element;
            }

            super.visitElement(element);
        }
    });

    return (T) ret[0];
}
 
public static List<PsiElement> getBlockPsiElement(PsiFile psiFile, final String blockName) {
    final List<PsiElement> psiElements = new ArrayList<>();

    psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitElement(PsiElement element) {

            if(SmartyPattern.getBlockPattern().accepts(element)) {
                String text = element.getText();
                if(blockName.equalsIgnoreCase(text)) {
                    psiElements.add(element);
                }

            }

            super.visitElement(element);
        }
    });

    return psiElements;
}
 
private static List<PsiElement> getIncludePsiElement(PsiFile psiFile, final String templateName) {
    final List<PsiElement> psiElements = new ArrayList<>();

    psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitElement(PsiElement element) {

            if(SmartyPattern.getFileIncludePattern().accepts(element)) {
                String text = element.getText();
                if(templateName.equalsIgnoreCase(text)) {
                    psiElements.add(element);
                }

            }

            super.visitElement(element);
        }
    });

    return psiElements;
}
 
源代码5 项目: consulo-unity3d   文件: Unity3dAssetUtil.java
@Nullable
@RequiredReadAction
public static CSharpTypeDeclaration findPrimaryType(@Nonnull PsiFile file)
{
	Ref<CSharpTypeDeclaration> typeRef = Ref.create();
	file.accept(new PsiRecursiveElementWalkingVisitor()
	{
		@Override
		public void visitElement(PsiElement element)
		{
			if(element instanceof CSharpTypeDeclaration)
			{
				typeRef.set((CSharpTypeDeclaration) element);
				stopWalking();
			}
			super.visitElement(element);
		}
	});
	return typeRef.get();
}
 
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof LatteFile)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();
	file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof LatteMacroTag) {
				checkClassicMacro((LatteMacroTag) element, problems, manager, isOnTheFly);

			} else {
				super.visitElement(element);
			}
		}
	});
	return problems.toArray(new ProblemDescriptor[0]);
}
 
@Nullable
public static <T extends PsiElement> T createFromText(@NotNull Project p, final Class<T> aClass, String text) {
    final PsiElement[] ret = new PsiElement[]{null};

    createDummyFile(p, text).accept(new PsiRecursiveElementWalkingVisitor() {
        public void visitElement(PsiElement element) {
            if(ret[0] == null && aClass.isInstance(element)) {
                ret[0] = element;
            }

            super.visitElement(element);
        }
    });

    return (T) ret[0];
}
 
源代码8 项目: idea-php-toolbox   文件: PhpElementsUtil.java
/**
 * Find a string return value of a method context "function() { return 'foo'}"
 * First match wins
 */
@Nullable
static public String getMethodReturnAsString(@NotNull Method method) {

    final Set<String> values = new HashSet<>();
    method.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitElement(PsiElement element) {

            if(PhpElementsUtil.getMethodReturnPattern().accepts(element)) {
                String value = PhpElementsUtil.getStringValue(element);
                if(value != null && StringUtils.isNotBlank(value)) {
                    values.add(value);
                }
            }

            super.visitElement(element);
        }
    });

    if(values.size() == 0) {
        return null;
    }

    // we support only first item
    return values.iterator().next();
}
 
private void buildEventVariables(@NotNull final Project project, final StringBuilder stringBuilder, Method classMethod) {
    classMethod.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if ((element instanceof StringLiteralExpression) && ((StringLiteralExpression) element).getContents().equals(generatorContainer.getHookName())) {
                PsiElement parent = element.getParent();
                if(parent instanceof ParameterList) {
                    PsiElement[] parameterList = ((ParameterList) parent).getParameters();
                    if(parameterList.length > 1) {
                        if(parameterList[1] instanceof ArrayCreationExpression) {
                            Map<String, PsiElement> eventParameters = PhpElementsUtil.getArrayCreationKeyMap((ArrayCreationExpression) parameterList[1]);
                            for(Map.Entry<String, PsiElement> entrySet : eventParameters.entrySet()) {
                                stringBuilder.append("\n");
                                PhpPsiElement psiElement = PhpElementsUtil.getArrayValue((ArrayCreationExpression) parameterList[1], entrySet.getKey());
                                if(psiElement instanceof PhpTypedElement) {

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

                                    PhpType type = ((PhpTypedElement) psiElement).getType();
                                    for (PhpClass aClass : PhpElementsUtil.getClassFromPhpTypeSet(project, type.getTypes())) {
                                        // force absolute namespace
                                        classes.add("\\" + StringUtils.stripStart(aClass.getPresentableFQN(), "\\"));
                                    }

                                    if(classes.size() > 0) {
                                        stringBuilder.append("/** @var ").append(StringUtils.join(classes, "|")).append("$").append(entrySet.getKey()).append(" */\n");
                                    }
                                }
                                stringBuilder.append("$").append(entrySet.getKey()).append(" = ").append("$args->get('").append(entrySet.getKey()).append("');\n");
                            }
                        }
                    }
                }
            }
            super.visitElement(element);
        }
    });
}
 
源代码10 项目: intellij-latte   文件: ClassUsagesInspection.java
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof LatteFile)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();
	file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof LattePhpClassReference) {
				String className = ((LattePhpClassReference) element).getClassName();
				Collection<PhpClass> classes = LattePhpUtil.getClassesByFQN(element.getProject(), className);
				if (classes.size() == 0) {
					addError(manager, problems, element, "Undefined class '" + className + "'", isOnTheFly);

				} else {
					for (PhpClass phpClass : classes) {
						if (phpClass.isDeprecated()) {
							addDeprecated(manager, problems, element, "Used class '" + className + "' is marked as deprecated", isOnTheFly);
							break;

						} else if (phpClass.isInternal()) {
							addDeprecated(manager, problems, element, "Used class '" + className + "' is marked as internal", isOnTheFly);
							break;
						}
					}
				}

			} else {
				super.visitElement(element);
			}
		}
	});

	return problems.toArray(new ProblemDescriptor[0]);
}
 
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof LatteFile)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();
	file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof BaseLattePhpElement) {
				if (!LattePhpVariableUtil.isNextDefinitionOperator(element)) {
					for (LattePhpArrayUsage usage : ((BaseLattePhpElement) element).getPhpArrayUsageList()) {
						if (usage.getPhpArrayContent().getFirstChild() == null) {
							addError(manager, problems, usage, "Can not use [] for reading", isOnTheFly);
						}
					}
				}

			} else if (element instanceof LattePhpForeach) {
				LattePhpType type = ((LattePhpForeach) element).getPhpExpression().getPhpType();
				if (!type.isMixed() && !type.isIterable(element.getProject())) {
					addProblem(
							manager,
							problems,
							((LattePhpForeach) element).getPhpExpression(),
							"Invalid argument supplied to 'foreach'. Expected types: 'array' or 'object', '" + type.toString() + "' provided.",
							isOnTheFly
					);
				}

			} else {
				super.visitElement(element);
			}
		}
	});

	return problems.toArray(new ProblemDescriptor[0]);
}
 
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof LatteFile)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();
	file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof LatteMacroModifier) {
				String filterName = ((LatteMacroModifier) element).getModifierName();
				LatteFilterSettings latteFilter = LatteConfiguration.getInstance(element.getProject()).getFilter(filterName);
				if (latteFilter == null) {
					LocalQuickFix addModifierFix = IntentionManager.getInstance().convertToFix(new AddCustomLatteModifier(filterName));
					ProblemHighlightType type = ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
					String description = "Undefined latte filter '" + filterName + "'";
					ProblemDescriptor problem = manager.createProblemDescriptor(element, description, true, type, isOnTheFly, addModifierFix);
					problems.add(problem);
				}

			} else {
				super.visitElement(element);
			}
		}
	});

	return problems.toArray(new ProblemDescriptor[0]);
}
 
源代码13 项目: intellij-latte   文件: MethodUsagesInspection.java
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof LatteFile)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();
	file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof LattePhpMethod) {
				if (((LattePhpMethod) element).isFunction()) {
					processFunction((LattePhpMethod) element, problems, manager, isOnTheFly);

				} else {
					processMethod((LattePhpMethod) element, problems, manager, isOnTheFly);
				}

			} else {
				super.visitElement(element);
			}
		}
	});

	return problems.toArray(new ProblemDescriptor[0]);
}
 
源代码14 项目: intellij-latte   文件: DeprecatedTagInspection.java
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof LatteFile)) {
		return null;
	}
	final List<ProblemDescriptor> problems = new ArrayList<>();
	file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof LatteMacroTag) {
				String macroName = ((LatteMacroTag) element).getMacroName();
				LatteTagSettings macro = LatteConfiguration.getInstance(element.getProject()).getTag(macroName);
				if (macro != null && macro.isDeprecated()) {
					String description = macro.getDeprecatedMessage() != null && macro.getDeprecatedMessage().length() > 0
							? macro.getDeprecatedMessage()
							: "Tag {" + macroName + "} is deprecated";
					ProblemDescriptor problem = manager.createProblemDescriptor(element, description, true, ProblemHighlightType.LIKE_DEPRECATED, isOnTheFly);
					problems.add(problem);

				}
			} else {
				super.visitElement(element);
			}
		}
	});

	return problems.toArray(new ProblemDescriptor[0]);
}
 
private static void checkClassicMacro(
		LatteMacroTag macroTag,
		@NotNull List<ProblemDescriptor> problems,
		@NotNull final InspectionManager manager,
		final boolean isOnTheFly
) {
	String name = macroTag.getMacroName();
	LatteTagSettings macro = LatteConfiguration.getInstance(macroTag.getProject()).getTag(name);
	if (macro == null || macro.isAllowedModifiers()) {
		return;
	}

	LatteMacroContent content = macroTag.getMacroContent();
	if (content == null) {
		return;
	}

	content.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof LatteMacroModifier && !((LatteMacroModifier) element).isVariableModifier()) {
				String description = "Modifiers are not allowed here";
				ProblemDescriptor problem = manager.createProblemDescriptor(element, description, true, ProblemHighlightType.GENERIC_ERROR, isOnTheFly);
				problems.add(problem);

			} else {
				super.visitElement(element);
			}
		}
	});
}
 
源代码16 项目: idea-php-toolbox   文件: PhpElementsUtil.java
/**
 * Find a string return value of a method context "function() { return 'foo'}"
 * First match wins
 */
@Nullable
static public String getMethodReturnAsString(@NotNull Method method) {

    final Set<String> values = new HashSet<>();
    method.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitElement(PsiElement element) {

            if(PhpElementsUtil.getMethodReturnPattern().accepts(element)) {
                String value = PhpElementsUtil.getStringValue(element);
                if(value != null && StringUtils.isNotBlank(value)) {
                    values.add(value);
                }
            }

            super.visitElement(element);
        }
    });

    if(values.size() == 0) {
        return null;
    }

    // we support only first item
    return values.iterator().next();
}
 
private void visitYaml(final ProblemsHolder holder, PsiFile psiFile) {
    psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(YamlElementPatternHelper.getSingleLineScalarKey("_controller", "controller").accepts(element)) {
                String text = PsiElementUtils.trimQuote(element.getText());
                if(StringUtils.isNotBlank(text)) {
                    InspectionUtil.inspectController(element, text, holder, new YamlLazyRouteName(element));
                }
            }

            super.visitElement(element);
        }
    });
}
 
private void visitXml(final ProblemsHolder holder, PsiFile psiFile) {
    psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(XmlHelper.getRouteControllerPattern().accepts(element)) {
                String text = PsiElementUtils.trimQuote(element.getText());
                if(StringUtils.isNotBlank(text)) {
                    InspectionUtil.inspectController(element, text, holder, new XmlLazyRouteName(element));
                }
            }

            super.visitElement(element);
        }
    });
}
 
private void visitYamlFile(PsiFile psiFile, final ProblemsHolder holder, @NotNull final ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector) {

        psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
            @Override
            public void visitElement(PsiElement element) {
                annotateCallMethod(element, holder, lazyServiceCollector);
                super.visitElement(element);
            }
        });

    }
 
private void visitXmlFile(@NotNull PsiFile psiFile, @NotNull final ProblemsHolder holder, @NotNull final ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector) {

        psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
            @Override
            public void visitElement(PsiElement element) {

                if(XmlHelper.getTagAttributePattern("tag", "method").inside(XmlHelper.getInsideTagPattern("services")).inFile(XmlHelper.getXmlFilePattern()).accepts(element) ||
                   XmlHelper.getTagAttributePattern("call", "method").inside(XmlHelper.getInsideTagPattern("services")).inFile(XmlHelper.getXmlFilePattern()).accepts(element)
                  )
                {

                    // attach to text child only
                    PsiElement[] psiElements = element.getChildren();
                    if(psiElements.length < 2) {
                        return;
                    }

                    String serviceClassValue = XmlHelper.getServiceDefinitionClass(element);
                    if(serviceClassValue != null && StringUtils.isNotBlank(serviceClassValue)) {
                        registerMethodProblem(psiElements[1], holder, serviceClassValue, lazyServiceCollector);
                    }

                }

                super.visitElement(element);
            }
        });

    }
 
/**
 * Find a string return value of a method context "function() { return 'foo'}"
 * First match wins
 */
@Nullable
static public String getMethodReturnAsString(@NotNull PhpClass phpClass, @NotNull String methodName) {

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

    final Set<String> values = new HashSet<>();
    method.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitElement(PsiElement element) {

            if(PhpElementsUtil.getMethodReturnPattern().accepts(element)) {
                String value = PhpElementsUtil.getStringValue(element);
                if(value != null && StringUtils.isNotBlank(value)) {
                    values.add(value);
                }
            }

            super.visitElement(element);
        }
    });

    if(values.size() == 0) {
        return null;
    }

    // we support only first item
    return values.iterator().next();
}
 
源代码22 项目: consulo   文件: ScanSourceCommentsAction.java
private void scanCommentsInFile(Project project, final VirtualFile vFile) {
  if (!vFile.isDirectory() && vFile.getFileType() instanceof LanguageFileType) {
    PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
    if (psiFile == null) return;

    for (PsiFile root : psiFile.getViewProvider().getAllFiles()) {
      root.accept(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitComment(PsiComment comment) {
          commentFound(vFile, comment.getText());
        }
      });
    }
  }
}
 
源代码23 项目: consulo   文件: SimpleDuplicatesFinder.java
private void deannotatePattern() {
  for (final PsiElement patternComponent : myPattern) {
    patternComponent.accept(new PsiRecursiveElementWalkingVisitor() {
      @Override public void visitElement(PsiElement element) {
        if (element.getUserData(PARAMETER) != null) {
          element.putUserData(PARAMETER, null);
        }
      }
    });
  }
}
 
源代码24 项目: consulo   文件: SimpleDuplicatesFinder.java
private void annotatePattern() {
  for (final PsiElement patternComponent : myPattern) {
    patternComponent.accept(new PsiRecursiveElementWalkingVisitor() {
      @Override
      public void visitElement(PsiElement element) {
        super.visitElement(element);
        if (myParameters.contains(element.getText())) {
          element.putUserData(PARAMETER, element);
        }

      }
    });
  }
}
 
private void visitReturnElements(@NotNull Project project, @NotNull String className, @NotNull String methodName, @NotNull final ReturnVisitor visitor) {

        for (PhpClass phpClass : PhpIndex.getInstance(project).getAllSubclasses(className)) {

            final Method method = phpClass.findOwnMethodByName(methodName);
            if(method == null) {
                continue;
            }

            method.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
                @Override
                public void visitElement(PsiElement element) {

                    if(!(element instanceof PhpReturn)) {
                        super.visitElement(element);
                        return;
                    }

                    PsiElement firstChild = ((PhpReturn) element).getFirstPsiChild();
                    if(!(firstChild instanceof ArrayCreationExpression)) {
                        return;
                    }

                    for (PsiElement arrayValue : firstChild.getChildren()) {

                        if(arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) {
                            continue;
                        }

                        PsiElement stringLiteral = arrayValue.getFirstChild();
                        if(!(stringLiteral instanceof StringLiteralExpression)) {
                            continue;
                        }

                        String contents = ((StringLiteralExpression) stringLiteral).getContents();
                        if(StringUtils.isNotBlank(contents)) {
                            visitor.visit(method, (StringLiteralExpression) stringLiteral, contents);
                        }

                    }

                    super.visitElement(element);
                }
            });

        }
    }
 
private void attachImplementsBlocks(PsiElement psiElement, Collection<LineMarkerInfo> lineMarkerInfos, Set<VirtualFile> virtualFiles) {
    if(virtualFiles.size() == 0) {
        return;
    }

    VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile();
    if(virtualFiles.contains(virtualFile)) {
        virtualFiles.remove(virtualFile);
    }

    final String blockName = psiElement.getText();
    if(StringUtils.isBlank(blockName)) {
        return;
    }

    final Collection<PsiElement> targets = new ArrayList<>();

    for(VirtualFile virtualTemplate: virtualFiles) {
        PsiFile psiFile = PsiManager.getInstance(psiElement.getProject()).findFile(virtualTemplate);
        if(psiFile != null) {
            psiFile.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
                @Override
                public void visitElement(PsiElement element) {

                    if(SmartyPattern.getBlockPattern().accepts(element)) {
                        String text = element.getText();
                        if(blockName.equalsIgnoreCase(text)) {
                            targets.add(element);
                        }

                    }

                    super.visitElement(element);
                }
            });
        }
    }

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

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.IMPLEMENTED).
        setTargets(targets).
        setTooltipText("Navigate to block");

    lineMarkerInfos.add(builder.createLineMarkerInfo(psiElement));
}
 
private void collectBootstrapSubscriber(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> lineMarkerInfos, PsiFile containingFile) {
    Map<String, Method> methods = new HashMap<>();

    // we dont want multiple line markers, so wrap all into one here
    Map<String, Set<PsiElement>> methodTargets = new HashMap<>();

    for(PsiElement psiElement: psiElements) {
        if(psiElement instanceof Method && ((Method) psiElement).getModifier().isPublic()) {
            methods.put(((Method) psiElement).getName(), (Method) psiElement);
        }
    }

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

    final Project project = containingFile.getProject();
    containingFile.accept(new PsiRecursiveElementWalkingVisitor() {
        @Override
        public void visitElement(PsiElement element) {
            if(!(element instanceof MethodReference)) {
                super.visitElement(element);
                return;
            }

            MethodReference methodReference = (MethodReference) element;
            String name = methodReference.getName();
            if(name != null && (name.equals("subscribeEvent") || name.equals("createEvent"))) {
                PsiElement[] parameters = methodReference.getParameters();
                if(parameters.length >= 2 && parameters[0] instanceof StringLiteralExpression && parameters[1] instanceof StringLiteralExpression) {
                    String subscriberName = ((StringLiteralExpression) parameters[0]).getContents();
                    String methodName = ((StringLiteralExpression) parameters[1]).getContents();

                    if(StringUtils.isNotBlank(subscriberName) && StringUtils.isNotBlank(methodName)) {

                        if(methods.containsKey(methodName)) {

                            if(!methodTargets.containsKey(methodName)) {
                                methodTargets.put(methodName, new HashSet<>());
                            }

                            methodTargets.get(methodName).add(parameters[1]);
                            methodTargets.get(methodName).addAll(HookSubscriberUtil.getAllHookTargets(project, subscriberName));
                        }
                    }
                }
            }

            super.visitElement(element);
        }
    });

    // we allow multiple events
    for(Map.Entry<String, Set<PsiElement>> method: methodTargets.entrySet()) {
        if(methods.containsKey(method.getKey())) {

            NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(ShopwarePluginIcons.SHOPWARE_LINEMARKER).
                setTargets(method.getValue()).
                setTooltipText("Related Targets");

            Method psiMethod = methods.get(method.getKey());

            // attach linemarker to leaf item which is our function name for performance reasons
            ASTNode node = psiMethod.getNode().findChildByType(PhpTokenTypes.IDENTIFIER);
            if(node != null) {
                lineMarkerInfos.add(builder.createLineMarkerInfo(node.getPsi()));
            }
        }
    }
}
 
源代码28 项目: intellij-latte   文件: ConstantUsagesInspection.java
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof LatteFile)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();
	file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof LattePhpConstant) {
				LattePhpType phpType = ((LattePhpConstant) element).getPhpType();

				Collection<PhpClass> phpClasses = phpType.getPhpClasses(element.getProject());
				if (phpClasses == null) {
					return;
				}

				boolean isFound = false;
				String constantName = ((LattePhpConstant) element).getConstantName();
				for (PhpClass phpClass : phpClasses) {
					for (Field field : phpClass.getFields()) {
						if (field.isConstant() && field.getName().equals(constantName)) {
							PhpModifier modifier = field.getModifier();
							if (modifier.isPrivate()) {
								addProblem(manager, problems, element, "Used private constant '" + constantName + "'", isOnTheFly);
							} else if (modifier.isProtected()) {
								addProblem(manager, problems, element, "Used protected constant '" + constantName + "'", isOnTheFly);
							} else if (field.isDeprecated()) {
								addDeprecated(manager, problems, element, "Used constant '" + constantName + "' is marked as deprecated", isOnTheFly);
							} else if (field.isInternal()) {
								addDeprecated(manager, problems, element, "Used constant '" + constantName + "' is marked as internal", isOnTheFly);
							}
							isFound = true;
						}
					}
				}

				if (!isFound) {
					addProblem(manager, problems, element, "Constant '" + constantName + "' not found for type '" + phpType.toString() + "'", isOnTheFly);
				}

			} else {
				super.visitElement(element);
			}
		}
	});

	return problems.toArray(new ProblemDescriptor[0]);
}
 
源代码29 项目: intellij-latte   文件: PropertyUsagesInspection.java
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof LatteFile)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();
	file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof LattePhpProperty) {
				LattePhpType phpType = ((LattePhpProperty) element).getPhpType();

				Collection<PhpClass> phpClasses = phpType.getPhpClasses(element.getProject());
				if (phpClasses == null) {
					return;
				}

				boolean isFound = false;
				String variableName = ((LattePhpProperty) element).getPropertyName();
				for (PhpClass phpClass : phpClasses) {
					for (Field field : phpClass.getFields()) {
						if (!field.isConstant() && field.getName().equals(LattePhpUtil.normalizePhpVariable(variableName))) {
							PhpModifier modifier = field.getModifier();
							if (modifier.isPrivate()) {
								addProblem(manager, problems, element, "Used private property '" + variableName + "'", isOnTheFly);
							} else if (modifier.isProtected()) {
								addProblem(manager, problems, element, "Used protected property '" + variableName + "'", isOnTheFly);
							} else if (field.isDeprecated()) {
								addDeprecated(manager, problems, element, "Used property '" + variableName + "' is marked as deprecated", isOnTheFly);
							} else if (field.isInternal()) {
								addDeprecated(manager, problems, element, "Used property '" + variableName + "' is marked as internal", isOnTheFly);
							}

							if (modifier.isStatic()) {
								String description = "Property '" + variableName + "' is static but used non statically";
								addProblem(manager, problems, element, description, isOnTheFly);

							}
							isFound = true;
						}
					}
				}

				if (!isFound) {
					addProblem(manager, problems, element, "Property '" + variableName + "' not found for type '" + phpType.toString() + "'", isOnTheFly);
				}

			} else {
				super.visitElement(element);
			}
		}
	});

	return problems.toArray(new ProblemDescriptor[0]);
}
 
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof LatteFile)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();
	file.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
		@Override
		public void visitElement(PsiElement element) {
			if (element instanceof LattePhpStaticVariable) {
				LattePhpType phpType = ((LattePhpStaticVariable) element).getPhpType();

				Collection<PhpClass> phpClasses = phpType.getPhpClasses(element.getProject());
				if (phpClasses == null) {
					return;
				}

				boolean isFound = false;
				String variableName = ((LattePhpStaticVariable) element).getVariableName();
				for (PhpClass phpClass : phpClasses) {
					for (Field field : phpClass.getFields()) {
						if (!field.isConstant() && field.getName().equals(variableName)) {
							PhpModifier modifier = field.getModifier();
							if (modifier.isPrivate()) {
								addProblem(manager, problems, element, "Used private static property '" + variableName + "'", isOnTheFly);
							} else if (modifier.isProtected()) {
								addProblem(manager, problems, element, "Used protected static property '" + variableName + "'", isOnTheFly);
							} else if (field.isDeprecated()) {
								addDeprecated(manager, problems, element, "Used static property '" + variableName + "' is marked as deprecated", isOnTheFly);
							} else if (field.isInternal()) {
								addDeprecated(manager, problems, element, "Used static property '" + variableName + "' is marked as internal", isOnTheFly);
							}

							if (!modifier.isStatic()) {
								String description = "Property '" + variableName + "' is not static but used statically";
								addProblem(manager, problems, element, description, isOnTheFly);

							}
							isFound = true;
						}
					}
				}

				if (!isFound) {
					addProblem(manager, problems, element, "Property '" + variableName + "' not found for type '" + phpType.toString() + "'", isOnTheFly);
				}

			} else {
				super.visitElement(element);
			}
		}
	});

	return problems.toArray(new ProblemDescriptor[0]);
}
 
 类所在包
 同包方法