Skip to content

Conversation

wbars
Copy link
Contributor

@wbars wbars commented May 24, 2017

No description provided.

GoStructType structType = ObjectUtils.tryCast(startElement, GoStructType.class);
if (structType == null) return;
List<GoFieldDeclaration> declarations = structType.getFieldDeclarationList();
PsiElement anchor = !declarations.isEmpty() ? ContainerUtil.getLastItem(declarations) : structType.getLbrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= ContainerUtil.getLastItem(declarations, structType.getLbrace)

if (structType == null) return;
List<GoFieldDeclaration> declarations = structType.getFieldDeclarationList();
PsiElement anchor = !declarations.isEmpty() ? ContainerUtil.getLastItem(declarations) : structType.getLbrace();
if (anchor != null) structType.addAfter(GoElementFactory.createFieldDeclaration(project, myFieldText, myTypeText), anchor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When can it happen? Can you test this?

GoType type = qualifier != null ? qualifier.getGoType(null) : null;
GoStructType structType = type != null ? ObjectUtils.tryCast(type.getUnderlyingType(), GoStructType.class) : null;
if (!"_".equals(reference.getCanonicalText()) && structType != null) {
fixes = new LocalQuickFix[]{new GoAddStructFieldFix(reference.getCanonicalText(), getTypeName(o), structType)};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, psi element that is passed to QuickFix is an inspection holder. In this case you pass there the element that should be changed, not the unresolved element. It's bad, because the struct type or unresolved reference could completely changed on the moment of quickfix invocation and should not be modified,

@wbars wbars force-pushed the unresolved_struct_fields branch from a2737bd to 2558b51 Compare May 24, 2017 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants