本文整理汇总了Java中com.jetbrains.php.lang.psi.elements.ConstantReference类的典型用法代码示例。如果您正苦于以下问题:Java ConstantReference类的具体用法?Java ConstantReference怎么用?Java ConstantReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstantReference类属于com.jetbrains.php.lang.psi.elements包,在下文中一共展示了ConstantReference类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildVisitor
import com.jetbrains.php.lang.psi.elements.ConstantReference; //导入依赖的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.psi.elements.ConstantReference; //导入依赖的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: reportTimestamps
import com.jetbrains.php.lang.psi.elements.ConstantReference; //导入依赖的package包/类
static void reportTimestamps(
@NotNull final ProblemsHolder problemsHolder,
@NotNull final PhpClass phpClass
) {
final Field fieldTimestamps = PhpClassUtil.findPropertyDeclaration(phpClass, "timestamps");
if (fieldTimestamps == null) {
return;
}
final PsiElement fieldTimestampsDefaultValue = fieldTimestamps.getDefaultValue();
if (!(fieldTimestampsDefaultValue instanceof PhpExpression)) {
return;
}
final PsiElement fieldTimestampsDefaultValueResolved = PsiElementUtil.resolve(fieldTimestampsDefaultValue);
if (!(fieldTimestampsDefaultValueResolved instanceof ConstantReference)) {
return;
}
if (!"true".equals(fieldTimestampsDefaultValueResolved.getText())) {
return;
}
final PsiElement issueReceptor = getReportableElement(phpClass, fieldTimestamps);
if (issueReceptor == null) {
return;
}
validatePropertyAnnotation(problemsHolder, phpClass, issueReceptor, "created_at", null);
validatePropertyAnnotation(problemsHolder, phpClass, issueReceptor, "updated_at", null);
}
示例4: testResolve
import com.jetbrains.php.lang.psi.elements.ConstantReference; //导入依赖的package包/类
public void testResolve() {
final PsiFile fileSample = getResourceFile("utils/PsiElementUtil.warpingLiterals.php");
// Default const types.
final StringLiteralExpression directLiteral = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "directLiteral"));
final StringLiteralExpression indirectLiteral = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "indirectLiteral"));
final StringLiteralExpression warpingLiteral = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "warpingLiteral"));
final StringLiteralExpression assignedLiteral = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "assignedLiteral"));
final StringLiteralExpression withSubAssignment = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "withSubAssignment"));
Assert.assertEquals("directValue", directLiteral.getContents());
Assert.assertEquals("indirectValue", indirectLiteral.getContents());
Assert.assertEquals("indirectValue", warpingLiteral.getContents());
Assert.assertEquals("indirectValue", assignedLiteral.getContents());
Assert.assertEquals("indirectValue", withSubAssignment.getContents());
final PsiElement ccUnresolvedConstantReference = getElementByName(fileSample, "ccUnresolvedConstantReference");
Assert.assertTrue(PsiElementUtil.resolve(ccUnresolvedConstantReference) instanceof ConstantReference);
// Class const types.
final StringLiteralExpression classIndirectLiteral = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "classIndirectLiteral"));
final StringLiteralExpression classWarpingLiteral = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "classWarpingLiteral"));
Assert.assertEquals("indirectClassValue", classIndirectLiteral.getContents());
Assert.assertEquals("indirectClassValue", classWarpingLiteral.getContents());
final PsiElement classResolvingFromProperty =
PsiElementUtil.resolve(valueOf((PhpExpression) ((Field) getElementByName(fileSample, "resolvingFromProperty")).getDefaultValue()));
Assert.assertEquals("TRUE", classResolvingFromProperty.getText());
final PsiElement classResolvingDirectlyFromProperty =
PsiElementUtil.resolve(valueOf((PhpExpression) ((Field) getElementByName(fileSample, "resolvingDirectlyFromProperty")).getDefaultValue()));
Assert.assertEquals("null", classResolvingDirectlyFromProperty.getText());
// Avoiding complex loopings.
final PsiElement shouldAvoidCyclicLoopingsWithConstants = getElementByName(fileSample, "shouldAvoidCyclicLoopingsWithConstants");
Assert.assertEquals("SHOULD_IGNORES_CYCLIC_LOOPINGS_A", PsiElementUtil.resolve(shouldAvoidCyclicLoopingsWithConstants).getText());
final PsiElement shouldAvoidCyclicLoopingsWithVariablesA = getElementByName(fileSample, "shouldAvoidCyclicLoopingsWithVariablesA");
Assert.assertEquals("$shouldAvoidCyclicLoopingsWithVariablesA", PsiElementUtil.resolve(shouldAvoidCyclicLoopingsWithVariablesA).getText());
// Resolving variables.
final StringLiteralExpression variableWrapping = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "variableWrapping"));
Assert.assertEquals("value", variableWrapping.getContents());
// With wrapping parentheses.
final StringLiteralExpression withParanteshesWrapping = (StringLiteralExpression) PsiElementUtil.resolve(getStringLiteral(fileSample, "withParanteshesWrapping"));
Assert.assertEquals("parentheses", withParanteshesWrapping.getContents());
// Should not resolve totally.
final PsiElement indirectShouldNotResolveTotally = PsiElementUtil.resolve(getStringLiteral(fileSample, "indirectShouldNotResolveTotally"));
Assert.assertTrue(indirectShouldNotResolveTotally instanceof MethodReference);
// Stop on first ConstantReference.
final PsiElement stopOnFirstConstantReference =
PsiElementUtil.resolve(getStringLiteral(fileSample, "stopOnFirstConstantReference"), ConstantReference.class::isInstance);
Assert.assertTrue(stopOnFirstConstantReference instanceof ConstantReference);
Assert.assertEquals("$stopOnFirstConstantReference = SHOULD_STOP_HERE", stopOnFirstConstantReference.getParent().getText());
final PsiElement stopOnFirstConstantReferenceIndirect =
PsiElementUtil.resolve(getStringLiteral(fileSample, "stopOnFirstConstantReferenceIndirect"), ConstantReference.class::isInstance);
Assert.assertTrue(stopOnFirstConstantReferenceIndirect instanceof ConstantReference);
Assert.assertEquals("$stopOnFirstConstantReference = SHOULD_STOP_HERE", stopOnFirstConstantReferenceIndirect.getParent().getText());
// Make sure that resolves to a @property will not broke.
final AssignmentExpression ccInstancePropertyRef = (AssignmentExpression) getElementByName(fileSample, "ccInstancePropertyRef").getParent();
final PsiElement ccInstanceProperty = PsiElementUtil.resolve(valueOf((PhpExpression) ccInstancePropertyRef.getValue()));
Assert.assertTrue(ccInstanceProperty instanceof PhpDocProperty);
}