本文整理汇总了Java中com.intellij.psi.PsiElementFactory.createExpressionFromText方法的典型用法代码示例。如果您正苦于以下问题:Java PsiElementFactory.createExpressionFromText方法的具体用法?Java PsiElementFactory.createExpressionFromText怎么用?Java PsiElementFactory.createExpressionFromText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiElementFactory
的用法示例。
在下文中一共展示了PsiElementFactory.createExpressionFromText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
示例3: createLoggerField
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
private LombokLightFieldBuilder createLoggerField(@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation) {
final Project project = psiClass.getProject();
final PsiManager manager = psiClass.getContainingFile().getManager();
final PsiElementFactory psiElementFactory = JavaPsiFacade.getElementFactory(project);
final PsiType psiLoggerType = psiElementFactory.createTypeFromText(loggerType, psiClass);
LombokLightFieldBuilder loggerField = new LombokLightFieldBuilder(manager, getLoggerName(psiClass), psiLoggerType)
.withContainingClass(psiClass)
.withModifier(PsiModifier.FINAL)
.withModifier(PsiModifier.PRIVATE)
.withNavigationElement(psiAnnotation);
if (isLoggerStatic(psiClass)) {
loggerField.withModifier(PsiModifier.STATIC);
}
final String loggerInitializerParameter = createLoggerInitializeParameter(psiClass, psiAnnotation);
final PsiExpression initializer = psiElementFactory.createExpressionFromText(String.format(loggerInitializer, loggerInitializerParameter), psiClass);
loggerField.setInitializer(initializer);
return loggerField;
}
示例4: invoke
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
if(!FileModificationService.getInstance().prepareFileForWrite(file))
{
return;
}
myConjuncts.remove(myConjunct);
myConjuncts.add(0, myConjunct);
final String intersectionTypeText = StringUtil.join(myConjuncts, new Function<PsiTypeElement, String>()
{
@Override
public String fun(PsiTypeElement element)
{
return element.getText();
}
}, " & ");
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
final PsiTypeCastExpression fixedCast = (PsiTypeCastExpression) elementFactory.createExpressionFromText("(" +
intersectionTypeText + ") a", myCastTypeElement);
final PsiTypeElement fixedCastCastType = fixedCast.getCastType();
LOG.assertTrue(fixedCastCastType != null);
final PsiElement flippedTypeElement = myCastTypeElement.replace(fixedCastCastType);
CodeStyleManager.getInstance(project).reformat(flippedTypeElement);
}
示例5: replaceExpressionWithReferenceTo
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
protected static void replaceExpressionWithReferenceTo(
@NotNull PsiExpression expression,
@NotNull PsiMember target)
throws IncorrectOperationException {
final Project project = expression.getProject();
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final PsiElementFactory factory = psiFacade.getElementFactory();
final PsiReferenceExpression newExpression = (PsiReferenceExpression)
factory.createExpressionFromText("xxx", expression);
final PsiReferenceExpression replacementExpression =
(PsiReferenceExpression)expression.replace(newExpression);
final PsiElement element = replacementExpression.bindToElement(target);
final JavaCodeStyleManager styleManager =
JavaCodeStyleManager.getInstance(project);
styleManager.shortenClassReferences(element);
}
示例6: replaceExpressionAndShorten
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
protected static void replaceExpressionAndShorten(
@NotNull PsiExpression expression,
@NotNull @NonNls String newExpressionText)
throws IncorrectOperationException {
final Project project = expression.getProject();
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final PsiElementFactory factory = psiFacade.getElementFactory();
final PsiExpression newExpression =
factory.createExpressionFromText(newExpressionText, expression);
final PsiElement replacementExp = expression.replace(newExpression);
final JavaCodeStyleManager javaCodeStyleManager =
JavaCodeStyleManager.getInstance(project);
javaCodeStyleManager.shortenClassReferences(replacementExp);
final CodeStyleManager styleManager =
CodeStyleManager.getInstance(project);
styleManager.reformat(replacementExp);
}
示例7: getSubexpression
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
@Nullable
static PsiPolyadicExpression getSubexpression(PsiPolyadicExpression expression, PsiJavaToken token) {
final PsiExpression[] operands = expression.getOperands();
if (operands.length == 2) {
return expression;
}
for (int i = 1; i < operands.length; i++) {
final PsiExpression operand = operands[i];
final PsiJavaToken currentToken = expression.getTokenBeforeOperand(operand);
if (currentToken == token) {
final String binaryExpressionText = operands[i - 1].getText() + ' ' + token.getText() + ' ' + operand.getText();
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(expression.getProject());
return (PsiPolyadicExpression)factory.createExpressionFromText(binaryExpressionText, expression);
}
}
return null;
}
示例8: getChildValueExpression
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
@Override
public PsiExpression getChildValueExpression(DebuggerTreeNode node, DebuggerContext context)
{
LOG.assertTrue(node.getDescriptor() instanceof ArrayElementDescriptorImpl, node.getDescriptor().getClass().getName());
ArrayElementDescriptorImpl descriptor = (ArrayElementDescriptorImpl) node.getDescriptor();
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
try
{
return elementFactory.createExpressionFromText("this[" + descriptor.getIndex() + "]", elementFactory.getArrayClass(LanguageLevel.HIGHEST));
}
catch(IncorrectOperationException e)
{
LOG.error(e);
return null;
}
}
示例9: getChildValueExpression
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
@Override
public PsiElement getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) throws EvaluateException
{
FieldDescriptor fieldDescriptor = (FieldDescriptor) node.getDescriptor();
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
try
{
return elementFactory.createExpressionFromText(fieldDescriptor.getField().name(), DebuggerUtils.findClass(fieldDescriptor.getObject().referenceType().name(), context.getProject(),
context.getDebugProcess().getSearchScope()));
}
catch(IncorrectOperationException e)
{
throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", fieldDescriptor.getField().name()), null);
}
}
示例10: getDescriptorEvaluation
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
@Override
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException
{
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myProject).getElementFactory();
String fieldName;
if(isStatic())
{
String typeName = myField.declaringType().name().replace('$', '.');
typeName = DebuggerTreeNodeExpression.normalize(typeName, PositionUtil.getContextElement(context), myProject);
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: getChildValueExpression
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
public PsiExpression getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) {
LOG.assertTrue(node.getDescriptor() instanceof ArrayElementDescriptorImpl, node.getDescriptor().getClass().getName());
ArrayElementDescriptorImpl descriptor = (ArrayElementDescriptorImpl)node.getDescriptor();
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
try {
LanguageLevel languageLevel = LanguageLevelProjectExtension.getInstance(node.getProject()).getLanguageLevel();
return elementFactory.createExpressionFromText("this[" + descriptor.getIndex() + "]", elementFactory.getArrayClass(languageLevel));
}
catch (IncorrectOperationException e) {
LOG.error(e);
return null;
}
}
示例12: getChildValueExpression
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
@Override
public PsiElement getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) throws EvaluateException {
FieldDescriptor fieldDescriptor = (FieldDescriptor)node.getDescriptor();
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
try {
return elementFactory.createExpressionFromText(fieldDescriptor.getField().name(), DebuggerUtils.findClass(
fieldDescriptor.getObject().referenceType().name(), context.getProject(), context.getDebugProcess().getSearchScope())
);
}
catch (IncorrectOperationException e) {
throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", fieldDescriptor.getField().name()), null);
}
}
示例13: getDescriptorEvaluation
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(context.getProject()).getElementFactory();
try {
return elementFactory.createExpressionFromText("this[" + myIndex + "]", null);
}
catch (IncorrectOperationException e) {
throw new EvaluateException(e.getMessage(), e);
}
}
示例14: getDescriptorEvaluation
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(context.getProject()).getElementFactory();
try {
return elementFactory.createExpressionFromText(getName(), PositionUtil.getContextElement(context));
}
catch (IncorrectOperationException e) {
throw new EvaluateException(DebuggerBundle.message("error.invalid.local.variable.name", getName()), e);
}
}
示例15: getDescriptorEvaluation
import com.intellij.psi.PsiElementFactory; //导入方法依赖的package包/类
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(context.getProject()).getElementFactory();
try {
return elementFactory.createExpressionFromText("this", null);
}
catch (IncorrectOperationException e) {
throw new EvaluateException(e.getMessage(), e);
}
}