Search in sources :

Example 1 with ClsFormatException

use of com.intellij.util.cls.ClsFormatException in project intellij-community by JetBrains.

the class SignatureParsing method parseTypeString.

@NotNull
public static String parseTypeString(CharacterIterator signature, Function<String, String> mapping) throws ClsFormatException {
    int dimensions = parseDimensions(signature);
    String text = parseTypeWithoutVariance(signature, mapping);
    if (text == null)
        throw new ClsFormatException();
    if (dimensions > 0) {
        text += StringUtil.repeat("[]", dimensions);
    }
    return text;
}
Also used : ClsFormatException(com.intellij.util.cls.ClsFormatException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ClsFormatException

use of com.intellij.util.cls.ClsFormatException in project intellij-community by JetBrains.

the class SignatureParsing method parseClassOrTypeVariableElement.

private static String parseClassOrTypeVariableElement(CharacterIterator signature, Function<String, String> mapping) throws ClsFormatException {
    char variance = parseVariance(signature);
    if (variance == '*') {
        return decorateTypeText(null, variance);
    }
    int dimensions = parseDimensions(signature);
    String text = parseTypeWithoutVariance(signature, mapping);
    if (text == null)
        throw new ClsFormatException();
    if (dimensions > 0) {
        text += StringUtil.repeat("[]", dimensions);
    }
    return decorateTypeText(text, variance);
}
Also used : ClsFormatException(com.intellij.util.cls.ClsFormatException)

Example 3 with ClsFormatException

use of com.intellij.util.cls.ClsFormatException in project intellij-community by JetBrains.

the class StubBuildingVisitor method visitMethod.

@Override
@Nullable
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    // See IDEA-78649
    if (isSet(access, Opcodes.ACC_SYNTHETIC))
        return null;
    if (name == null)
        return null;
    if (SYNTHETIC_CLASS_INIT_METHOD.equals(name))
        return null;
    // skip semi-synthetic enum methods
    boolean isEnum = myResult.isEnum();
    if (isEnum) {
        if ("values".equals(name) && desc.startsWith("()"))
            return null;
        //noinspection SpellCheckingInspection
        if ("valueOf".equals(name) && desc.startsWith("(Ljava/lang/String;)"))
            return null;
    }
    boolean isConstructor = SYNTHETIC_INIT_METHOD.equals(name);
    boolean isDeprecated = isSet(access, Opcodes.ACC_DEPRECATED);
    boolean isVarargs = isSet(access, Opcodes.ACC_VARARGS);
    boolean isStatic = isSet(access, Opcodes.ACC_STATIC);
    boolean isAnnotationMethod = myResult.isAnnotationType();
    byte flags = PsiMethodStubImpl.packFlags(isConstructor, isAnnotationMethod, isVarargs, isDeprecated, false, false);
    String canonicalMethodName = isConstructor ? myResult.getName() : name;
    MethodInfo info = null;
    boolean generic = false;
    if (signature != null) {
        try {
            info = parseMethodSignature(signature, exceptions);
            generic = true;
        } catch (ClsFormatException e) {
            if (LOG.isDebugEnabled())
                LOG.debug("source=" + mySource + " signature=" + signature, e);
        }
    }
    if (info == null) {
        info = parseMethodDescription(desc, exceptions);
    }
    PsiMethodStubImpl stub = new PsiMethodStubImpl(myResult, canonicalMethodName, TypeInfo.fromString(info.returnType, false), flags, null);
    PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packMethodFlags(access, myResult.isInterface()));
    PsiTypeParameterListStub list = new PsiTypeParameterListStubImpl(stub);
    for (Pair<String, String[]> parameter : info.typeParameters) {
        PsiTypeParameterStub parameterStub = new PsiTypeParameterStubImpl(list, StringRef.fromString(parameter.first));
        newReferenceList(JavaStubElementTypes.EXTENDS_BOUND_LIST, parameterStub, parameter.second);
    }
    boolean isEnumConstructor = isEnum && isConstructor;
    boolean isInnerClassConstructor = isConstructor && !(myParent instanceof PsiFileStub) && !isSet(myModList.getModifiersMask(), Opcodes.ACC_STATIC);
    List<String> args = info.argTypes;
    if (!generic && isEnumConstructor && args.size() >= 2 && CommonClassNames.JAVA_LANG_STRING.equals(args.get(0)) && "int".equals(args.get(1))) {
        // omit synthetic enum constructor parameters
        args = args.subList(2, args.size());
    }
    PsiParameterListStubImpl parameterList = new PsiParameterListStubImpl(stub);
    int paramCount = args.size();
    PsiParameterStubImpl[] paramStubs = new PsiParameterStubImpl[paramCount];
    for (int i = 0; i < paramCount; i++) {
        // omit synthetic inner class constructor parameter
        if (i == 0 && !generic && isInnerClassConstructor)
            continue;
        String arg = args.get(i);
        boolean isEllipsisParam = isVarargs && i == paramCount - 1;
        TypeInfo typeInfo = TypeInfo.fromString(arg, isEllipsisParam);
        String paramName = i < parameterNames.length ? parameterNames[i] : "p" + (i + 1);
        PsiParameterStubImpl parameterStub = new PsiParameterStubImpl(parameterList, paramName, typeInfo, isEllipsisParam, true);
        paramStubs[i] = parameterStub;
        new PsiModifierListStubImpl(parameterStub, 0);
    }
    newReferenceList(JavaStubElementTypes.THROWS_LIST, stub, ArrayUtil.toStringArray(info.throwTypes));
    int localVarIgnoreCount = isStatic ? 0 : isEnumConstructor ? 3 : 1;
    int paramIgnoreCount = isEnumConstructor ? 2 : isInnerClassConstructor ? 1 : 0;
    return new MethodAnnotationCollectingVisitor(stub, modList, localVarIgnoreCount, paramIgnoreCount, paramCount, paramStubs, myMapping);
}
Also used : TypeInfo(com.intellij.psi.impl.cache.TypeInfo) PsiFileStub(com.intellij.psi.stubs.PsiFileStub) ClsFormatException(com.intellij.util.cls.ClsFormatException) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ClsFormatException

use of com.intellij.util.cls.ClsFormatException in project intellij-community by JetBrains.

the class StubBuildingVisitor method parseMethodSignature.

private MethodInfo parseMethodSignature(String signature, String[] exceptions) throws ClsFormatException {
    MethodInfo result = new MethodInfo();
    CharacterIterator iterator = new StringCharacterIterator(signature);
    result.typeParameters = SignatureParsing.parseTypeParametersDeclaration(iterator, myMapping);
    if (iterator.current() != '(')
        throw new ClsFormatException();
    iterator.next();
    if (iterator.current() == ')') {
        result.argTypes = ContainerUtil.emptyList();
    } else {
        result.argTypes = ContainerUtil.newSmartList();
        while (iterator.current() != ')' && iterator.current() != CharacterIterator.DONE) {
            result.argTypes.add(SignatureParsing.parseTypeString(iterator, myMapping));
        }
        if (iterator.current() != ')')
            throw new ClsFormatException();
    }
    iterator.next();
    result.returnType = SignatureParsing.parseTypeString(iterator, myMapping);
    result.throwTypes = null;
    while (iterator.current() == '^') {
        iterator.next();
        if (result.throwTypes == null)
            result.throwTypes = ContainerUtil.newSmartList();
        result.throwTypes.add(SignatureParsing.parseTypeString(iterator, myMapping));
    }
    if (exceptions != null && (result.throwTypes == null || exceptions.length > result.throwTypes.size())) {
        // a signature may be inconsistent with exception list - in this case, the more complete list takes precedence
        result.throwTypes = ContainerUtil.map(exceptions, name -> myMapping.fun(name));
    }
    return result;
}
Also used : ArrayUtil(com.intellij.util.ArrayUtil) Array(java.lang.reflect.Array) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContainerUtil(com.intellij.util.containers.ContainerUtil) ModifierFlags(com.intellij.psi.impl.cache.ModifierFlags) PsiNameHelper(com.intellij.psi.PsiNameHelper) TypeInfo(com.intellij.psi.impl.cache.TypeInfo) Map(java.util.Map) Logger(com.intellij.openapi.diagnostic.Logger) Pair.pair(com.intellij.openapi.util.Pair.pair) LanguageLevel(com.intellij.pom.java.LanguageLevel) BitUtil.isSet(com.intellij.util.BitUtil.isSet) com.intellij.psi.impl.java.stubs(com.intellij.psi.impl.java.stubs) CharacterIterator(java.text.CharacterIterator) StringUtil(com.intellij.openapi.util.text.StringUtil) StringRef(com.intellij.util.io.StringRef) Set(java.util.Set) IOException(java.io.IOException) ClsFormatException(com.intellij.util.cls.ClsFormatException) StringCharacterIterator(java.text.StringCharacterIterator) CommonClassNames(com.intellij.psi.CommonClassNames) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) com.intellij.psi.impl.java.stubs.impl(com.intellij.psi.impl.java.stubs.impl) Function(com.intellij.util.Function) Pair(com.intellij.openapi.util.Pair) org.jetbrains.org.objectweb.asm(org.jetbrains.org.objectweb.asm) PsiFileStub(com.intellij.psi.stubs.PsiFileStub) StubElement(com.intellij.psi.stubs.StubElement) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) StringCharacterIterator(java.text.StringCharacterIterator) CharacterIterator(java.text.CharacterIterator) StringCharacterIterator(java.text.StringCharacterIterator) ClsFormatException(com.intellij.util.cls.ClsFormatException)

Example 5 with ClsFormatException

use of com.intellij.util.cls.ClsFormatException in project intellij-community by JetBrains.

the class ClassFileStubBuilder method buildStubTree.

@Override
public StubElement buildStubTree(@NotNull FileContent fileContent) {
    VirtualFile file = fileContent.getFile();
    byte[] content = fileContent.getContent();
    try {
        try {
            file.setPreloadedContentHint(content);
            ClassFileDecompilers.Decompiler decompiler = ClassFileDecompilers.find(file);
            if (decompiler instanceof Full) {
                return ((Full) decompiler).getStubBuilder().buildFileStub(fileContent);
            }
        } catch (ClsFormatException e) {
            if (LOG.isDebugEnabled())
                LOG.debug(file.getPath(), e);
            else
                LOG.info(file.getPath() + ": " + e.getMessage());
        }
        try {
            PsiFileStub<?> stub = ClsFileImpl.buildFileStub(file, content);
            if (stub == null && fileContent.getFileName().indexOf('$') < 0) {
                LOG.info("No stub built for file " + fileContent);
            }
            return stub;
        } catch (ClsFormatException e) {
            if (LOG.isDebugEnabled())
                LOG.debug(file.getPath(), e);
            else
                LOG.info(file.getPath() + ": " + e.getMessage());
        }
    } finally {
        file.setPreloadedContentHint(null);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ClassFileDecompilers(com.intellij.psi.compiled.ClassFileDecompilers) ClsFormatException(com.intellij.util.cls.ClsFormatException) Full(com.intellij.psi.compiled.ClassFileDecompilers.Full)

Aggregations

ClsFormatException (com.intellij.util.cls.ClsFormatException)7 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 LanguageLevel (com.intellij.pom.java.LanguageLevel)2 TypeInfo (com.intellij.psi.impl.cache.TypeInfo)2 PsiFileStub (com.intellij.psi.stubs.PsiFileStub)2 IOException (java.io.IOException)2 CharacterIterator (java.text.CharacterIterator)2 StringCharacterIterator (java.text.StringCharacterIterator)2 NotNull (org.jetbrains.annotations.NotNull)2 PluginException (com.intellij.diagnostic.PluginException)1 Logger (com.intellij.openapi.diagnostic.Logger)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Pair (com.intellij.openapi.util.Pair)1 Pair.pair (com.intellij.openapi.util.Pair.pair)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 CommonClassNames (com.intellij.psi.CommonClassNames)1 PsiNameHelper (com.intellij.psi.PsiNameHelper)1 ClassFileDecompilers (com.intellij.psi.compiled.ClassFileDecompilers)1 Full (com.intellij.psi.compiled.ClassFileDecompilers.Full)1