private ClsElementImpl calculateChild() { if(PsiJavaParserFacadeImpl.getPrimitiveType(myTypeText) != null) { return null; } if(isArray()) { return myVariance == VARIANCE_NONE ? new ClsTypeElementImpl(this, myTypeText.substring(0, myTypeText.length() - 2), myVariance) : new ClsTypeElementImpl(this, myTypeText, VARIANCE_NONE); } if(isVarArgs()) { return new ClsTypeElementImpl(this, myTypeText.substring(0, myTypeText.length() - 3), myVariance); } return myVariance == VARIANCE_INVARIANT ? null : new ClsJavaCodeReferenceElementImpl(this, myTypeText); }
@Nullable public static PrimitiveValue getInnerPrimitiveValue(ObjectReference value) { ReferenceType type = value.referenceType(); Field valueField = type.fieldByName("value"); if(valueField != null) { Value primitiveValue = value.getValue(valueField); if(primitiveValue instanceof PrimitiveValue) { LOG.assertTrue(type.name().equals(PsiJavaParserFacadeImpl.getPrimitiveType(primitiveValue.type().name()).getBoxedTypeName())); return (PrimitiveValue) primitiveValue; } } return null; }
private ClsElementImpl calculateChild() { if (PsiJavaParserFacadeImpl.getPrimitiveType(myTypeText) != null) { return null; } if (isArray()) { return myVariance == VARIANCE_NONE ? new ClsTypeElementImpl(this, myTypeText.substring(0, myTypeText.length() - 2), myVariance) : new ClsTypeElementImpl(this, myTypeText, VARIANCE_NONE); } if (isVarArgs()) { return new ClsTypeElementImpl(this, myTypeText.substring(0, myTypeText.length() - 3), myVariance); } return myVariance == VARIANCE_INVARIANT ? null : new ClsJavaCodeReferenceElementImpl(this, myTypeText); }
public static PsiExpression createExpressionFromText(final String exprText, final PsiManager manager, final ClsElementImpl parent) { final PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(manager.getProject()).getParserFacade(); final PsiJavaFile dummyJavaFile = ((PsiJavaParserFacadeImpl)parserFacade).getDummyJavaFile(); // to resolve classes from java.lang final PsiExpression expr; try { expr = parserFacade.createExpressionFromText(exprText, dummyJavaFile); } catch (IncorrectOperationException e) { LOG.error(e); return null; } return psiToClsExpression(expr, parent); }
@NotNull public static PsiAnnotationMemberValue createMemberValueFromText(final String text, final PsiManager manager, final ClsElementImpl parent) { final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); final PsiJavaFile context = ((PsiJavaParserFacadeImpl)factory).getDummyJavaFile(); // to resolve classes from java.lang final LanguageLevel level = PsiUtil.getLanguageLevel(parent); final DummyHolder holder = DummyHolderFactory.createHolder(manager, new JavaDummyElement(text, ANNOTATION_VALUE, level), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiAnnotationMemberValue)) { LOG.error("Could not parse initializer:'" + text + "'"); return null; } return getMemberValue(element, parent); }
@NotNull public static Pair<PsiElement, PsiType> getPsiClassAndType(@Nullable String className, Project project) { PsiElement contextClass = null; PsiType contextType = null; if(!StringUtil.isEmpty(className)) { PsiPrimitiveType primitiveType = PsiJavaParserFacadeImpl.getPrimitiveType(className); if(primitiveType != null) { contextClass = JavaPsiFacade.getInstance(project).findClass(primitiveType.getBoxedTypeName(), GlobalSearchScope.allScope(project)); contextType = primitiveType; } else { contextClass = findClass(className, project, GlobalSearchScope.allScope(project)); if(contextClass != null) { contextClass = contextClass.getNavigationElement(); } if(contextClass instanceof PsiCompiledElement) { contextClass = ((PsiCompiledElement) contextClass).getMirror(); } contextType = getType(className, project); } if(contextClass != null) { contextClass.putUserData(PSI_TYPE_KEY, contextType); } } return Pair.create(contextClass, contextType); }