use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class PsiElementFactoryImpl method createImportStatement.
@NotNull
@Override
public PsiImportStatement createImportStatement(@NotNull final PsiClass aClass) throws IncorrectOperationException {
if (aClass instanceof PsiAnonymousClass) {
throw new IncorrectOperationException("Cannot create import statement for anonymous class.");
} else if (aClass.getParent() instanceof PsiDeclarationStatement) {
throw new IncorrectOperationException("Cannot create import statement for local class.");
}
final PsiJavaFile aFile = createDummyJavaFile("import " + aClass.getQualifiedName() + ";");
final PsiImportStatementBase statement = extractImport(aFile, false);
return (PsiImportStatement) CodeStyleManager.getInstance(myManager.getProject()).reformat(statement);
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class PsiElementFactoryImpl method createParameter.
@NotNull
@Override
public PsiParameter createParameter(@NotNull final String name, @NotNull final PsiType type) throws IncorrectOperationException {
PsiUtil.checkIsIdentifier(myManager, name);
if (PsiType.NULL.equals(type)) {
throw new IncorrectOperationException("Cannot create parameter with type \"null\".");
}
final String text = type.getCanonicalText(true) + " " + name;
PsiParameter parameter = createParameterFromText(text, null);
final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myManager.getProject());
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, JavaCodeStyleSettingsFacade.getInstance(myManager.getProject()).isGenerateFinalParameters());
GeneratedMarkerVisitor.markGenerated(parameter);
parameter = (PsiParameter) JavaCodeStyleManager.getInstance(myManager.getProject()).shortenClassReferences(parameter);
return (PsiParameter) codeStyleManager.reformat(parameter);
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class PsiElementFactoryImpl method createCatchSection.
@NotNull
@Override
public PsiCatchSection createCatchSection(@NotNull final PsiType exceptionType, @NotNull final String exceptionName, @Nullable final PsiElement context) throws IncorrectOperationException {
if (!(exceptionType instanceof PsiClassType || exceptionType instanceof PsiDisjunctionType)) {
throw new IncorrectOperationException("Unexpected type:" + exceptionType);
}
@NonNls final String text = "catch (" + exceptionType.getCanonicalText(true) + " " + exceptionName + ") {}";
final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CATCH_SECTION, level(context)), context);
final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
if (!(element instanceof PsiCatchSection)) {
throw new IncorrectOperationException("Incorrect catch section '" + text + "'. Parsed element: " + element);
}
final Project project = myManager.getProject();
final JavaPsiImplementationHelper helper = JavaPsiImplementationHelper.getInstance(project);
helper.setupCatchBlock(exceptionName, exceptionType, context, (PsiCatchSection) element);
final CodeStyleManager styleManager = CodeStyleManager.getInstance(project);
final PsiCatchSection catchSection = (PsiCatchSection) styleManager.reformat(element);
GeneratedMarkerVisitor.markGenerated(catchSection);
return catchSection;
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class PsiElementFactoryImpl method createTypeParameter.
@NotNull
@Override
public PsiTypeParameter createTypeParameter(String name, PsiClassType[] superTypes) {
@NonNls StringBuilder builder = new StringBuilder();
builder.append("public <").append(name);
if (superTypes.length > 1 || superTypes.length == 1 && !superTypes[0].equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) {
builder.append(" extends ");
for (PsiClassType type : superTypes) {
if (type.equalsToText(CommonClassNames.JAVA_LANG_OBJECT))
continue;
builder.append(type.getCanonicalText(true)).append('&');
}
builder.delete(builder.length() - 1, builder.length());
}
builder.append("> void foo(){}");
try {
return createMethodFromText(builder.toString(), null).getTypeParameters()[0];
} catch (RuntimeException e) {
throw new IncorrectOperationException("type parameter text: " + builder.toString());
}
}
use of com.intellij.util.IncorrectOperationException in project intellij-community by JetBrains.
the class PsiElementFactoryImpl method createImportStaticStatement.
@NotNull
@Override
public PsiImportStaticStatement createImportStaticStatement(@NotNull final PsiClass aClass, @NotNull final String memberName) throws IncorrectOperationException {
if (aClass instanceof PsiAnonymousClass) {
throw new IncorrectOperationException("Cannot create import statement for anonymous class.");
} else if (aClass.getParent() instanceof PsiDeclarationStatement) {
throw new IncorrectOperationException("Cannot create import statement for local class.");
}
final PsiJavaFile aFile = createDummyJavaFile("import static " + aClass.getQualifiedName() + "." + memberName + ";");
final PsiImportStatementBase statement = extractImport(aFile, true);
return (PsiImportStaticStatement) CodeStyleManager.getInstance(myManager.getProject()).reformat(statement);
}
Aggregations