use of com.intellij.psi.PsiKeyword in project intellij-community by JetBrains.
the class IfStatementSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = new ArrayList<>();
result.addAll(expandToWholeLine(editorText, e.getTextRange(), false));
PsiIfStatement statement = (PsiIfStatement) e;
final PsiKeyword elseKeyword = statement.getElseElement();
if (elseKeyword != null) {
final PsiStatement then = statement.getThenBranch();
if (then != null) {
final TextRange thenRange = new TextRange(statement.getTextRange().getStartOffset(), then.getTextRange().getEndOffset());
if (thenRange.contains(cursorOffset)) {
result.addAll(expandToWholeLine(editorText, thenRange, false));
}
}
result.addAll(expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), statement.getTextRange().getEndOffset()), false));
final PsiStatement branch = statement.getElseBranch();
if (branch instanceof PsiIfStatement) {
PsiIfStatement elseIf = (PsiIfStatement) branch;
final PsiKeyword element = elseIf.getElseElement();
if (element != null) {
final PsiStatement elseThen = elseIf.getThenBranch();
if (elseThen != null) {
result.addAll(expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), elseThen.getTextRange().getEndOffset()), false));
}
}
}
}
return result;
}
use of com.intellij.psi.PsiKeyword in project intellij-community by JetBrains.
the class ThrowsUsageTargetProvider method getTargets.
@Override
@Nullable
public UsageTarget[] getTargets(Editor editor, final PsiFile file) {
if (editor == null || file == null)
return null;
PsiElement element = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()));
if (element == null)
return null;
if (element instanceof PsiKeyword && PsiKeyword.THROWS.equals(element.getText())) {
return new UsageTarget[] { new PsiElement2UsageTargetAdapter(element) };
}
final PsiElement parent = element.getParent();
if (parent instanceof PsiThrowStatement) {
return new UsageTarget[] { new PsiElement2UsageTargetAdapter(parent) };
}
return null;
}
use of com.intellij.psi.PsiKeyword in project android by JetBrains.
the class Modifier method ParseModifierList.
public static int ParseModifierList(@NotNull PsiModifierList modList) {
int modifierBits = Modifier.PRIVATE;
if (modList != null) {
for (PsiElement pe : modList.getChildren()) {
if (pe instanceof PsiKeyword) {
PsiKeyword curWord = (PsiKeyword) pe;
if (curWord.textMatches("public")) {
modifierBits &= ~0x3;
modifierBits |= Modifier.PUBLIC;
} else if (curWord.textMatches("private")) {
modifierBits &= ~0x3;
modifierBits |= Modifier.PRIVATE;
} else if (curWord.textMatches("final")) {
modifierBits |= Modifier.FINAL;
} else if (curWord.textMatches("abstract")) {
modifierBits |= Modifier.ABSTRACT;
} else if (curWord.textMatches("interface")) {
modifierBits |= Modifier.INTERFACE;
} else if (curWord.textMatches("native")) {
modifierBits |= Modifier.NATIVE;
} else if (curWord.textMatches("protected")) {
modifierBits &= ~0x3;
modifierBits |= Modifier.PROTECTED;
} else if (curWord.textMatches("static")) {
modifierBits |= Modifier.STATIC;
} else if (curWord.textMatches("synchronized")) {
modifierBits |= Modifier.SYNCHRONIZED;
} else if (curWord.textMatches("transient")) {
modifierBits |= Modifier.TRANSIENT;
} else if (curWord.textMatches("volatile")) {
modifierBits |= Modifier.VOLATILE;
} else if (curWord.textMatches("strictfp")) {
modifierBits |= Modifier.STRICTFP;
} else if (curWord.textMatches("annotation")) {
modifierBits |= Modifier.ANNOTATION;
} else if (curWord.textMatches("enum")) {
modifierBits |= Modifier.ENUM;
}
}
}
}
return modifierBits;
}
use of com.intellij.psi.PsiKeyword in project oxy-template-support-plugin by mutant-industries.
the class GlobalVariableTypeProvider method getTypeFromProvider.
@Nullable
private JSType getTypeFromProvider(@NotNull PsiClass provider) {
PsiMethod[] provideMethods = provider.findMethodsByName(PROVIDE_METHOD_NAME, true);
PsiElement elementAt;
PsiReturnStatement returnStatement;
if (provideMethods.length < 1 || (returnStatement = PsiTreeUtil.findChildOfType(provideMethods[0], PsiReturnStatement.class)) == null || !((elementAt = returnStatement.getFirstChild()) instanceof PsiKeyword) || !((elementAt = elementAt.getNextSibling()) instanceof PsiWhiteSpace)) {
return null;
}
elementAt = elementAt.getNextSibling();
if (elementAt instanceof PsiExpression) {
return InnerJsJavaTypeConverter.getPsiElementJsType(elementAt);
}
return null;
}
Aggregations