本文整理汇总了Java中com.intellij.psi.PsiElementFactory类的典型用法代码示例。如果您正苦于以下问题:Java PsiElementFactory类的具体用法?Java PsiElementFactory怎么用?Java PsiElementFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiElementFactory类属于com.intellij.psi包,在下文中一共展示了PsiElementFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateConvertMethod
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
protected void generateConvertMethod(PsiElementFactory factory, PsiClass cls, ClassEntity classEntity) {
if (cls == null || cls.getName() == null) {
return;
}
if (Config.getInstant().isObjectFromData()) {
createMethod(factory, Config.getInstant().getObjectFromDataStr().replace("$ClassName$", cls.getName()).trim(), cls);
}
if (Config.getInstant().isObjectFromData1()) {
createMethod(factory, Config.getInstant().getObjectFromDataStr1().replace("$ClassName$", cls.getName()).trim(), cls);
}
if (Config.getInstant().isArrayFromData()) {
createMethod(factory, Config.getInstant().getArrayFromDataStr().replace("$ClassName$", cls.getName()).trim(), cls);
}
if (Config.getInstant().isArrayFromData1()) {
createMethod(factory, Config.getInstant().getArrayFromData1Str().replace("$ClassName$", cls.getName()).trim(), cls);
}
}
示例2: createMethod
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
protected void createMethod(PsiElementFactory factory, String method, PsiClass cls) {
Try.run(new Try.TryListener() {
@Override
public void run() {
cls.add(factory.createMethodFromText(method, cls));
}
@Override
public void runAgain() {
}
@Override
public void error() {
}
});
}
示例3: generateField
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
protected void generateField(PsiElementFactory factory, FieldEntity fieldEntity, PsiClass cls, ClassEntity classEntity) {
if (fieldEntity.isGenerate()) {
Try.run(new Try.TryListener() {
@Override
public void run() {
cls.add(factory.createFieldFromText(generateFieldText(classEntity, fieldEntity, null), cls));
}
@Override
public void runAgain() {
fieldEntity.setFieldName(FieldHelper.generateLuckyFieldName(fieldEntity.getFieldName()));
cls.add(factory.createFieldFromText(generateFieldText(classEntity, fieldEntity, Constant.FIXME), cls));
}
@Override
public void error() {
cls.addBefore(factory.createCommentFromText("// FIXME generate failure field " + fieldEntity.getFieldName(), cls), cls.getChildren()[0]);
}
});
}
}
示例4: FieldsDialog
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
public FieldsDialog(ConvertBridge.Operator operator, ClassEntity classEntity,
PsiElementFactory factory, PsiClass psiClass, PsiClass aClass, PsiFile file, Project project
, String generateClassStr) {
this.operator = operator;
this.factory = factory;
this.aClass = aClass;
this.file = file;
this.project = project;
this.psiClass = psiClass;
this.generateClassStr = generateClassStr;
setContentPane(contentPane);
setTitle("Virgo Model");
getRootPane().setDefaultButton(buttonOK);
this.setAlwaysOnTop(true);
initListener(classEntity, generateClassStr);
}
示例5: addAnnotationToPackageInfo
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
private void addAnnotationToPackageInfo(Project project, PsiJavaFile packageInfoFile) {
if (!FileModificationService.getInstance().preparePsiElementForWrite(packageInfoFile)) {
return;
}
PsiPackageStatement packageStatement = packageInfoFile.getPackageStatement();
if (packageStatement == null) {
return;
}
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiAnnotation annotation = factory.createAnnotationFromText("@" + annotationForTypeQualifierFqn,
packageInfoFile.getContext());
PsiElement addedAnnotation = packageInfoFile.addBefore(annotation, packageStatement);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(addedAnnotation);
removeRedundantAnnotationsInPackage(project, packageInfoFile.getContainingDirectory().getFiles(), annotation);
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:19,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java
示例6: findAnnotations
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
static List<String> findAnnotations(PsiModifierListOwner element, boolean nullable) {
if (overridesSuper(element)) {
return Collections.emptyList();
}
List<String> annotations = new ArrayList<>();
Project project = element.getProject();
PsiModifierList modifierList = element.getModifierList();
List<String> nullabilityAnnotations = nullable
? NullableNotNullManager.getInstance(project).getNullables()
: NullableNotNullManager.getInstance(project).getNotNulls();
for (String notNullAnnotationFqn : nullabilityAnnotations) {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiAnnotation annotation = factory.createAnnotationFromText("@" + notNullAnnotationFqn, null);
PsiAnnotation.TargetType[] targetTypes = getTargetsForLocation(modifierList);
if (isNullabilityAnnotationForTypeQualifierDefault(annotation, nullable, targetTypes)) {
annotations.add(annotation.getQualifiedName());
}
}
return annotations;
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:22,代码来源:NullabilityAnnotationsWithTypeQualifierDefault.java
示例7: makePsiMethod
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
private PsiMethod makePsiMethod( AbstractSrcMethod method, PsiClass psiClass )
{
PsiElementFactory elementFactory = JavaPsiFacade.getInstance( psiClass.getProject() ).getElementFactory();
StringBuilder sb = new StringBuilder();
method.render( sb, 0 );
try
{
return elementFactory.createMethodFromText( sb.toString(), psiClass );
}
catch( IncorrectOperationException ioe )
{
// the text of the method does not conform to method grammar, probably being edited in an IJ editor,
// ignore these since the editor provides error information
return null;
}
}
示例8: actionPerformed
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
// 获取编辑器中的文件
Project project = e.getData(PlatformDataKeys.PROJECT);
Editor editor = e.getData(PlatformDataKeys.EDITOR);
PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
// 获取当前类
PsiClass targetClass = getTargetClass(editor, file);
// 获取元素操作的工厂类
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
// 生成代码
new LayoutCreator(project, targetClass, factory, file).execute();
}
示例9: JavaCoreProjectEnvironment
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
public JavaCoreProjectEnvironment(Disposable parentDisposable, CoreApplicationEnvironment applicationEnvironment) {
super(parentDisposable, applicationEnvironment);
myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myPsiManager));
myProject.registerService(JavaPsiImplementationHelper.class, createJavaPsiImplementationHelper());
myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myPsiManager));
myProject.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension());
myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myMessageBus));
myProject.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade());
myProject.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager());
myPackageIndex = createCorePackageIndex();
myProject.registerService(PackageIndex.class, myPackageIndex);
myFileManager = createCoreFileManager();
myProject.registerService(JavaFileManager.class, myFileManager);
JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject, myPsiManager, myFileManager, myMessageBus);
myProject.registerService(JavaPsiFacade.class, javaPsiFacade);
}
示例10: getDescriptorEvaluation
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
@Override
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(context.getProject()).getElementFactory();
String fieldName;
if(isStatic()) {
String typeName = myField.declaringType().name().replace('$', '.');
typeName = DebuggerTreeNodeExpression.normalize(typeName, PositionUtil.getContextElement(context), context.getProject());
fieldName = typeName + "." + getName();
}
else {
//noinspection HardCodedStringLiteral
fieldName = isOuterLocalVariableValue()? StringUtil.trimStart(getName(), OUTER_LOCAL_VAR_FIELD_PREFIX) : "this." + getName();
}
try {
return elementFactory.createExpressionFromText(fieldName, null);
}
catch (IncorrectOperationException e) {
throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", getName()), e);
}
}
示例11: doFix
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
@Override
protected void doFix(Project project, ProblemDescriptor descriptor)
throws IncorrectOperationException {
final PsiElement element = descriptor.getPsiElement();
final String text = element.getText();
final int max = text.length() - 1;
if (max < 1) {
return;
}
int index = 0;
while (index < max && (text.charAt(index) == '0' || text.charAt(index) == '_')) {
index++;
}
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final PsiElementFactory factory = psiFacade.getElementFactory();
final String textWithoutLeadingZeros = text.substring(index);
final PsiExpression decimalNumber =
factory.createExpressionFromText(textWithoutLeadingZeros,
element);
element.replace(decimalNumber);
}
示例12: getParameterTypes
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
@Override
public PsiType[] getParameterTypes() {
ArrayList<PsiType> types = new ArrayList<PsiType>();
PsiManagerEx manager = getManager();
GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
for (GrDocMethodParameter parameter : getParameters()) {
GrDocReferenceElement typeElement = parameter.getTypeElement();
try {
PsiType type = factory.createTypeFromText(typeElement.getText(), this);
type = TypesUtil.boxPrimitiveType(type, manager, scope);
types.add(type);
} catch (IncorrectOperationException e) {
LOG.info(e);
types.add(null);
}
}
return types.toArray(PsiType.createArray(types.size()));
}
示例13: readMethod
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
@Override
public void readMethod(PsiCodeBlock methodBody, PsiElementFactory factory, PsiField field) {
if (null == methodBody) {
return;
}
String fieldName = field.getName();
String parameterType = ((PsiClassReferenceType) field.getType()).getParameters()[0].getPresentableText();
// // phones = new ArrayList<>();
// // in.readTypedList(phones, Phone.CREATOR);
// methodBody.add(factory.createStatementFromText(fieldName + " = new ArrayList<" + parameterType + ">();", null));
// methodBody.add(factory.createStatementFromText("in.readTypedList(" + fieldName + ", " + parameterType + ".CREATOR);", null));
// phones = in.createTypedArrayList(Phone.CREATOR);
methodBody.add(factory.createStatementFromText(fieldName + " = in.createTypedArrayList(" + parameterType + ".CREATOR);", null));
}
示例14: testQuickFix_classWithNullaryConstructor
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
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]));
}
示例15: testQuickFix_classWithNonNullaryConstructor
import com.intellij.psi.PsiElementFactory; //导入依赖的package包/类
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]));
}