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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations