use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class JavaFormatterTest method testSpacesIncode.
public void testSpacesIncode() throws Exception {
final JavaPsiFacade facade = getJavaFacade();
final LanguageLevel level = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
try {
doTextTest("class C<Y, X> {\n" + "}", "class C<Y, X> {\n" + "}");
getSettings().SPACE_BEFORE_METHOD_LBRACE = true;
getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true;
doTextTest("enum En {\n" + " A(10) {},\n" + " B(10) {},\n" + " C(10);\n" + "\n" + " En(int i) { }\n" + "}", "enum En {\n" + " A(10) {},\n" + " B(10) {},\n" + " C(10);\n" + "\n" + " En(int i) { }\n" + "}");
doTextTest("class C {\n" + " void foo (Map<?, String> s) {\n" + " Set<? extends Map<?, String>.Entry<?, String>> temp = s.entries();\n" + " }\n" + "}", "class C {\n" + " void foo(Map<?, String> s) {\n" + " Set<? extends Map<?, String>.Entry<?, String>> temp = s.entries();\n" + " }\n" + "}");
doTextTest("class B {\n" + " public final A<String> myDelegate = new A<String>();\n" + "\n" + " public List<? extends String> method1() {\n" + " return myDelegate.method1();\n" + " }\n" + "\n" + " public String method2(String t) {\n" + " return myDelegate.method2(t);\n" + " }\n" + "}", "class B {\n" + " public final A<String> myDelegate = new A<String>();\n" + "\n" + " public List<? extends String> method1() {\n" + " return myDelegate.method1();\n" + " }\n" + "\n" + " public String method2(String t) {\n" + " return myDelegate.method2(t);\n" + " }\n" + "}");
} finally {
LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(level);
}
}
use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class ChangeToEndOfLineCommentIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final PsiComment comment = (PsiComment) element;
final JavaPsiFacade manager = JavaPsiFacade.getInstance(comment.getProject());
final PsiElement parent = comment.getParent();
assert parent != null;
final PsiElementFactory factory = manager.getElementFactory();
final String commentText = comment.getText();
final PsiElement whitespace = comment.getNextSibling();
final String text = commentText.substring(2, commentText.length() - 2);
final String[] lines = text.split("\n");
for (int i = lines.length - 1; i >= 1; i--) {
final PsiComment nextComment = factory.createCommentFromText("//" + lines[i].trim() + '\n', parent);
parent.addAfter(nextComment, comment);
/* if (whitespace != null) {
final PsiElement newWhiteSpace =
factory.createWhiteSpaceFromText(whitespace.getText());
parent.addAfter(newWhiteSpace, comment);
} */
}
final PsiComment newComment = factory.createCommentFromText("//" + lines[0], parent);
comment.replace(newComment);
}
use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class ChangeToCStyleCommentIntention method processIntention.
@Override
public void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
final PsiComment selectedComment = (PsiComment) element;
PsiComment firstComment = selectedComment;
while (true) {
final PsiElement prevComment = getPrevNonWhiteSpace(firstComment);
if (!isEndOfLineComment(prevComment)) {
break;
}
firstComment = (PsiComment) prevComment;
}
final JavaPsiFacade manager = JavaPsiFacade.getInstance(selectedComment.getProject());
final PsiElementFactory factory = manager.getElementFactory();
String text = getCommentContents(firstComment);
final List<PsiElement> commentsToDelete = new ArrayList<>();
PsiElement nextComment = firstComment;
while (true) {
nextComment = getNextNonWhiteSpace(nextComment);
if (!isEndOfLineComment(nextComment)) {
break;
}
text += //to get the whitespace for proper spacing
nextComment.getPrevSibling().getText() + " " + getCommentContents((PsiComment) nextComment);
commentsToDelete.add(nextComment);
}
final PsiComment newComment = factory.createCommentFromText("/*" + text + " */", selectedComment.getParent());
firstComment.replace(newComment);
for (PsiElement commentToDelete : commentsToDelete) {
commentToDelete.delete();
}
}
use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class GradleDslAnnotator method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (element instanceof GrReferenceExpression) {
GrReferenceExpression referenceExpression = (GrReferenceExpression) element;
final GrExpression qualifier = ResolveUtil.getSelfOrWithQualifier(referenceExpression);
if (qualifier == null)
return;
if (qualifier instanceof GrReferenceExpression && ((GrReferenceExpression) qualifier).resolve() instanceof PsiClass)
return;
PsiType psiType = GradleResolverUtil.getTypeOf(qualifier);
if (psiType == null)
return;
if (InheritanceUtil.isInheritor(psiType, GradleCommonClassNames.GRADLE_API_NAMED_DOMAIN_OBJECT_COLLECTION)) {
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(element.getProject());
PsiClass defaultGroovyMethodsClass = javaPsiFacade.findClass(GroovyCommonClassNames.DEFAULT_GROOVY_METHODS, element.getResolveScope());
if (canBeMethodOf(referenceExpression.getReferenceName(), defaultGroovyMethodsClass))
return;
final String qualifiedName = TypesUtil.getQualifiedName(psiType);
final PsiClass containerClass = qualifiedName != null ? javaPsiFacade.findClass(qualifiedName, element.getResolveScope()) : null;
if (canBeMethodOf(referenceExpression.getReferenceName(), containerClass))
return;
PsiElement nameElement = referenceExpression.getReferenceNameElement();
if (nameElement != null) {
holder.createInfoAnnotation(nameElement, null).setTextAttributes(MAP_KEY);
}
}
}
}
use of com.intellij.psi.JavaPsiFacade in project intellij-community by JetBrains.
the class I18NInspectionTest method testEnum.
public void testEnum() throws Exception {
final JavaPsiFacade facade = getJavaFacade();
final LanguageLevel effectiveLanguageLevel = LanguageLevelProjectExtension.getInstance(facade.getProject()).getLanguageLevel();
LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(LanguageLevel.JDK_1_5);
try {
doTest();
} finally {
LanguageLevelProjectExtension.getInstance(facade.getProject()).setLanguageLevel(effectiveLanguageLevel);
}
}
Aggregations