本文整理汇总了Java中com.jetbrains.php.lang.lexer.PhpTokenTypes类的典型用法代码示例。如果您正苦于以下问题:Java PhpTokenTypes类的具体用法?Java PhpTokenTypes怎么用?Java PhpTokenTypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PhpTokenTypes类属于com.jetbrains.php.lang.lexer包,在下文中一共展示了PhpTokenTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyFix
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement expression = descriptor.getPsiElement();
if (expression instanceof ArrayHashElement) {
PsiElement next = expression.getNextSibling();
if (next instanceof PsiWhiteSpace) {
next.delete();
}
next = expression.getNextSibling();
if (null != next && PhpTokenTypes.opCOMMA == next.getNode().getElementType()) {
next.delete();
}
next = expression.getNextSibling();
if (next instanceof PsiWhiteSpace) {
next.delete();
}
expression.delete();
}
}
示例2: applyFix
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement expression = descriptor.getPsiElement();
if (null != expression && expression.getParent() instanceof ArrayCreationExpression) {
final ArrayCreationExpression container = (ArrayCreationExpression) expression.getParent();
final PsiElement closingBracket = container.getLastChild();
if (null == closingBracket) {
return;
}
for (String translation : missing) {
/* reach or create a comma */
PsiElement last = closingBracket.getPrevSibling();
if (last instanceof PsiWhiteSpace) {
last = last.getPrevSibling();
}
if (null != last && PhpTokenTypes.opCOMMA != last.getNode().getElementType()) {
last.getParent().addAfter(PhpPsiElementFactory.createComma(project), last);
last = last.getNextSibling();
}
/* add a new translation */
final String escaped = PhpStringUtil.escapeText(translation, true, '\n', '\t');
final String pairPattern = "array('%s%' => '%s%')".replace("%s%", escaped).replace("%s%", escaped);
final ArrayCreationExpression array = PhpPsiElementFactory.createFromText(project, ArrayCreationExpression.class, pairPattern);
final PhpPsiElement pair = null == array ? null : array.getHashElements().iterator().next();
final PsiWhiteSpace space = PhpPsiElementFactory.createFromText(project, PsiWhiteSpace.class, " ");
if (null == last || null == pair || null == space) {
continue;
}
last.getParent().addAfter(pair, last);
last.getParent().addAfter(space, last);
}
}
}
示例3: arrowedReference
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
static ElementPattern<PsiElement> arrowedReference() {
final PsiElementPattern.Capture<PsiElement> arrowedCase = PlatformPatterns.psiElement(PhpTokenTypes.IDENTIFIER).afterLeaf("->");
return StandardPatterns.or(
arrowedCase.withParent(FieldReference.class),
arrowedCase.withParent(MethodReference.class)
);
}
示例4: testGetPrevMatch
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
public void testGetPrevMatch() {
final PsiFile fileSample = getResourceFile("utils/TreeUtil.elements.php");
Assert.assertNull(TreeUtil.getPrevMatch(
getElementByName(fileSample, "referenceVariable"),
filterBy -> false,
stopBy -> false
));
Assert.assertNull(TreeUtil.getPrevMatch(
getElementByName(fileSample, "referenceVariable"),
filterBy -> false,
stopBy -> true
));
final Function referenceFunction = (Function) getElementByName(fileSample, "referenceFunction");
final PhpReturnType returnType = referenceFunction.getReturnType();
final PsiElement referenceReturnType = valueOf((returnType != null) ? returnType.getClassReference() : null);
Assert.assertNull(TreeUtil.getPrevMatch(
referenceReturnType,
filterBy -> (filterBy instanceof ASTNode) && filterBy.equals(PhpTokenTypes.opQUEST),
PhpDocComment.class::isInstance
));
Assert.assertEquals(PhpTokenTypes.opQUEST,
valueOf(((ASTNode) TreeUtil.getPrevMatch(
referenceReturnType,
filterBy -> (filterBy instanceof ASTNode) && ((ASTNode) filterBy).getElementType().equals(PhpTokenTypes.opQUEST),
stopBy -> false
))).getElementType());
}
示例5: BxSuperglobalsProvider
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
public BxSuperglobalsProvider() {
extend(CompletionType.BASIC, PlatformPatterns.psiElement(PhpTokenTypes.VARIABLE).withLanguage(PhpLanguage.INSTANCE), new CompletionProvider<CompletionParameters>() {
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
String currentFileName = parameters.getOriginalFile().getName();
for (String variable : bxSuperglobals.keySet()) {
BxSuperglobal superglobal = bxSuperglobals.get(variable);
if (superglobal.scopeFileNames == null || superglobal.scopeFileNames.contains(currentFileName))
resultSet.addElement(LookupElementBuilder.create("$" + variable));
}
}
});
}
示例6: getSuitableEditorPosition
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
private static int getSuitableEditorPosition(Editor editor, PhpFile phpFile)
{
PsiElement currElement = phpFile.findElementAt(editor.getCaretModel().getOffset());
if (currElement != null) {
PsiElement parent = currElement.getParent();
for (PsiElement prevParent = currElement; parent != null && !(parent instanceof PhpFile); parent = parent.getParent()) {
if (isClassMember(parent)) {
return getNextPos(parent);
}
if (parent instanceof PhpClass) {
while (prevParent != null) {
if (isClassMember(prevParent) || prevParent.getNode().getElementType() == PhpTokenTypes.chLBRACE) {
return getNextPos(prevParent);
}
prevParent = prevParent.getPrevSibling();
}
for (PsiElement classChild = parent.getFirstChild(); classChild != null; classChild = classChild.getNextSibling()) {
if (classChild.getNode().getElementType() == PhpTokenTypes.chLBRACE) {
return getNextPos(classChild);
}
}
}
prevParent = parent;
}
}
return -1;
}
示例7: isAvailable
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
/**
* Check if the intent is available at the current position.
*
* @param project Current project.
* @param editor Current editor.
* @param element Element selected by the caret.
*
* @return True if we can use the intent, false otherwise.
*/
public boolean isAvailable (@NotNull Project project, Editor editor, @Nullable PsiElement element)
{
if (element == null || !PhpWorkaroundUtil.isIntentionAvailable(element) || element.getParent() == null)
{
return false;
}
ASTNode ast_node = element.getNode();
if (ast_node == null)
{
return false;
}
IElementType element_type = ast_node.getElementType();
// Must be either a double quoted or a single quoted string.
if (element_type != PhpTokenTypes.STRING_LITERAL && element_type != PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE)
{
return false;
}
// Unquote the class string if needed.
String class_name = getUnquotedString(element.getText());
PhpIndex php_index = PhpIndex.getInstance(project);
// Look for both regular and namespaced class names.
return (
class_name.length() > 0
&& (php_index.getClassByName(class_name) != null || php_index.getClassesByFQN(class_name).size() > 0)
);
}
示例8: collectNavigationMarkers
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
@Override
protected void collectNavigationMarkers(
@NotNull PsiElement element,
Collection<? super RelatedItemLineMarkerInfo> result
) {
ASTNode node = element.getNode();
if (node == null) {
return;
}
IElementType elementType = node.getElementType();
PsiElement parent = element.getParent();
boolean isPhpClassMethod = (elementType == PhpTokenTypes.IDENTIFIER) && parent instanceof Method;
boolean isPhpClass = (elementType == PhpTokenTypes.IDENTIFIER) && parent instanceof PhpClass;
boolean isPhpClassField = (elementType == PhpTokenTypes.VARIABLE) && parent instanceof Field;
if (isPhpClass || isPhpClassMethod || isPhpClassField) {
PhpNamedElement classMember = PsiTreeUtil.getParentOfType(element, PhpNamedElement.class);
List<PhpNamedElement> matchedAdvices = PointcutAdvisor.getMatchedAdvices(classMember);
if (matchedAdvices.size() > 0) {
NavigationGutterIconBuilder<PsiElement> builder = null;
builder = NavigationGutterIconBuilder.create(GoAopIcons.ADVISING_ELEMENT);
if (matchedAdvices.size() > 1) {
builder.setTooltipText("Navigate to AOP advices");
} else {
builder.setTooltipText("Advised by '" + matchedAdvices.get(0).getFQN() + "'");
}
builder.setTargets(matchedAdvices);
result.add(builder.createLineMarkerInfo(element));
}
}
}
示例9: collectNavigationMarkers
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
@Override
protected void collectNavigationMarkers(
@NotNull PsiElement element,
Collection<? super RelatedItemLineMarkerInfo> result
) {
ASTNode node = element.getNode();
if (node == null) {
return;
}
IElementType elementType = node.getElementType();
PsiElement parent = element.getParent();
boolean isPhpClassMethod = (elementType == PhpTokenTypes.IDENTIFIER) && parent instanceof Method;
boolean isPhpClassField = (elementType == PhpTokenTypes.VARIABLE) && parent instanceof Field;
if (!isPhpClassMethod && !isPhpClassField) {
return;
}
boolean isParentAspect = PluginUtil.isAspect(((PhpClassMember) parent).getContainingClass());
if (!isParentAspect) {
return;
}
PhpNamedElement aspectMember = PsiTreeUtil.getParentOfType(element, PhpNamedElement.class);
List<PhpNamedElement> matchedElements = PointcutAdvisor.getMatchedElements(aspectMember);
if (matchedElements != null && matchedElements.size() > 0) {
NavigationGutterIconBuilder<PsiElement> builder;
builder = NavigationGutterIconBuilder.create(GoAopIcons.ADVISED_ELEMENT);
if (matchedElements.size() > 1) {
builder.setTooltipText("Navigate to advised elements");
} else {
builder.setTooltipText("Advising '" + matchedElements.get(0).getFQN() + "'");
}
builder.setTargets(matchedElements);
result.add(builder.createLineMarkerInfo(element));
}
}
示例10: collectSubscriberTargets
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
private void collectSubscriberTargets(@NotNull List<PsiElement> psiElements, final @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {
Collection<PhpClass> phpClasses = new ArrayList<>();
for (PsiElement psiElement : psiElements) {
if(psiElement instanceof PhpClass && PhpElementsUtil.isInstanceOf((PhpClass) psiElement, "Enlight\\Event\\SubscriberInterface")) {
phpClasses.add((PhpClass) psiElement);
}
}
for (PhpClass phpClass : phpClasses) {
Method getSubscribedEvents = phpClass.findOwnMethodByName("getSubscribedEvents");
if(getSubscribedEvents == null) {
continue;
}
Map<String, Pair<String, PsiElement>> methodEvent = new HashMap<>();
HookSubscriberUtil.visitSubscriberEvents(getSubscribedEvents, (event, methodName, key) ->
methodEvent.put(methodName, Pair.create(event, key))
);
for (Method method : phpClass.getOwnMethods()) {
if(!methodEvent.containsKey(method.getName()) || !method.getAccess().isPublic()) {
continue;
}
Pair<String, PsiElement> result = methodEvent.get(method.getName());
NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(ShopwarePluginIcons.SHOPWARE_LINEMARKER).
setTargets(new MyCollectionNotNullLazyValue(result.getSecond(), result.getFirst())).
setTooltipText("Related Targets");
// attach linemarker to leaf item which is our function name for performance reasons
ASTNode node = method.getNode().findChildByType(PhpTokenTypes.IDENTIFIER);
if(node != null) {
lineMarkerInfos.add(builder.createLineMarkerInfo(node.getPsi()));
}
}
}
}
示例11: buildVisitor
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
PsiFile psiFile = holder.getFile();
if(!ShopwareProjectComponent.isValidForProject(psiFile)) {
return super.buildVisitor(holder, isOnTheFly);
}
if(!"Bootstrap.php".equals(psiFile.getName())) {
return super.buildVisitor(holder, isOnTheFly);
}
return new PsiElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if(element instanceof Method) {
String methodName = ((Method) element).getName();
if(INSTALL_METHODS.contains(((Method) element).getName())) {
if(PsiTreeUtil.collectElementsOfType(element, PhpReturn.class).size() == 0) {
PsiElement psiElement = PsiElementUtils.getChildrenOfType(element, PlatformPatterns.psiElement(PhpTokenTypes.IDENTIFIER).withText(methodName));
if(psiElement != null) {
holder.registerProblem(psiElement, "Shopware need return statement", ProblemHighlightType.GENERIC_ERROR);
}
}
}
}
super.visitElement(element);
}
};
}
示例12: getPhpDoubleQuotedStringExpression
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
static PsiElement getPhpDoubleQuotedStringExpression(PsiElement psiElement) {
if (psiElement instanceof PhpFile) return null;
if (psiElement instanceof StringLiteralExpression) {
PsiElement firstChild = psiElement.getFirstChild();
if (firstChild != null) {
ASTNode childAstNode = firstChild.getNode();
IElementType childElementType = childAstNode.getElementType();
if (childElementType == PhpTokenTypes.STRING_LITERAL || childElementType == PhpTokenTypes.chLDOUBLE_QUOTE) {
return psiElement;
}
}
}
PsiElement parentPsi = psiElement.getParent();
return parentPsi != null ? getPhpDoubleQuotedStringExpression(parentPsi) : null;
}
示例13: mapPhpDoubleQuotedComplexStringContent
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
/**
* Gets the child nodes of a PHP double quoted string psiElement and maps them to a List of String values. Allows to
* specify a callback function for processing string literal fragments, and other for embedded variables and
* expressions. Delimiter double quotes are omitted since their presence is constant.
*
* @param psiElement The PHP double quoted string literal whose nodes are wanted to map
* @param stringFragmentMapper A Function implementation which gets a String from the ASTNode of any string
* literal fragment on the PHP string. Any node which lead to a null return value
* will be omitted from the result.
* @param embeddedExpressionMapper A Function implementation which gets a String from the ASTNode of any variable or
* expression embedded on the PHP string. Any node which lead to a null return value
* will be omitted from the result.
* @return A List of String objects containing the results of sequentially applying the PHP string pieces to the
* provided Function implementations as determined by the node type.
*/
public static List<String> mapPhpDoubleQuotedComplexStringContent(PsiElement psiElement, Function<ASTNode, String> stringFragmentMapper, Function<ASTNode, String> embeddedExpressionMapper) {
ASTNode astNode = psiElement.getNode();
if (astNode == null) return null;
ASTNode[] children = astNode.getChildren(null);
// complex strings always have more than one child node
if (children.length <= 1) return null;
List<String> map = new ArrayList<String>();
for (ASTNode childNode : children) {
IElementType pieceType = childNode.getElementType();
// skip delimiter quotes
if (pieceType == PhpTokenTypes.chLDOUBLE_QUOTE || pieceType == PhpTokenTypes.chRDOUBLE_QUOTE) continue;
if (pieceType == PhpTokenTypes.STRING_LITERAL) {
// the ASTNode is a piece of textual content of the string
String stringFragmentResult = stringFragmentMapper.apply(childNode);
if (stringFragmentResult != null) {
map.add(stringFragmentResult);
}
} else {
// the ASTNode is a variable or expression embedded in the string
String embeddedExpressionResult = embeddedExpressionMapper.apply(childNode);
if (embeddedExpressionResult != null) {
map.add(embeddedExpressionResult);
}
}
}
return map;
}
示例14: deleteArrayElement
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
public static void deleteArrayElement(PsiElement element) {
IElementType type;
do {
PsiElement nextSibling = element.getNextSibling();
element.delete();
element = nextSibling;
type = element.getNode().getElementType();
} while (element.isValid() && (type == PhpElementTypes.WHITE_SPACE || type == PhpTokenTypes.opCOMMA));
}
示例15: visitAttributeForeach
import com.jetbrains.php.lang.lexer.PhpTokenTypes; //导入依赖的package包/类
private static void visitAttributeForeach(@NotNull Method method, @NotNull Consumer<Pair<String, PsiElement>> consumer) {
Parameter[] parameters = method.getParameters();
if(parameters.length < 3) {
return;
}
for (Variable variable : PhpElementsUtil.getVariablesInScope(method, parameters[2])) {
// foreach ($attributes as $attribute)
PsiElement psiElement = PsiTreeUtil.nextVisibleLeaf(variable);
if(psiElement != null && psiElement.getNode().getElementType() == PhpTokenTypes.kwAS) {
PsiElement parent = variable.getParent();
if(!(parent instanceof ForeachStatement)) {
continue;
}
PhpPsiElement variableDecl = variable.getNextPsiSibling();
if(variableDecl instanceof Variable) {
for (Variable variable1 : PhpElementsUtil.getVariablesInScope(parent, (Variable) variableDecl)) {
visitVariable(variable1, consumer);
}
}
}
// in_array('foobar', $attributes)
PsiElement parameterList = variable.getParent();
if(parameterList instanceof ParameterList && PsiElementUtils.getParameterIndexValue(variable) == 1) {
PsiElement functionCall = parameterList.getParent();
if(functionCall instanceof FunctionReference && "in_array".equalsIgnoreCase(((FunctionReference) functionCall).getName())) {
PsiElement[] functionParameter = ((ParameterList) parameterList).getParameters();
if(functionParameter.length > 0) {
String stringValue = PhpElementsUtil.getStringValue(functionParameter[0]);
if(stringValue != null && StringUtils.isNotBlank(stringValue)) {
consumer.accept(Pair.create(stringValue, functionParameter[0]));
}
}
}
}
}
}