本文整理汇总了Java中com.jetbrains.php.lang.parser.PhpElementTypes类的典型用法代码示例。如果您正苦于以下问题:Java PhpElementTypes类的具体用法?Java PhpElementTypes怎么用?Java PhpElementTypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PhpElementTypes类属于com.jetbrains.php.lang.parser包,在下文中一共展示了PhpElementTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildVisitor
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
return new PhpElementVisitor() {
@Override
public void visitPhpElement(PhpPsiElement element) {
if (!PlatformPatterns.psiElement(PhpElementTypes.CONSTANT_REF).accepts(element)) {
return;
}
ConstantReference constantReference = (ConstantReference) element;
Set<String> constants = getRemovedConstantsFQNs(constantReference);
if (constants.contains(constantReference.getFQN())) {
problemsHolder.registerProblem(element, "Constant removed with TYPO3 9, consider using an alternative");
}
}
};
}
示例2: getRemovedConstantsFQNs
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
private Set<String> getRemovedConstantsFQNs(ConstantReference element) {
Set<PsiElement> elements = new HashSet<>();
PsiFile[] constantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ConstantMatcher.php", GlobalSearchScope.allScope(element.getProject()));
for (PsiFile file : constantMatcherFiles) {
Collections.addAll(
elements,
PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el)
)
);
}
return elements.stream()
.map(stringLiteral -> "\\" + ((StringLiteralExpression)stringLiteral).getContents())
.collect(Collectors.toSet());
}
示例3: buildVisitor
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
return new PhpElementVisitor() {
@Override
public void visitPhpElement(PhpPsiElement element) {
if (!PlatformPatterns.psiElement(PhpElementTypes.FUNCTION_CALL).accepts(element)) {
return;
}
Set<String> constants = getRemovedGlobalFuntions(element);
FunctionReference constantReference = (FunctionReference) element;
if (constants.contains(constantReference.getFQN())) {
problemsHolder.registerProblem(element, "Global function removed with TYPO3 9, consider using an alternative");
}
}
};
}
示例4: getRemovedGlobalFuntions
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
private Set<String> getRemovedGlobalFuntions(PhpPsiElement element) {
Set<PsiElement> elements = new HashSet<>();
PsiFile[] constantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "FunctionCallMatcher.php", GlobalSearchScope.allScope(element.getProject()));
for (PsiFile file : constantMatcherFiles) {
Collections.addAll(
elements,
PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el)
)
);
}
return elements.stream()
.map(stringLiteral -> "\\" + ((StringLiteralExpression) stringLiteral).getContents())
.collect(Collectors.toSet());
}
示例5: buildVisitor
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
return new PhpElementVisitor() {
@Override
public void visitPhpElement(PhpPsiElement element) {
if (!PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE).accepts(element)) {
return;
}
Set<String> constants = getDeprecatedClassConstants(element);
ClassConstantReference classConstantReference = (ClassConstantReference) element;
if (constants.contains(classConstantReference.getText())) {
problemsHolder.registerProblem(element, "Deprecated class constant");
}
}
};
}
示例6: getDeprecatedClassConstants
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
private Set<String> getDeprecatedClassConstants(PhpPsiElement element) {
Set<PsiElement> elements = new HashSet<>();
PsiFile[] classConstantMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ClassConstantMatcher.php", GlobalSearchScope.allScope(element.getProject()));
for (PsiFile file : classConstantMatcherFiles) {
Collections.addAll(
elements,
PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el)
)
);
}
return elements.stream().map(stringLiteral -> ((StringLiteralExpression)stringLiteral).getContents()).collect(Collectors.toSet());
}
示例7: buildVisitor
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
return new PhpElementVisitor() {
@Override
public void visitPhpElement(PhpPsiElement element) {
if (!PlatformPatterns.psiElement(PhpElementTypes.CLASS_REFERENCE).accepts(element)) {
return;
}
Set<String> constants = getDeprecatedClasses(element);
ClassReference classReference = (ClassReference) element;
if (constants.contains(classReference.getFQN())) {
problemsHolder.registerProblem(element, "Class removed with TYPO3 9, consider using an alternative");
}
}
};
}
示例8: getDeprecatedClasses
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
private Set<String> getDeprecatedClasses(PhpPsiElement element) {
Set<PsiElement> elements = new HashSet<>();
PsiFile[] classNameMatcherFiles = FilenameIndex.getFilesByName(element.getProject(), "ClassNameMatcher.php", GlobalSearchScope.allScope(element.getProject()));
for (PsiFile file : classNameMatcherFiles) {
Collections.addAll(
elements,
PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el)
)
);
}
return elements.stream()
.map(stringLiteral -> "\\" + ((StringLiteralExpression)stringLiteral).getContents())
.collect(Collectors.toSet());
}
示例9: isMethodWithFirstStringOrFieldReference
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
public static boolean isMethodWithFirstStringOrFieldReference(PsiElement psiElement, String... methodName) {
if (!PlatformPatterns
.psiElement(PhpElementTypes.METHOD_REFERENCE)
.withChild(PlatformPatterns
.psiElement(PhpElementTypes.PARAMETER_LIST)
.withFirstChild(PlatformPatterns.or(
PlatformPatterns.psiElement(PhpElementTypes.STRING),
PlatformPatterns.psiElement(PhpElementTypes.FIELD_REFERENCE),
PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE)
))
).accepts(psiElement)) {
return false;
}
// cant we move it up to PlatformPatterns? withName condition dont looks working
String methodRefName = ((MethodReference) psiElement).getName();
return null != methodRefName && Arrays.asList(methodName).contains(methodRefName);
}
示例10: isValidComponentCall
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
/**
* Is the element is a parameter of $APPLICATION->IncludeComponent() call
*/
private static boolean isValidComponentCall(Object o, String component) {
PsiElement parameters = ((PsiElement) o).getParent(); if (parameters instanceof ParameterList) {
if (component != null) {
PsiElement[] params = ((ParameterList) parameters).getParameters(); if (params.length == 0 || params[0].getNode().getElementType() != PhpElementTypes.STRING || !((StringLiteralExpression) params[0]).getContents().equals(component))
return false;
}
PsiElement psiMethod = parameters.getParent(); if (psiMethod instanceof MethodReference) {
MethodReference method = (MethodReference) psiMethod;
/* CBitrixComponent::includeComponentClass() */
if (method.getClassReference() instanceof ClassReference && method.isStatic())
return "CBitrixComponent".equals(method.getClassReference().getName())
&& "includeComponentClass".equals(method.getName());
/* $APPLICATION->IncludeComponent() */
if (method.getClassReference() instanceof Variable && !method.isStatic())
return "APPLICATION".equals(method.getClassReference().getName())
&& "IncludeComponent".equals(method.getName());
}
}
return false;
}
示例11: isModuleKeyInFlatArray
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
public static boolean isModuleKeyInFlatArray(@NotNull StringLiteralExpression psiElement, @NotNull String key) {
PsiElement arrayKey = psiElement.getParent();
if(arrayKey != null && arrayKey.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
PsiElement hashElement = arrayKey.getParent();
if(hashElement instanceof ArrayHashElement) {
PsiElement arrayCreation = hashElement.getParent();
if(arrayCreation instanceof ArrayCreationExpression) {
PsiElement arrayValue = arrayCreation.getParent();
if(arrayValue != null && arrayValue.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
PsiElement hashArray = arrayValue.getParent();
if(hashArray instanceof ArrayHashElement) {
PhpPsiElement keyString = ((ArrayHashElement) hashArray).getKey();
if(keyString instanceof StringLiteralExpression) {
String contents = ((StringLiteralExpression) keyString).getContents();
if(key.equals(contents)) {
return true;
}
}
}
}
}
}
}
return false;
}
示例12: isExtendKey
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
public static boolean isExtendKey(@NotNull StringLiteralExpression parent) {
ArrayCreationExpression arrayCreation = PhpElementsUtil.getCompletableArrayCreationElement(parent);
if(arrayCreation == null) {
return false;
}
PsiElement arrayValue = arrayCreation.getParent();
if(arrayValue != null && arrayValue.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
PsiElement hashArray = arrayValue.getParent();
if(hashArray instanceof ArrayHashElement) {
PhpPsiElement key = ((ArrayHashElement) hashArray).getKey();
if(key instanceof StringLiteralExpression && "extend".equals(((StringLiteralExpression) key).getContents())) {
return true;
}
}
}
return false;
}
示例13: isMethodWithFirstStringOrFieldReference
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
/**
* $this->methodName('service_name')
* $this->methodName(SERVICE::NAME)
* $this->methodName($this->name)
*/
static public boolean isMethodWithFirstStringOrFieldReference(PsiElement psiElement, String... methodName) {
if(!PlatformPatterns
.psiElement(PhpElementTypes.METHOD_REFERENCE)
.withChild(PlatformPatterns
.psiElement(PhpElementTypes.PARAMETER_LIST)
.withFirstChild(PlatformPatterns.or(
PlatformPatterns.psiElement(PhpElementTypes.STRING),
PlatformPatterns.psiElement(PhpElementTypes.FIELD_REFERENCE),
PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE)
))
).accepts(psiElement)) {
return false;
}
// cant we move it up to PlatformPatterns? withName condition dont looks working
String methodRefName = ((MethodReference) psiElement).getName();
return null != methodRefName && Arrays.asList(methodName).contains(methodRefName);
}
示例14: matches
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {
PsiElement parent = parameter.getElement().getParent();
if(!(parent instanceof StringLiteralExpression)) {
return false;
}
PsiElement arrayValue = parent.getParent();
if(arrayValue == null || arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) {
return false;
}
PsiElement arrayCreation = arrayValue.getParent();
if(!(arrayCreation instanceof ArrayCreationExpression)) {
return false;
}
PsiElement phpReturn = arrayCreation.getParent();
if(!(phpReturn instanceof PhpReturn)) {
return false;
}
return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn);
}
示例15: getPattern
import com.jetbrains.php.lang.parser.PhpElementTypes; //导入依赖的package包/类
/**
* [$this, '']
* array($this, '')
*/
@NotNull
@Override
public PsiElementPattern.Capture<PsiElement> getPattern() {
return PlatformPatterns.psiElement().withParent(
PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE).afterLeafSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement().withText(",")
).afterSiblingSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE).withFirstNonWhitespaceChild(
PlatformPatterns.psiElement(Variable.class)
).afterLeafSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement().withText(PlatformPatterns.string().oneOf("[", "("))
)
)
)
);
}