PSI Questions and answers
PurgedPsiQuestionsAndAnswers
PsiDocumentation
-- BrighamBorischnokov - 09 Sep 2005
Hi! How can I create PsiWhiteSpace? elements? There seems to be no corresponding factory method..
-- OleMatzura - 01 Dec 2002
Just curious, why would you need that?
-- ValentinKipiatkov - 04 Dec 2002
> Just curious, why would you need that?
I also looked for such factory method. You may need it for reformat tasks (e.g. insert a white space element or replace one white space element with another).
-- TimurZambalayev - 03 Jun 2003
How can you get a reference to the JTree in the Project Window?
-- CharlesDeCroes - 09 Dec 2002
Is it related to PSI? I guess it isn't.
-- ValentinKipiatkov - 02 Jan 2003
When I use EditorFactory?.getInstance().createViewer to create a viewer for my java file, the method returns an instance of an editor which when shown doesn't not highlight java keywords but even though it hightlights class fields. Why is that? Besides it highlights class fields only in case the file has been already opened at least once for editing. That is a very strange side effect, isn't it?
-- KeshSibilev - 24 Jan 2003
Is there a factory method for creating PsiJavaTokens? (e.g. commas, braces)? I'm attempting to insert a new element into a PsiArrayInitializerExpression? but can not determine how to either have the PsiArrayInitializerExpression?'s add function insert the comma for me or to do it manually. The ability to construct PsiWhiteSpace? programatically would also be useful (for inserting a newline after the array element).
-- BrianMcDonald - 14 Feb 2003
I too would like to know how to either create a PsiWhiteSpace? element and replace an existing one with it, or modify the contents of an existing PsiWhiteSpace? element. Am trying to write a code beautifier
or reformatter plugin, and essentially need the ability to alter white space.
May I also ask, how would one go about reordering two PsiElements?, e.g. adjacent PsiDeclarationStatements??
-- DaveKriewall - 04 Mar 2003
How to programmatically change IDEA project classpath?
Hi! I need to add/remove entries to/from IDEA project classpath from plugin code. Is it possible to do that, using OpenAPI or PsiAPI?? ProjectRootManager? has methods to retrieve classpath entries, but does not provide a way to manipulate it. I hope I havent overlooked the API call for that. It would be nice to be able to do so, otherwise users have to go ProjectOptions?/Paths/Classpath/Browse to find the correct entries, whereas this information is available in the plugin code. Thanks in advance!
-- PavlinZahariev - 07 Mar 2003
Hi! I have a fairly basic question. I am writing a tool to help out with some of our code generation and ran into a problem working with imports using the PSI. I am creating statements from text (PsiElementFactory?.createStatementFromText()) and would like to add imports for the classes that I use within the statements. Right now I am using the fully qualified name. What is the best way to go about this? Thanks!
-- JohnHampton - 20 Mar 2003
PSI handles imports for classes automatically. Use PsiElementFactory?.createClassReference, create some dummy references in your text, and then replace them. Alternatively, put fq names to text, and then use CodeStyleManagager?.shortenClassReferences.
-- DmitryLomov - 14 Jun 2003
Here's a bit of code I've used to solve your problem. The code chunk uses a couple helper functions at the bottom. In my code example the 'formatter' is the class that you are using in new statement.
// craete import statement for formatter if necessary
PsiElement file = getFile(psiElement);
PsiElement[] topChildren = file.getContainingFile().getChildren();
for (int i = 0; i < topChildren.length; i++) {
PsiElement element = topChildren[i];
if (element instanceof PsiImportList) {
PsiImportList list = (PsiImportList)element;
addImportIfNecessary(list, formatterPkg, formatterFQName, psiFactory, psiElement, project);
break;
}
}
private static void addImportIfNecessary(PsiImportList list, String formatterPkg, String formatterFQName,
PsiElementFactory psiFactory, PsiElement psiElement, final Project project) throws IncorrectOperationException {
PsiImportStatement statement = list.findOnDemandImportStatement(formatterPkg);
if (statement == null) {
// didn't find pkg
statement = list.findSingleClassImportStatement(formatterFQName);
}
if (statement == null) {
// didn't find fqn
PsiElement newImport = psiFactory.createImportStatement(psiElement.getManager().findClass(formatterFQName));
newImport = list.add(newImport);
newImport = CodeStyleManager.getInstance(project).reformat(newImport);
}
}
private static PsiElement getFile(PsiElement selectedClass) {
PsiElement file = selectedClass;
while (!(file instanceof PsiJavaFile)) file = file.getParent();
return file;
}
-- BrianMcDonald - 26 Mar 2003
This would we a really nice thing to have...
-- TimmRoser - 26.3.2003
com.intellij.psi.codeStyle.CodeStyleManager.isUseDefaultDodeStyleScheme() should probably be changed to isUseDefaultCodeStyleScheme(), right?
-- TimurZambalayev - May 14, 2003
Intentions API question.
The newly opened intentions API looks about like I expected. The only method I didn't anticipate was Intention.getFamilyName(). As near as I can tell, though, it doesn't do anything. Is this just a future hook for some hypothetical "Intention Preferences" GUI, or is there something else going on?
-- DaveGriffith - 23 May 2003
See javadoc at IntentionPlugins
-- DmitryLomov - 03 Jun 2003
If I programmatically change the format of a file it takes a bit of time for IDEA to refresh the file and show the changes. Is there a way to programmatically force this refresh to occur?
-- SalCampana - 02 Jun 2003
CategoryQuestionsAndAnswers
|
|