PsiMethod method = ...; // get the PsiMethod object int count = 0; // initialize the counter method.putUserData("invocationCount", count); // later on, when the method is invoked: count = method.getUserData("invocationCount"); count++; method.putUserData("invocationCount", count);
PsiFile file = ...; // get the PsiFile object String extension = getFileExtension(file.getName()); file.putUserData("extension", extension);In this example, we attach the file extension to the file's PSI element using the key "extension". We can then retrieve the extension as needed. Package/library: `com.intellij.psi`