public ClsTypeElementImpl(@NotNull PsiElement parent, @NotNull String typeText, char variance) { myParent = parent; myTypeText = TypeInfo.internFrequentType(typeText); myVariance = variance; myChild = new AtomicNullableLazyValue<ClsElementImpl>() { @Override protected ClsElementImpl compute() { return calculateChild(); } }; myCachedType = new AtomicNotNullLazyValue<PsiType>() { @NotNull @Override protected PsiType compute() { return calculateType(); } }; }
@Override @NotNull public PsiType getType() { final PsiFieldStub stub = getStub(); if (stub != null) { PsiType type = SoftReference.dereference(myCachedType); if (type != null) return type; String typeText = TypeInfo.createTypeText(stub.getType(true)); try { type = JavaPsiFacade.getInstance(getProject()).getParserFacade().createTypeFromText(typeText, this); myCachedType = new SoftReference<PsiType>(type); return type; } catch (IncorrectOperationException e) { LOG.error(e); return null; } } myCachedType = null; return JavaSharedImplUtil.getType(getTypeElement(), getNameIdentifier()); }
public ClsTypeElementImpl(@NotNull PsiElement parent, @NotNull String typeText, char variance) { myParent = parent; myTypeText = TypeInfo.internFrequentType(typeText); myVariance = variance; myChild = new VolatileNullableLazyValue<ClsElementImpl>() { @Nullable @Override protected ClsElementImpl compute() { return calculateChild(); } }; myCachedType = new AtomicNotNullLazyValue<PsiType>() { @NotNull @Override protected PsiType compute() { return calculateType(); } }; }
@Override @Nullable public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { if(isSet(access, Opcodes.ACC_SYNTHETIC)) { return null; } if(name == null) { return null; } byte flags = PsiFieldStubImpl.packFlags(isSet(access, Opcodes.ACC_ENUM), isSet(access, Opcodes.ACC_DEPRECATED), false, false); TypeInfo type = fieldType(desc, signature); String initializer = constToString(value, type.text, false, myMapping); PsiFieldStub stub = new PsiFieldStubImpl(myResult, name, type, initializer, flags); PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packFieldFlags(access)); return new FieldAnnotationCollectingVisitor(modList, myMapping); }
private TypeInfo fieldType(String desc, String signature) { String type = null; if(signature != null) { try { type = SignatureParsing.parseTypeString(new StringCharacterIterator(signature), myMapping); } catch(ClsFormatException e) { if(LOG.isDebugEnabled()) { LOG.debug("source=" + mySource + " signature=" + signature, e); } } } if(type == null) { type = toJavaType(Type.getType(desc), myMapping); } return TypeInfo.fromString(type, false); }
@Override public void serialize(@NotNull final PsiMethodStub stub, @NotNull final StubOutputStream dataStream) throws IOException { dataStream.writeName(stub.getName()); TypeInfo.writeTYPE(dataStream, stub.getReturnTypeText(false)); dataStream.writeByte(((PsiMethodStubImpl)stub).getFlags()); if (stub.isAnnotationMethod()) { dataStream.writeName(stub.getDefaultValueText()); } }
@NotNull @Override public PsiMethodStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { StringRef name = dataStream.readName(); final TypeInfo type = TypeInfo.readTYPE(dataStream); byte flags = dataStream.readByte(); final StringRef defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readName() : null; return new PsiMethodStubImpl(parentStub, StringRef.toString(name), type, flags, StringRef.toString(defaultMethodValue)); }
@Override public PsiFieldStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) { final TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub); boolean isDeprecatedByComment = false; boolean hasDeprecatedAnnotation = false; boolean hasDocComment = false; String name = null; String initializer = null; boolean expectingInit = false; for (final LighterASTNode child : tree.getChildren(node)) { final IElementType type = child.getTokenType(); if (type == JavaDocElementType.DOC_COMMENT) { hasDocComment = true; isDeprecatedByComment = RecordUtil.isDeprecatedByDocComment(tree, child); } else if (type == JavaElementType.MODIFIER_LIST) { hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child); } else if (type == JavaTokenType.IDENTIFIER) { name = RecordUtil.intern(tree.getCharTable(), child); } else if (type == JavaTokenType.EQ) { expectingInit = true; } else if (expectingInit && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) && type != JavaTokenType.SEMICOLON) { initializer = encodeInitializer(tree, child); break; } } final boolean isEnumConst = node.getTokenType() == JavaElementType.ENUM_CONSTANT; final byte flags = PsiFieldStubImpl.packFlags(isEnumConst, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment); return new PsiFieldStubImpl(parentStub, name, typeInfo, initializer, flags); }
@Override public void serialize(@NotNull final PsiFieldStub stub, @NotNull final StubOutputStream dataStream) throws IOException { dataStream.writeName(stub.getName()); TypeInfo.writeTYPE(dataStream, stub.getType(false)); dataStream.writeName(stub.getInitializerText()); dataStream.writeByte(((PsiFieldStubImpl)stub).getFlags()); }
@NotNull @Override public PsiFieldStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { final StringRef name = dataStream.readName(); final TypeInfo type = TypeInfo.readTYPE(dataStream); final StringRef initializerText = dataStream.readName(); final byte flags = dataStream.readByte(); return new PsiFieldStubImpl(parentStub, name, type, initializerText, flags); }
public PsiMethodStubImpl(StubElement parent, String name, byte flags, String signature, @NotNull List<String> args, @Nullable List<String> throwables, String desc, int modifiersMask) { super(parent, isAnnotationMethod(flags) ? JavaStubElementTypes.ANNOTATION_METHOD : JavaStubElementTypes.METHOD); myName = name; myDefaultValueText = null; new PsiModifierListStubImpl(this, modifiersMask); String returnType = null; boolean parsedViaGenericSignature = false; if (signature != null) { try { returnType = StubBuildingVisitor.parseMethodViaGenericSignature(signature, this, args, throwables); parsedViaGenericSignature = true; } catch (ClsFormatException ignored) { } } if (returnType == null) { returnType = StubBuildingVisitor.parseMethodViaDescription(desc, this, args); } myReturnType = TypeInfo.fromString(returnType); myFlags = (byte)(flags | (parsedViaGenericSignature ? PARSED_VIA_GENERIC_SIGNATURE : 0)); }
public PsiMethodStubImpl(StubElement parent, String name, @NotNull TypeInfo returnType, byte flags, @Nullable String defaultValueText) { super(parent, isAnnotationMethod(flags) ? JavaStubElementTypes.ANNOTATION_METHOD : JavaStubElementTypes.METHOD); myReturnType = returnType; myFlags = flags; myName = name; myDefaultValueText = defaultValueText; }
public PsiFieldStubImpl(StubElement parent, StringRef name, @NotNull TypeInfo type, @Nullable StringRef initializer, byte flags) { super(parent, isEnumConst(flags) ? JavaStubElementTypes.ENUM_CONSTANT : JavaStubElementTypes.FIELD); myName = name; myType = type; myInitializer = initializer; myFlags = flags; }
@Override public PsiParameterStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub); LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, JavaTokenType.IDENTIFIER); String name = RecordUtil.intern(tree.getCharTable(), id); return new PsiParameterStubImpl(parentStub, name, typeInfo, typeInfo.isEllipsis); }
@NotNull @Override public PsiParameterStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { StringRef name = dataStream.readName(); TypeInfo type = TypeInfo.readTYPE(dataStream); boolean isEllipsis = dataStream.readBoolean(); return new PsiParameterStubImpl(parentStub, name, type, isEllipsis); }
@Override @Nullable public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { if ((access & Opcodes.ACC_SYNTHETIC) != 0) return null; if (!isCorrectName(name)) return null; byte flags = PsiFieldStubImpl.packFlags((access & Opcodes.ACC_ENUM) != 0, (access & Opcodes.ACC_DEPRECATED) != 0, false, false); TypeInfo type = fieldType(desc, signature); String initializer = constToString(value, type.text, false); PsiFieldStub stub = new PsiFieldStubImpl(myResult, name, type, initializer, flags); PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packFieldFlags(access)); return new AnnotationCollectingVisitor(modList); }
@NotNull public static TypeInfo fieldType(String desc, String signature) { if (signature != null) { try { return TypeInfo.fromString(SignatureParsing.parseTypeString(new StringCharacterIterator(signature, 0))); } catch (ClsFormatException e) { return fieldTypeViaDescription(desc); } } else { return fieldTypeViaDescription(desc); } }
@NotNull private static TypeInfo fieldTypeViaDescription(@NotNull String desc) { Type type = Type.getType(desc); final int dim = type.getSort() == Type.ARRAY ? type.getDimensions() : 0; if (dim > 0) { type = type.getElementType(); } return new TypeInfo(getTypeText(type), (byte)dim, false, PsiAnnotationStub.EMPTY_ARRAY); //todo read annos from .class file }
public ClsJavaCodeReferenceElementImpl(PsiElement parent, @NotNull String canonicalText) { myParent = parent; String canonical = TypeInfo.internFrequentType(canonicalText); myCanonicalText = canonical; String qName = TypeInfo.internFrequentType(PsiNameHelper.getQualifiedClassName(myCanonicalText, false)); myQualifiedName = qName.equals(canonical) ? canonical : qName; String[] classParameters = PsiNameHelper.getClassParametersText(canonicalText); myRefParameterList = classParameters.length == 0 ? null : new ClsReferenceParameterListImpl(this, classParameters); }
@Override public PsiType getReturnType() { if (isConstructor()) return null; final PsiMethodStub stub = getStub(); if (stub != null) { PsiType type = SoftReference.dereference(myCachedType); if (type != null) return type; final String typeText = TypeInfo.createTypeText(stub.getReturnTypeText(true)); if (typeText == null) return null; try { type = JavaPsiFacade.getInstance(getProject()).getElementFactory().createTypeFromText(typeText, this); myCachedType = new SoftReference<PsiType>(type); return type; } catch (IncorrectOperationException e) { LOG.error("stub: " + stub + "; method: " + getText(), e); return null; } } myCachedType = null; PsiTypeElement typeElement = getReturnTypeElement(); if (typeElement == null) return null; PsiParameterList parameterList = getParameterList(); return JavaSharedImplUtil.getType(typeElement, parameterList); }
@NotNull @Override public PsiMethodStub deserialize(@NotNull final StubInputStream dataStream, final StubElement parentStub) throws IOException { StringRef name = dataStream.readName(); final TypeInfo type = TypeInfo.readTYPE(dataStream); byte flags = dataStream.readByte(); final StringRef defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readName() : null; return new PsiMethodStubImpl(parentStub, name, type, flags, defaultMethodValue); }
@Override public PsiFieldStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) { final TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub); boolean isDeprecatedByComment = false; boolean hasDeprecatedAnnotation = false; String name = null; String initializer = null; boolean expectingInit = false; for (final LighterASTNode child : tree.getChildren(node)) { final IElementType type = child.getTokenType(); if (type == JavaDocElementType.DOC_COMMENT) { isDeprecatedByComment = RecordUtil.isDeprecatedByDocComment(tree, child); } else if (type == JavaElementType.MODIFIER_LIST) { hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child); } else if (type == JavaTokenType.IDENTIFIER) { name = RecordUtil.intern(tree.getCharTable(), child); } else if (type == JavaTokenType.EQ) { expectingInit = true; } else if (expectingInit && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) && type != JavaTokenType.SEMICOLON) { initializer = encodeInitializer(tree, child); break; } } final boolean isEnumConst = node.getTokenType() == JavaElementType.ENUM_CONSTANT; final byte flags = PsiFieldStubImpl.packFlags(isEnumConst, isDeprecatedByComment, hasDeprecatedAnnotation); return new PsiFieldStubImpl(parentStub, name, typeInfo, initializer, flags); }
public PsiMethodStubImpl(StubElement parent, StringRef name, TypeInfo returnType, byte flags, StringRef defaultValueText) { super(parent, isAnnotationMethod(flags) ? JavaStubElementTypes.ANNOTATION_METHOD : JavaStubElementTypes.METHOD); myReturnType = returnType; myFlags = flags; myName = name; myDefaultValueText = defaultValueText; }
@Override public PsiParameterStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub); LighterASTNode id = LightTreeUtil.requiredChildOfType(tree, node, ID_TYPES); String name = RecordUtil.intern(tree.getCharTable(), id); return new PsiParameterStubImpl(parentStub, name, typeInfo, typeInfo.isEllipsis); }
@Override @Nullable public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { if ((access & Opcodes.ACC_SYNTHETIC) != 0) return null; if (!isCorrectName(name)) return null; byte flags = PsiFieldStubImpl.packFlags((access & Opcodes.ACC_ENUM) != 0, (access & Opcodes.ACC_DEPRECATED) != 0, false); TypeInfo type = fieldType(desc, signature); String initializer = constToString(value, "boolean".equals(type.text.getString()), false); PsiFieldStub stub = new PsiFieldStubImpl(myResult, name, type, initializer, flags); PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packFieldFlags(access)); return new AnnotationCollectingVisitor(modList); }
@NotNull private static TypeInfo fieldType(String desc, String signature) { if (signature != null) { try { return TypeInfo.fromString(SignatureParsing.parseTypeString(new StringCharacterIterator(signature, 0))); } catch (ClsFormatException e) { return fieldTypeViaDescription(desc); } } else { return fieldTypeViaDescription(desc); } }
@NotNull private static TypeInfo fieldTypeViaDescription(@NotNull String desc) { Type type = Type.getType(desc); final int dim = type.getSort() == Type.ARRAY ? type.getDimensions() : 0; if (dim > 0) { type = type.getElementType(); } return new TypeInfo(getTypeText(type), (byte)dim, false, Collections.<PsiAnnotationStub>emptyList()); //todo read annos from .class file }
public ClsJavaCodeReferenceElementImpl(PsiElement parent, String canonicalText) { myParent = parent; String canonical = TypeInfo.internFrequentType(canonicalText); myCanonicalText = canonical; String qName = TypeInfo.internFrequentType(PsiNameHelper.getQualifiedClassName(myCanonicalText, false)); myQualifiedName = qName.equals(canonical) ? canonical : qName; String[] classParameters = PsiNameHelper.getClassParametersText(canonicalText); myRefParameterList = classParameters.length == 0 ? null : new ClsReferenceParameterListImpl(this, classParameters); }
@Override public void serialize(@NotNull final PsiMethodStub stub, @NotNull final StubOutputStream dataStream) throws IOException { dataStream.writeName(stub.getName()); TypeInfo.writeTYPE(dataStream, stub.getReturnTypeText(false)); dataStream.writeByte(((PsiMethodStubImpl) stub).getFlags()); if(stub.isAnnotationMethod()) { dataStream.writeName(stub.getDefaultValueText()); } }
@Override public void serialize(@NotNull final PsiFieldStub stub, @NotNull final StubOutputStream dataStream) throws IOException { dataStream.writeName(stub.getName()); TypeInfo.writeTYPE(dataStream, stub.getType(false)); dataStream.writeName(stub.getInitializerText()); dataStream.writeByte(((PsiFieldStubImpl) stub).getFlags()); }
public PsiFieldStubImpl(StubElement parent, String name, @NotNull TypeInfo type, @Nullable String initializer, byte flags) { this(parent, StringRef.fromString(name), type, StringRef.fromString(initializer), flags); }