use of com.intellij.psi.PsiElementFactory 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.PsiElementFactory in project intellij-community by JetBrains.
the class InstanceValueDescriptor method getDescriptorEvaluation.
@Override
public PsiExpression getDescriptorEvaluation(DebuggerContext debuggerContext) throws EvaluateException {
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myProject).getElementFactory();
ObjectReference ref = ((ObjectReference) getValue());
String name = NamesUtils.getUniqueName(ref).replace("@", "");
String presentation = String.format("%s_DebugLabel", name);
return elementFactory.createExpressionFromText(presentation, ContextUtil.getContextElement(debuggerContext));
}
use of com.intellij.psi.PsiElementFactory in project kotlin by JetBrains.
the class KotlinFindClassUsagesDialog method getRepresentingPsiClass.
@NotNull
private static PsiClass getRepresentingPsiClass(@NotNull KtClassOrObject classOrObject) {
PsiClass lightClass = toLightClass(classOrObject);
if (lightClass != null)
return lightClass;
// TODO: Remove this code when light classes are generated for builtins
PsiElementFactory factory = PsiElementFactory.SERVICE.getInstance(classOrObject.getProject());
String name = classOrObject.getName();
if (name == null || name.isEmpty()) {
name = "Anonymous";
}
PsiClass javaClass;
if (classOrObject instanceof KtClass) {
KtClass klass = (KtClass) classOrObject;
javaClass = !klass.isInterface() ? factory.createClass(name) : klass.isAnnotation() ? factory.createAnnotationType(name) : factory.createInterface(name);
} else {
javaClass = factory.createClass(name);
}
//noinspection ConstantConditions
javaClass.getModifierList().setModifierProperty(PsiModifier.FINAL, !(classOrObject instanceof KtClass && KtPsiUtilKt.isInheritable((KtClass) classOrObject)));
javaClass.putUserData(ORIGINAL_CLASS, classOrObject);
return javaClass;
}
use of com.intellij.psi.PsiElementFactory in project google-cloud-intellij by GoogleCloudPlatform.
the class ConstructorInspectionTest method testQuickFix_classWithNullaryConstructor.
public void testQuickFix_classWithNullaryConstructor() {
ProblemDescriptorImpl problemDescriptorMock = mock(ProblemDescriptorImpl.class);
MockitoAnnotations.initMocks(this);
PsiElementFactory factory = JavaPsiFacade.getInstance(myFixture.getProject()).getElementFactory();
PsiClass psiClass = factory.createClass(getName());
PsiMethod nullaryConstructor = factory.createMethodFromText("public " + psiClass.getName() + "() { }", psiClass);
psiClass.addAfter(nullaryConstructor, null);
ConstructorInspection constructorInspection = new ConstructorInspection();
ConstructorInspection.MyQuickFix myQuickFix = constructorInspection.new MyQuickFix(psiClass);
myQuickFix.applyFix(myFixture.getProject(), problemDescriptorMock);
Assert.assertEquals(1, psiClass.getConstructors().length);
Assert.assertTrue(EndpointUtilities.isPublicNullaryConstructor(psiClass.getConstructors()[0]));
}
use of com.intellij.psi.PsiElementFactory in project google-cloud-intellij by GoogleCloudPlatform.
the class ConstructorInspectionTest method testQuickFix_classWithNonNullaryConstructor.
public void testQuickFix_classWithNonNullaryConstructor() {
ProblemDescriptorImpl problemDescriptorMock = mock(ProblemDescriptorImpl.class);
MockitoAnnotations.initMocks(this);
PsiElementFactory factory = JavaPsiFacade.getInstance(myFixture.getProject()).getElementFactory();
PsiClass psiClass = factory.createClass(getName());
PsiMethod nullaryConstructor = factory.createMethodFromText("public " + psiClass.getName() + "(String param) { }", psiClass);
psiClass.addAfter(nullaryConstructor, null);
ConstructorInspection constructorInspection = new ConstructorInspection();
ConstructorInspection.MyQuickFix myQuickFix = constructorInspection.new MyQuickFix(psiClass);
myQuickFix.applyFix(myFixture.getProject(), problemDescriptorMock);
Assert.assertEquals(2, psiClass.getConstructors().length);
Assert.assertTrue(EndpointUtilities.isPublicNullaryConstructor(psiClass.getConstructors()[0]));
}
Aggregations