Lines 97-109
Link Here
|
97 |
import org.openide.util.ImageUtilities; |
97 |
import org.openide.util.ImageUtilities; |
98 |
import org.openide.util.NbBundle; |
98 |
import org.openide.util.NbBundle; |
99 |
import org.openide.xml.XMLUtil; |
99 |
import org.openide.xml.XMLUtil; |
|
|
100 |
import org.netbeans.swing.plaf.LFCustoms; |
100 |
|
101 |
|
101 |
/** |
102 |
/** |
102 |
* |
103 |
* |
103 |
* @author Dusan Balek |
104 |
* @author Dusan Balek |
104 |
*/ |
105 |
*/ |
105 |
public abstract class JavaCompletionItem implements CompletionItem { |
106 |
public abstract class JavaCompletionItem implements CompletionItem { |
106 |
|
107 |
|
107 |
protected static int SMART_TYPE = 1000; |
108 |
protected static int SMART_TYPE = 1000; |
108 |
private static final String GENERATE_TEXT = NbBundle.getMessage(JavaCompletionItem.class, "generate_Lbl"); |
109 |
private static final String GENERATE_TEXT = NbBundle.getMessage(JavaCompletionItem.class, "generate_Lbl"); |
109 |
private static final Logger LOGGER = Logger.getLogger(JavaCompletionItem.class.getName()); |
110 |
private static final Logger LOGGER = Logger.getLogger(JavaCompletionItem.class.getName()); |
Lines 111-117
Link Here
|
111 |
public static final JavaCompletionItem createKeywordItem(String kwd, String postfix, int substitutionOffset, boolean smartType) { |
112 |
public static final JavaCompletionItem createKeywordItem(String kwd, String postfix, int substitutionOffset, boolean smartType) { |
112 |
return new KeywordItem(kwd, 0, postfix, substitutionOffset, smartType); |
113 |
return new KeywordItem(kwd, 0, postfix, substitutionOffset, smartType); |
113 |
} |
114 |
} |
114 |
|
115 |
|
115 |
public static final JavaCompletionItem createPackageItem(String pkgFQN, int substitutionOffset, boolean inPackageStatement) { |
116 |
public static final JavaCompletionItem createPackageItem(String pkgFQN, int substitutionOffset, boolean inPackageStatement) { |
116 |
return new PackageItem(pkgFQN, substitutionOffset, inPackageStatement); |
117 |
return new PackageItem(pkgFQN, substitutionOffset, inPackageStatement); |
117 |
} |
118 |
} |
Lines 130-136
Link Here
|
130 |
throw new IllegalArgumentException("kind=" + elem.getKind()); |
131 |
throw new IllegalArgumentException("kind=" + elem.getKind()); |
131 |
} |
132 |
} |
132 |
} |
133 |
} |
133 |
|
134 |
|
134 |
public static final JavaCompletionItem createArrayItem(CompilationInfo info, ArrayType type, int substitutionOffset, ReferencesCount referencesCount, Elements elements, WhiteListQuery.WhiteList whiteList) { |
135 |
public static final JavaCompletionItem createArrayItem(CompilationInfo info, ArrayType type, int substitutionOffset, ReferencesCount referencesCount, Elements elements, WhiteListQuery.WhiteList whiteList) { |
135 |
int dim = 0; |
136 |
int dim = 0; |
136 |
TypeMirror tm = type; |
137 |
TypeMirror tm = type; |
Lines 156-162
Link Here
|
156 |
} |
157 |
} |
157 |
throw new IllegalArgumentException("array element kind=" + tm.getKind()); |
158 |
throw new IllegalArgumentException("array element kind=" + tm.getKind()); |
158 |
} |
159 |
} |
159 |
|
160 |
|
160 |
public static final JavaCompletionItem createTypeParameterItem(TypeParameterElement elem, int substitutionOffset) { |
161 |
public static final JavaCompletionItem createTypeParameterItem(TypeParameterElement elem, int substitutionOffset) { |
161 |
return new TypeParameterItem(elem, substitutionOffset); |
162 |
return new TypeParameterItem(elem, substitutionOffset); |
162 |
} |
163 |
} |
Lines 175-181
Link Here
|
175 |
throw new IllegalArgumentException("kind=" + elem.getKind()); |
176 |
throw new IllegalArgumentException("kind=" + elem.getKind()); |
176 |
} |
177 |
} |
177 |
} |
178 |
} |
178 |
|
179 |
|
179 |
public static final JavaCompletionItem createVariableItem(CompilationInfo info, String varName, int substitutionOffset, boolean newVarName, boolean smartType) { |
180 |
public static final JavaCompletionItem createVariableItem(CompilationInfo info, String varName, int substitutionOffset, boolean newVarName, boolean smartType) { |
180 |
return new VariableItem(info, null, varName, substitutionOffset, newVarName, smartType, -1); |
181 |
return new VariableItem(info, null, varName, substitutionOffset, newVarName, smartType, -1); |
181 |
} |
182 |
} |
Lines 190-196
Link Here
|
190 |
throw new IllegalArgumentException("kind=" + elem.getKind()); |
191 |
throw new IllegalArgumentException("kind=" + elem.getKind()); |
191 |
} |
192 |
} |
192 |
} |
193 |
} |
193 |
|
194 |
|
194 |
public static final JavaCompletionItem createThisOrSuperConstructorItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, String name, WhiteListQuery.WhiteList whiteList) { |
195 |
public static final JavaCompletionItem createThisOrSuperConstructorItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, String name, WhiteListQuery.WhiteList whiteList) { |
195 |
if (elem.getKind() == ElementKind.CONSTRUCTOR) |
196 |
if (elem.getKind() == ElementKind.CONSTRUCTOR) |
196 |
return new ConstructorItem(info, elem, type, substitutionOffset, isDeprecated, false, name, whiteList); |
197 |
return new ConstructorItem(info, elem, type, substitutionOffset, isDeprecated, false, name, whiteList); |
Lines 219-225
Link Here
|
219 |
public static final JavaCompletionItem createDefaultConstructorItem(TypeElement elem, int substitutionOffset, boolean smartType) { |
220 |
public static final JavaCompletionItem createDefaultConstructorItem(TypeElement elem, int substitutionOffset, boolean smartType) { |
220 |
return new DefaultConstructorItem(elem, substitutionOffset, smartType); |
221 |
return new DefaultConstructorItem(elem, substitutionOffset, smartType); |
221 |
} |
222 |
} |
222 |
|
223 |
|
223 |
public static final JavaCompletionItem createParametersItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, int activeParamIndex, String name) { |
224 |
public static final JavaCompletionItem createParametersItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, int activeParamIndex, String name) { |
224 |
return new ParametersItem(info, elem, type, substitutionOffset, isDeprecated, activeParamIndex, name); |
225 |
return new ParametersItem(info, elem, type, substitutionOffset, isDeprecated, activeParamIndex, name); |
225 |
} |
226 |
} |
Lines 227-237
Link Here
|
227 |
public static final JavaCompletionItem createAnnotationItem(CompilationInfo info, TypeElement elem, DeclaredType type, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, WhiteListQuery.WhiteList whiteList) { |
228 |
public static final JavaCompletionItem createAnnotationItem(CompilationInfo info, TypeElement elem, DeclaredType type, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, WhiteListQuery.WhiteList whiteList) { |
228 |
return new AnnotationItem(info, elem, type, substitutionOffset, referencesCount, isDeprecated, true, whiteList); |
229 |
return new AnnotationItem(info, elem, type, substitutionOffset, referencesCount, isDeprecated, true, whiteList); |
229 |
} |
230 |
} |
230 |
|
231 |
|
231 |
public static final JavaCompletionItem createAttributeItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated) { |
232 |
public static final JavaCompletionItem createAttributeItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated) { |
232 |
return new AttributeItem(info, elem, type, substitutionOffset, isDeprecated); |
233 |
return new AttributeItem(info, elem, type, substitutionOffset, isDeprecated); |
233 |
} |
234 |
} |
234 |
|
235 |
|
235 |
public static final JavaCompletionItem createAttributeValueItem(CompilationInfo info, String value, String documentation, TypeElement element, int substitutionOffset, ReferencesCount referencesCount, WhiteListQuery.WhiteList whiteList) { |
236 |
public static final JavaCompletionItem createAttributeValueItem(CompilationInfo info, String value, String documentation, TypeElement element, int substitutionOffset, ReferencesCount referencesCount, WhiteListQuery.WhiteList whiteList) { |
236 |
return new AttributeValueItem(info, value, documentation, element, substitutionOffset, referencesCount, whiteList); |
237 |
return new AttributeValueItem(info, value, documentation, element, substitutionOffset, referencesCount, whiteList); |
237 |
} |
238 |
} |
Lines 337-355
Link Here
|
337 |
defaultAction(component); |
338 |
defaultAction(component); |
338 |
return true; |
339 |
return true; |
339 |
} |
340 |
} |
340 |
|
341 |
|
341 |
public CompletionTask createDocumentationTask() { |
342 |
public CompletionTask createDocumentationTask() { |
342 |
return null; |
343 |
return null; |
343 |
} |
344 |
} |
344 |
|
345 |
|
345 |
public CompletionTask createToolTipTask() { |
346 |
public CompletionTask createToolTipTask() { |
346 |
return null; |
347 |
return null; |
347 |
} |
348 |
} |
348 |
|
349 |
|
349 |
public int getPreferredWidth(Graphics g, Font defaultFont) { |
350 |
public int getPreferredWidth(Graphics g, Font defaultFont) { |
350 |
return CompletionUtilities.getPreferredWidth(getLeftHtmlText(), getRightHtmlText(), g, defaultFont); |
351 |
return CompletionUtilities.getPreferredWidth(getLeftHtmlText(), getRightHtmlText(), g, defaultFont); |
351 |
} |
352 |
} |
352 |
|
353 |
|
353 |
public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) { |
354 |
public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) { |
354 |
CompletionUtilities.renderHtml(getIcon(), getLeftHtmlText(), getRightHtmlText(), g, defaultFont, defaultColor, width, height, selected); |
355 |
CompletionUtilities.renderHtml(getIcon(), getLeftHtmlText(), getRightHtmlText(), g, defaultFont, defaultColor, width, height, selected); |
355 |
} |
356 |
} |
Lines 357-367
Link Here
|
357 |
protected ImageIcon getIcon() { |
358 |
protected ImageIcon getIcon() { |
358 |
return null; |
359 |
return null; |
359 |
} |
360 |
} |
360 |
|
361 |
|
361 |
protected String getLeftHtmlText() { |
362 |
protected String getLeftHtmlText() { |
362 |
return null; |
363 |
return null; |
363 |
} |
364 |
} |
364 |
|
365 |
|
365 |
protected String getRightHtmlText() { |
366 |
protected String getRightHtmlText() { |
366 |
return null; |
367 |
return null; |
367 |
} |
368 |
} |
Lines 431-437
Link Here
|
431 |
} |
432 |
} |
432 |
}); |
433 |
}); |
433 |
} |
434 |
} |
434 |
|
435 |
|
435 |
static abstract class WhiteListJavaCompletionItem<T extends Element> extends JavaCompletionItem { |
436 |
static abstract class WhiteListJavaCompletionItem<T extends Element> extends JavaCompletionItem { |
436 |
|
437 |
|
437 |
private static final String WARNING = "org/netbeans/modules/java/editor/resources/warning_badge.gif"; //NOI18N |
438 |
private static final String WARNING = "org/netbeans/modules/java/editor/resources/warning_badge.gif"; //NOI18N |
Lines 486-498
Link Here
|
486 |
return super.getIcon(); |
487 |
return super.getIcon(); |
487 |
} |
488 |
} |
488 |
} |
489 |
} |
489 |
|
490 |
|
490 |
static class KeywordItem extends JavaCompletionItem { |
491 |
static class KeywordItem extends JavaCompletionItem { |
491 |
|
492 |
|
492 |
private static final String JAVA_KEYWORD = "org/netbeans/modules/java/editor/resources/javakw_16.png"; //NOI18N |
493 |
private static final String JAVA_KEYWORD = "org/netbeans/modules/java/editor/resources/javakw_16.png"; //NOI18N |
493 |
private static final String KEYWORD_COLOR = "<font color=#000099>"; //NOI18N |
494 |
private static final String KEYWORD_COLOR = "<font color=#000099>"; //NOI18N |
494 |
private static ImageIcon icon; |
495 |
private static ImageIcon icon; |
495 |
|
496 |
|
496 |
private String kwd; |
497 |
private String kwd; |
497 |
private int dim; |
498 |
private int dim; |
498 |
private String postfix; |
499 |
private String postfix; |
Lines 506-529
Link Here
|
506 |
this.postfix = postfix; |
507 |
this.postfix = postfix; |
507 |
this.smartType = smartType; |
508 |
this.smartType = smartType; |
508 |
} |
509 |
} |
509 |
|
510 |
|
510 |
public int getSortPriority() { |
511 |
public int getSortPriority() { |
511 |
return smartType ? 600 - SMART_TYPE : 600; |
512 |
return smartType ? 600 - SMART_TYPE : 600; |
512 |
} |
513 |
} |
513 |
|
514 |
|
514 |
public CharSequence getSortText() { |
515 |
public CharSequence getSortText() { |
515 |
return kwd; |
516 |
return kwd; |
516 |
} |
517 |
} |
517 |
|
518 |
|
518 |
public CharSequence getInsertPrefix() { |
519 |
public CharSequence getInsertPrefix() { |
519 |
return kwd; |
520 |
return kwd; |
520 |
} |
521 |
} |
521 |
|
522 |
|
522 |
protected ImageIcon getIcon(){ |
523 |
protected ImageIcon getIcon(){ |
523 |
if (icon == null) icon = ImageUtilities.loadImageIcon(JAVA_KEYWORD, false); |
524 |
if (icon == null) icon = ImageUtilities.loadImageIcon(JAVA_KEYWORD, false); |
524 |
return icon; |
525 |
return icon; |
525 |
} |
526 |
} |
526 |
|
527 |
|
527 |
protected String getLeftHtmlText() { |
528 |
protected String getLeftHtmlText() { |
528 |
if (leftText == null) { |
529 |
if (leftText == null) { |
529 |
StringBuilder sb = new StringBuilder(); |
530 |
StringBuilder sb = new StringBuilder(); |
Lines 538-544
Link Here
|
538 |
} |
539 |
} |
539 |
return leftText; |
540 |
return leftText; |
540 |
} |
541 |
} |
541 |
|
542 |
|
542 |
@Override |
543 |
@Override |
543 |
protected void substituteText (final JTextComponent c, final int offset, int len, String toAdd, final boolean assignToVar) { |
544 |
protected void substituteText (final JTextComponent c, final int offset, int len, String toAdd, final boolean assignToVar) { |
544 |
if (dim == 0) { |
545 |
if (dim == 0) { |
Lines 587-593
Link Here
|
587 |
for(int i = 0; i < dim; i++) { |
588 |
for(int i = 0; i < dim; i++) { |
588 |
sb.append("[${PAR"); //NOI18N |
589 |
sb.append("[${PAR"); //NOI18N |
589 |
sb.append(cnt++); |
590 |
sb.append(cnt++); |
590 |
sb.append(" instanceof=\"int\" default=\"\"}]"); //NOI18N |
591 |
sb.append(" instanceof=\"int\" default=\"\"}]"); //NOI18N |
591 |
} |
592 |
} |
592 |
final int length = len; |
593 |
final int length = len; |
593 |
doc.runAtomic (new Runnable () { |
594 |
doc.runAtomic (new Runnable () { |
Lines 608-625
Link Here
|
608 |
ctm.createTemporary(sb.append(text).toString()).insert(c); |
609 |
ctm.createTemporary(sb.append(text).toString()).insert(c); |
609 |
} |
610 |
} |
610 |
} |
611 |
} |
611 |
|
612 |
|
612 |
public String toString() { |
613 |
public String toString() { |
613 |
return kwd; |
614 |
return kwd; |
614 |
} |
615 |
} |
615 |
} |
616 |
} |
616 |
|
617 |
|
617 |
static class PackageItem extends JavaCompletionItem { |
618 |
static class PackageItem extends JavaCompletionItem { |
618 |
|
619 |
|
619 |
private static final String PACKAGE = "org/netbeans/modules/java/editor/resources/package.gif"; // NOI18N |
620 |
private static final String PACKAGE = "org/netbeans/modules/java/editor/resources/package.gif"; // NOI18N |
620 |
private static final String PACKAGE_COLOR = "<font color=#005600>"; //NOI18N |
621 |
private static final String PACKAGE_COLOR = "<font color=#005600>"; //NOI18N |
621 |
private static ImageIcon icon; |
622 |
private static ImageIcon icon; |
622 |
|
623 |
|
623 |
private boolean inPackageStatement; |
624 |
private boolean inPackageStatement; |
624 |
private String simpleName; |
625 |
private String simpleName; |
625 |
private String sortText; |
626 |
private String sortText; |
Lines 632-655
Link Here
|
632 |
this.simpleName = idx < 0 ? pkgFQN : pkgFQN.substring(idx + 1); |
633 |
this.simpleName = idx < 0 ? pkgFQN : pkgFQN.substring(idx + 1); |
633 |
this.sortText = this.simpleName + "#" + pkgFQN; //NOI18N |
634 |
this.sortText = this.simpleName + "#" + pkgFQN; //NOI18N |
634 |
} |
635 |
} |
635 |
|
636 |
|
636 |
public int getSortPriority() { |
637 |
public int getSortPriority() { |
637 |
return 900; |
638 |
return 900; |
638 |
} |
639 |
} |
639 |
|
640 |
|
640 |
public CharSequence getSortText() { |
641 |
public CharSequence getSortText() { |
641 |
return sortText; |
642 |
return sortText; |
642 |
} |
643 |
} |
643 |
|
644 |
|
644 |
public CharSequence getInsertPrefix() { |
645 |
public CharSequence getInsertPrefix() { |
645 |
return simpleName; |
646 |
return simpleName; |
646 |
} |
647 |
} |
647 |
|
648 |
|
648 |
protected ImageIcon getIcon(){ |
649 |
protected ImageIcon getIcon(){ |
649 |
if (icon == null) icon = ImageUtilities.loadImageIcon(PACKAGE, false); |
650 |
if (icon == null) icon = ImageUtilities.loadImageIcon(PACKAGE, false); |
650 |
return icon; |
651 |
return icon; |
651 |
} |
652 |
} |
652 |
|
653 |
|
653 |
protected String getLeftHtmlText() { |
654 |
protected String getLeftHtmlText() { |
654 |
if (leftText == null) { |
655 |
if (leftText == null) { |
655 |
StringBuilder sb = new StringBuilder(); |
656 |
StringBuilder sb = new StringBuilder(); |
Lines 675-693
Link Here
|
675 |
protected void substituteText(JTextComponent c, int offset, int len, String toAdd, final boolean assingToVar) { |
676 |
protected void substituteText(JTextComponent c, int offset, int len, String toAdd, final boolean assingToVar) { |
676 |
super.substituteText(c, offset, len, inPackageStatement || toAdd != null ? toAdd : ".", assingToVar); //NOI18N |
677 |
super.substituteText(c, offset, len, inPackageStatement || toAdd != null ? toAdd : ".", assingToVar); //NOI18N |
677 |
} |
678 |
} |
678 |
|
679 |
|
679 |
public String toString() { |
680 |
public String toString() { |
680 |
return simpleName; |
681 |
return simpleName; |
681 |
} |
682 |
} |
682 |
} |
683 |
} |
683 |
|
684 |
|
684 |
static class ClassItem extends WhiteListJavaCompletionItem<TypeElement> { |
685 |
static class ClassItem extends WhiteListJavaCompletionItem<TypeElement> { |
685 |
|
686 |
|
686 |
private static final String CLASS = "org/netbeans/modules/editor/resources/completion/class_16.png"; //NOI18N |
687 |
private static final String CLASS = "org/netbeans/modules/editor/resources/completion/class_16.png"; //NOI18N |
687 |
private static final String CLASS_COLOR = "<font color=#560000>"; //NOI18N |
688 |
private static final String CLASS_COLOR = "<font color=#560000>"; //NOI18N |
688 |
private static final String PKG_COLOR = "<font color=#808080>"; //NOI18N |
689 |
private static final String PKG_COLOR = "<font color=#808080>"; //NOI18N |
689 |
private static ImageIcon icon; |
690 |
private static ImageIcon icon; |
690 |
|
691 |
|
691 |
protected TypeMirrorHandle<DeclaredType> typeHandle; |
692 |
protected TypeMirrorHandle<DeclaredType> typeHandle; |
692 |
private int dim; |
693 |
private int dim; |
693 |
private boolean isDeprecated; |
694 |
private boolean isDeprecated; |
Lines 701-707
Link Here
|
701 |
private CharSequence sortText; |
702 |
private CharSequence sortText; |
702 |
private String leftText; |
703 |
private String leftText; |
703 |
private boolean autoImport; |
704 |
private boolean autoImport; |
704 |
|
705 |
|
705 |
private ClassItem(CompilationInfo info, TypeElement elem, DeclaredType type, int dim, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addTypeVars, boolean addSimpleName, boolean smartType, boolean autoImport, WhiteListQuery.WhiteList whiteList) { |
706 |
private ClassItem(CompilationInfo info, TypeElement elem, DeclaredType type, int dim, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addTypeVars, boolean addSimpleName, boolean smartType, boolean autoImport, WhiteListQuery.WhiteList whiteList) { |
706 |
super(substitutionOffset, ElementHandle.create(elem), whiteList); |
707 |
super(substitutionOffset, ElementHandle.create(elem), whiteList); |
707 |
this.typeHandle = TypeMirrorHandle.create(type); |
708 |
this.typeHandle = TypeMirrorHandle.create(type); |
Lines 722-736
Link Here
|
722 |
} |
723 |
} |
723 |
this.autoImport = autoImport; |
724 |
this.autoImport = autoImport; |
724 |
} |
725 |
} |
725 |
|
726 |
|
726 |
public int getSortPriority() { |
727 |
public int getSortPriority() { |
727 |
return smartType ? 800 - SMART_TYPE : 800; |
728 |
return smartType ? 800 - SMART_TYPE : 800; |
728 |
} |
729 |
} |
729 |
|
730 |
|
730 |
public CharSequence getSortText() { |
731 |
public CharSequence getSortText() { |
731 |
return sortText; |
732 |
return sortText; |
732 |
} |
733 |
} |
733 |
|
734 |
|
734 |
public CharSequence getInsertPrefix() { |
735 |
public CharSequence getInsertPrefix() { |
735 |
return simpleName; |
736 |
return simpleName; |
736 |
} |
737 |
} |
Lines 738-744
Link Here
|
738 |
public boolean instantSubstitution(JTextComponent component) { |
739 |
public boolean instantSubstitution(JTextComponent component) { |
739 |
return false; |
740 |
return false; |
740 |
} |
741 |
} |
741 |
|
742 |
|
742 |
public CompletionTask createDocumentationTask() { |
743 |
public CompletionTask createDocumentationTask() { |
743 |
return typeHandle.getKind() == TypeKind.DECLARED ? JavaCompletionProvider.createDocTask(ElementHandle.from(typeHandle)) : null; |
744 |
return typeHandle.getKind() == TypeKind.DECLARED ? JavaCompletionProvider.createDocTask(ElementHandle.from(typeHandle)) : null; |
744 |
} |
745 |
} |
Lines 771-777
Link Here
|
771 |
} |
772 |
} |
772 |
return leftText; |
773 |
return leftText; |
773 |
} |
774 |
} |
774 |
|
775 |
|
775 |
protected String getColor() { |
776 |
protected String getColor() { |
776 |
return CLASS_COLOR; |
777 |
return CLASS_COLOR; |
777 |
} |
778 |
} |
Lines 857-863
Link Here
|
857 |
Iterator<? extends TypeMirror> tas = type != null ? type.getTypeArguments().iterator() : null; |
858 |
Iterator<? extends TypeMirror> tas = type != null ? type.getTypeArguments().iterator() : null; |
858 |
if (tas != null && tas.hasNext()) { |
859 |
if (tas != null && tas.hasNext()) { |
859 |
sb.append('<'); //NOI18N |
860 |
sb.append('<'); //NOI18N |
860 |
if (!insideNew || elem.getModifiers().contains(Modifier.ABSTRACT) |
861 |
if (!insideNew || elem.getModifiers().contains(Modifier.ABSTRACT) |
861 |
|| controller.getSourceVersion().compareTo(SourceVersion.RELEASE_7) < 0) { |
862 |
|| controller.getSourceVersion().compareTo(SourceVersion.RELEASE_7) < 0) { |
862 |
while (tas.hasNext()) { |
863 |
while (tas.hasNext()) { |
863 |
TypeMirror ta = tas.next(); |
864 |
TypeMirror ta = tas.next(); |
Lines 1012-1076
Link Here
|
1012 |
} |
1013 |
} |
1013 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-import_resolve"), cancel, false); //NOI18N |
1014 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-import_resolve"), cancel, false); //NOI18N |
1014 |
} |
1015 |
} |
1015 |
|
1016 |
|
1016 |
public String toString() { |
1017 |
public String toString() { |
1017 |
return simpleName; |
1018 |
return simpleName; |
1018 |
} |
1019 |
} |
1019 |
} |
1020 |
} |
1020 |
|
1021 |
|
1021 |
static class InterfaceItem extends ClassItem { |
1022 |
static class InterfaceItem extends ClassItem { |
1022 |
|
1023 |
|
1023 |
private static final String INTERFACE = "org/netbeans/modules/editor/resources/completion/interface.png"; // NOI18N |
1024 |
private static final String INTERFACE = "org/netbeans/modules/editor/resources/completion/interface.png"; // NOI18N |
1024 |
private static final String INTERFACE_COLOR = "<font color=#404040>"; //NOI18N |
1025 |
private static final String INTERFACE_COLOR = "<font color=#404040>"; //NOI18N |
1025 |
private static ImageIcon icon; |
1026 |
private static ImageIcon icon; |
1026 |
|
1027 |
|
1027 |
private InterfaceItem(CompilationInfo info, TypeElement elem, DeclaredType type, int dim, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addTypeVars, boolean addSimpleName, boolean smartType, boolean autoImport, WhiteListQuery.WhiteList whiteList) { |
1028 |
private InterfaceItem(CompilationInfo info, TypeElement elem, DeclaredType type, int dim, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addTypeVars, boolean addSimpleName, boolean smartType, boolean autoImport, WhiteListQuery.WhiteList whiteList) { |
1028 |
super(info, elem, type, dim, substitutionOffset, referencesCount, isDeprecated, insideNew, addTypeVars, addSimpleName, smartType, autoImport, whiteList); |
1029 |
super(info, elem, type, dim, substitutionOffset, referencesCount, isDeprecated, insideNew, addTypeVars, addSimpleName, smartType, autoImport, whiteList); |
1029 |
} |
1030 |
} |
1030 |
|
1031 |
|
1031 |
protected ImageIcon getBaseIcon(){ |
1032 |
protected ImageIcon getBaseIcon(){ |
1032 |
if (icon == null) icon = ImageUtilities.loadImageIcon(INTERFACE, false); |
1033 |
if (icon == null) icon = ImageUtilities.loadImageIcon(INTERFACE, false); |
1033 |
return icon; |
1034 |
return icon; |
1034 |
} |
1035 |
} |
1035 |
|
1036 |
|
1036 |
protected String getColor() { |
1037 |
protected String getColor() { |
1037 |
return INTERFACE_COLOR; |
1038 |
return INTERFACE_COLOR; |
1038 |
} |
1039 |
} |
1039 |
} |
1040 |
} |
1040 |
|
1041 |
|
1041 |
static class EnumItem extends ClassItem { |
1042 |
static class EnumItem extends ClassItem { |
1042 |
|
1043 |
|
1043 |
private static final String ENUM = "org/netbeans/modules/editor/resources/completion/enum.png"; // NOI18N |
1044 |
private static final String ENUM = "org/netbeans/modules/editor/resources/completion/enum.png"; // NOI18N |
1044 |
private static ImageIcon icon; |
1045 |
private static ImageIcon icon; |
1045 |
|
1046 |
|
1046 |
private EnumItem(CompilationInfo info, TypeElement elem, DeclaredType type, int dim, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addSimpleName, boolean smartType, boolean autoImport, WhiteListQuery.WhiteList whiteList) { |
1047 |
private EnumItem(CompilationInfo info, TypeElement elem, DeclaredType type, int dim, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addSimpleName, boolean smartType, boolean autoImport, WhiteListQuery.WhiteList whiteList) { |
1047 |
super(info, elem, type, dim, substitutionOffset, referencesCount, isDeprecated, insideNew, false, addSimpleName, smartType, autoImport, whiteList); |
1048 |
super(info, elem, type, dim, substitutionOffset, referencesCount, isDeprecated, insideNew, false, addSimpleName, smartType, autoImport, whiteList); |
1048 |
} |
1049 |
} |
1049 |
|
1050 |
|
1050 |
protected ImageIcon getBaseIcon(){ |
1051 |
protected ImageIcon getBaseIcon(){ |
1051 |
if (icon == null) icon = ImageUtilities.loadImageIcon(ENUM, false); |
1052 |
if (icon == null) icon = ImageUtilities.loadImageIcon(ENUM, false); |
1052 |
return icon; |
1053 |
return icon; |
1053 |
} |
1054 |
} |
1054 |
} |
1055 |
} |
1055 |
|
1056 |
|
1056 |
static class AnnotationTypeItem extends ClassItem { |
1057 |
static class AnnotationTypeItem extends ClassItem { |
1057 |
|
1058 |
|
1058 |
private static final String ANNOTATION = "org/netbeans/modules/editor/resources/completion/annotation_type.png"; // NOI18N |
1059 |
private static final String ANNOTATION = "org/netbeans/modules/editor/resources/completion/annotation_type.png"; // NOI18N |
1059 |
private static ImageIcon icon; |
1060 |
private static ImageIcon icon; |
1060 |
|
1061 |
|
1061 |
private AnnotationTypeItem(CompilationInfo info, TypeElement elem, DeclaredType type, int dim, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addSimpleName, boolean smartType, boolean autoImport, WhiteListQuery.WhiteList whiteList) { |
1062 |
private AnnotationTypeItem(CompilationInfo info, TypeElement elem, DeclaredType type, int dim, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean insideNew, boolean addSimpleName, boolean smartType, boolean autoImport, WhiteListQuery.WhiteList whiteList) { |
1062 |
super(info, elem, type, dim, substitutionOffset, referencesCount, isDeprecated, insideNew, false, addSimpleName, smartType, autoImport, whiteList); |
1063 |
super(info, elem, type, dim, substitutionOffset, referencesCount, isDeprecated, insideNew, false, addSimpleName, smartType, autoImport, whiteList); |
1063 |
} |
1064 |
} |
1064 |
|
1065 |
|
1065 |
protected ImageIcon getBaseIcon(){ |
1066 |
protected ImageIcon getBaseIcon(){ |
1066 |
if (icon == null) icon = ImageUtilities.loadImageIcon(ANNOTATION, false); |
1067 |
if (icon == null) icon = ImageUtilities.loadImageIcon(ANNOTATION, false); |
1067 |
return icon; |
1068 |
return icon; |
1068 |
} |
1069 |
} |
1069 |
} |
1070 |
} |
1070 |
|
1071 |
|
1071 |
static class TypeParameterItem extends JavaCompletionItem { |
1072 |
static class TypeParameterItem extends JavaCompletionItem { |
1072 |
|
1073 |
|
1073 |
private static final String TYPE_PARAMETER_COLOR = "<font color=#000000>"; //NOI18N |
|
|
1074 |
|
1074 |
|
1075 |
private String simpleName; |
1075 |
private String simpleName; |
1076 |
private String leftText; |
1076 |
private String leftText; |
Lines 1079-1110
Link Here
|
1079 |
super(substitutionOffset); |
1079 |
super(substitutionOffset); |
1080 |
this.simpleName = elem.getSimpleName().toString(); |
1080 |
this.simpleName = elem.getSimpleName().toString(); |
1081 |
} |
1081 |
} |
1082 |
|
1082 |
|
1083 |
public int getSortPriority() { |
1083 |
public int getSortPriority() { |
1084 |
return 700; |
1084 |
return 700; |
1085 |
} |
1085 |
} |
1086 |
|
1086 |
|
1087 |
public CharSequence getSortText() { |
1087 |
public CharSequence getSortText() { |
1088 |
return simpleName; |
1088 |
return simpleName; |
1089 |
} |
1089 |
} |
1090 |
|
1090 |
|
1091 |
public CharSequence getInsertPrefix() { |
1091 |
public CharSequence getInsertPrefix() { |
1092 |
return simpleName; |
1092 |
return simpleName; |
1093 |
} |
1093 |
} |
1094 |
|
1094 |
|
1095 |
protected String getLeftHtmlText() { |
1095 |
protected String getLeftHtmlText() { |
1096 |
if (leftText == null) |
1096 |
if (leftText == null) |
1097 |
leftText = TYPE_PARAMETER_COLOR + simpleName + COLOR_END; |
1097 |
leftText = LFCustoms.getTextFgColorHTML() + simpleName + COLOR_END; |
1098 |
return leftText; |
1098 |
return leftText; |
1099 |
} |
1099 |
} |
1100 |
|
1100 |
|
1101 |
public String toString() { |
1101 |
public String toString() { |
1102 |
return simpleName; |
1102 |
return simpleName; |
1103 |
} |
1103 |
} |
1104 |
} |
1104 |
} |
1105 |
|
1105 |
|
1106 |
static class VariableItem extends JavaCompletionItem { |
1106 |
static class VariableItem extends JavaCompletionItem { |
1107 |
|
1107 |
|
1108 |
private static final String LOCAL_VARIABLE = "org/netbeans/modules/editor/resources/completion/localVariable.gif"; //NOI18N |
1108 |
private static final String LOCAL_VARIABLE = "org/netbeans/modules/editor/resources/completion/localVariable.gif"; //NOI18N |
1109 |
private static final String PARAMETER_COLOR = "<font color=#00007c>"; //NOI18N |
1109 |
private static final String PARAMETER_COLOR = "<font color=#00007c>"; //NOI18N |
1110 |
private static ImageIcon icon; |
1110 |
private static ImageIcon icon; |
Lines 1117-1123
Link Here
|
1117 |
private String rightText; |
1117 |
private String rightText; |
1118 |
private int assignToVarPos; |
1118 |
private int assignToVarPos; |
1119 |
private String assignToVarText; |
1119 |
private String assignToVarText; |
1120 |
|
1120 |
|
1121 |
private VariableItem(CompilationInfo info, TypeMirror type, String varName, int substitutionOffset, boolean newVarName, boolean smartType, int assignToVarPos) { |
1121 |
private VariableItem(CompilationInfo info, TypeMirror type, String varName, int substitutionOffset, boolean newVarName, boolean smartType, int assignToVarPos) { |
1122 |
super(substitutionOffset); |
1122 |
super(substitutionOffset); |
1123 |
this.varName = varName; |
1123 |
this.varName = varName; |
Lines 1127-1141
Link Here
|
1127 |
this.assignToVarPos = assignToVarPos; |
1127 |
this.assignToVarPos = assignToVarPos; |
1128 |
this.assignToVarText = assignToVarPos < 0 ? null : getAssignToVarText(info, type, varName); |
1128 |
this.assignToVarText = assignToVarPos < 0 ? null : getAssignToVarText(info, type, varName); |
1129 |
} |
1129 |
} |
1130 |
|
1130 |
|
1131 |
public int getSortPriority() { |
1131 |
public int getSortPriority() { |
1132 |
return smartType ? 200 - SMART_TYPE : 200; |
1132 |
return smartType ? 200 - SMART_TYPE : 200; |
1133 |
} |
1133 |
} |
1134 |
|
1134 |
|
1135 |
public CharSequence getSortText() { |
1135 |
public CharSequence getSortText() { |
1136 |
return varName; |
1136 |
return varName; |
1137 |
} |
1137 |
} |
1138 |
|
1138 |
|
1139 |
public CharSequence getInsertPrefix() { |
1139 |
public CharSequence getInsertPrefix() { |
1140 |
return varName; |
1140 |
return varName; |
1141 |
} |
1141 |
} |
Lines 1145-1160
Link Here
|
1145 |
leftText = PARAMETER_COLOR + BOLD + varName + BOLD_END + COLOR_END; |
1145 |
leftText = PARAMETER_COLOR + BOLD + varName + BOLD_END + COLOR_END; |
1146 |
return leftText; |
1146 |
return leftText; |
1147 |
} |
1147 |
} |
1148 |
|
1148 |
|
1149 |
protected String getRightHtmlText() { |
1149 |
protected String getRightHtmlText() { |
1150 |
if (rightText == null) |
1150 |
if (rightText == null) |
1151 |
rightText = escape(typeName); |
1151 |
rightText = escape(typeName); |
1152 |
return rightText; |
1152 |
return rightText; |
1153 |
} |
1153 |
} |
1154 |
|
1154 |
|
1155 |
protected ImageIcon getIcon(){ |
1155 |
protected ImageIcon getIcon(){ |
1156 |
if (icon == null) icon = ImageUtilities.loadImageIcon(LOCAL_VARIABLE, false); |
1156 |
if (icon == null) icon = ImageUtilities.loadImageIcon(LOCAL_VARIABLE, false); |
1157 |
return icon; |
1157 |
return icon; |
1158 |
} |
1158 |
} |
1159 |
|
1159 |
|
1160 |
@Override |
1160 |
@Override |
Lines 1193-1210
Link Here
|
1193 |
} |
1193 |
} |
1194 |
|
1194 |
|
1195 |
static class FieldItem extends WhiteListJavaCompletionItem<VariableElement> { |
1195 |
static class FieldItem extends WhiteListJavaCompletionItem<VariableElement> { |
1196 |
|
1196 |
|
1197 |
private static final String FIELD_PUBLIC = "org/netbeans/modules/editor/resources/completion/field_16.png"; //NOI18N |
1197 |
private static final String FIELD_PUBLIC = "org/netbeans/modules/editor/resources/completion/field_16.png"; //NOI18N |
1198 |
private static final String FIELD_PROTECTED = "org/netbeans/modules/editor/resources/completion/field_protected_16.png"; //NOI18N |
1198 |
private static final String FIELD_PROTECTED = "org/netbeans/modules/editor/resources/completion/field_protected_16.png"; //NOI18N |
1199 |
private static final String FIELD_PACKAGE = "org/netbeans/modules/editor/resources/completion/field_package_private_16.png"; //NOI18N |
1199 |
private static final String FIELD_PACKAGE = "org/netbeans/modules/editor/resources/completion/field_package_private_16.png"; //NOI18N |
1200 |
private static final String FIELD_PRIVATE = "org/netbeans/modules/editor/resources/completion/field_private_16.png"; //NOI18N |
1200 |
private static final String FIELD_PRIVATE = "org/netbeans/modules/editor/resources/completion/field_private_16.png"; //NOI18N |
1201 |
private static final String FIELD_ST_PUBLIC = "org/netbeans/modules/editor/resources/completion/field_static_16.png"; //NOI18N |
1201 |
private static final String FIELD_ST_PUBLIC = "org/netbeans/modules/editor/resources/completion/field_static_16.png"; //NOI18N |
1202 |
private static final String FIELD_ST_PROTECTED = "org/netbeans/modules/editor/resources/completion/field_static_protected_16.png"; //NOI18N |
1202 |
private static final String FIELD_ST_PROTECTED = "org/netbeans/modules/editor/resources/completion/field_static_protected_16.png"; //NOI18N |
1203 |
private static final String FIELD_ST_PACKAGE = "org/netbeans/modules/editor/resources/completion/field_static_package_private_16.png"; //NOI18N |
1203 |
private static final String FIELD_ST_PACKAGE = "org/netbeans/modules/editor/resources/completion/field_static_package_private_16.png"; //NOI18N |
1204 |
private static final String FIELD_ST_PRIVATE = "org/netbeans/modules/editor/resources/completion/field_static_private_16.png"; //NOI18N |
1204 |
private static final String FIELD_ST_PRIVATE = "org/netbeans/modules/editor/resources/completion/field_static_private_16.png"; //NOI18N |
1205 |
private static final String FIELD_COLOR = "<font color=#008618>"; //NOI18N |
1205 |
private static final String FIELD_COLOR = "<font color=#008618>"; //NOI18N |
1206 |
private static ImageIcon icon[][] = new ImageIcon[2][4]; |
1206 |
private static ImageIcon icon[][] = new ImageIcon[2][4]; |
1207 |
|
1207 |
|
1208 |
private boolean isInherited; |
1208 |
private boolean isInherited; |
1209 |
private boolean isDeprecated; |
1209 |
private boolean isDeprecated; |
1210 |
private boolean smartType; |
1210 |
private boolean smartType; |
Lines 1217-1223
Link Here
|
1217 |
private CharSequence enclSortText; |
1217 |
private CharSequence enclSortText; |
1218 |
private int assignToVarPos; |
1218 |
private int assignToVarPos; |
1219 |
private String assignToVarText; |
1219 |
private String assignToVarText; |
1220 |
|
1220 |
|
1221 |
private FieldItem(CompilationInfo info, VariableElement elem, TypeMirror type, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean smartType, int assignToVarPos, WhiteListQuery.WhiteList whiteList) { |
1221 |
private FieldItem(CompilationInfo info, VariableElement elem, TypeMirror type, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean smartType, int assignToVarPos, WhiteListQuery.WhiteList whiteList) { |
1222 |
super(substitutionOffset, ElementHandle.create(elem), whiteList); |
1222 |
super(substitutionOffset, ElementHandle.create(elem), whiteList); |
1223 |
this.isInherited = isInherited; |
1223 |
this.isInherited = isInherited; |
Lines 1235-1249
Link Here
|
1235 |
this.assignToVarPos = assignToVarPos; |
1235 |
this.assignToVarPos = assignToVarPos; |
1236 |
this.assignToVarText = assignToVarPos < 0 ? null : getAssignToVarText(info, type, this.simpleName); |
1236 |
this.assignToVarText = assignToVarPos < 0 ? null : getAssignToVarText(info, type, this.simpleName); |
1237 |
} |
1237 |
} |
1238 |
|
1238 |
|
1239 |
public int getSortPriority() { |
1239 |
public int getSortPriority() { |
1240 |
return smartType ? 300 - SMART_TYPE : 300; |
1240 |
return smartType ? 300 - SMART_TYPE : 300; |
1241 |
} |
1241 |
} |
1242 |
|
1242 |
|
1243 |
public CharSequence getSortText() { |
1243 |
public CharSequence getSortText() { |
1244 |
return simpleName + "#" + enclSortText; //NOI18N |
1244 |
return simpleName + "#" + enclSortText; //NOI18N |
1245 |
} |
1245 |
} |
1246 |
|
1246 |
|
1247 |
public CharSequence getInsertPrefix() { |
1247 |
public CharSequence getInsertPrefix() { |
1248 |
return simpleName; |
1248 |
return simpleName; |
1249 |
} |
1249 |
} |
Lines 1276-1288
Link Here
|
1276 |
rightText = escape(typeName); |
1276 |
rightText = escape(typeName); |
1277 |
return rightText; |
1277 |
return rightText; |
1278 |
} |
1278 |
} |
1279 |
|
1279 |
|
1280 |
protected ImageIcon getBaseIcon(){ |
1280 |
protected ImageIcon getBaseIcon(){ |
1281 |
int level = getProtectionLevel(modifiers); |
1281 |
int level = getProtectionLevel(modifiers); |
1282 |
boolean isStatic = modifiers.contains(Modifier.STATIC); |
1282 |
boolean isStatic = modifiers.contains(Modifier.STATIC); |
1283 |
ImageIcon cachedIcon = icon[isStatic?1:0][level]; |
1283 |
ImageIcon cachedIcon = icon[isStatic?1:0][level]; |
1284 |
if (cachedIcon != null) |
1284 |
if (cachedIcon != null) |
1285 |
return cachedIcon; |
1285 |
return cachedIcon; |
1286 |
|
1286 |
|
1287 |
String iconPath = FIELD_PUBLIC; |
1287 |
String iconPath = FIELD_PUBLIC; |
1288 |
if (isStatic) { |
1288 |
if (isStatic) { |
Lines 1324-1330
Link Here
|
1324 |
} |
1324 |
} |
1325 |
ImageIcon newIcon = ImageUtilities.loadImageIcon(iconPath, false); |
1325 |
ImageIcon newIcon = ImageUtilities.loadImageIcon(iconPath, false); |
1326 |
icon[isStatic?1:0][level] = newIcon; |
1326 |
icon[isStatic?1:0][level] = newIcon; |
1327 |
return newIcon; |
1327 |
return newIcon; |
1328 |
} |
1328 |
} |
1329 |
|
1329 |
|
1330 |
@Override |
1330 |
@Override |
Lines 1379-1385
Link Here
|
1379 |
tmp.insert(c); |
1379 |
tmp.insert(c); |
1380 |
} |
1380 |
} |
1381 |
} |
1381 |
} |
1382 |
} catch (BadLocationException ble) { |
1382 |
} catch (BadLocationException ble) { |
1383 |
} |
1383 |
} |
1384 |
} |
1384 |
} |
1385 |
|
1385 |
|
Lines 1395-1412
Link Here
|
1395 |
return sb.toString(); |
1395 |
return sb.toString(); |
1396 |
} |
1396 |
} |
1397 |
} |
1397 |
} |
1398 |
|
1398 |
|
1399 |
static class MethodItem extends WhiteListJavaCompletionItem<ExecutableElement> { |
1399 |
static class MethodItem extends WhiteListJavaCompletionItem<ExecutableElement> { |
1400 |
|
1400 |
|
1401 |
private static final String METHOD_PUBLIC = "org/netbeans/modules/editor/resources/completion/method_16.png"; //NOI18N |
1401 |
private static final String METHOD_PUBLIC = "org/netbeans/modules/editor/resources/completion/method_16.png"; //NOI18N |
1402 |
private static final String METHOD_PROTECTED = "org/netbeans/modules/editor/resources/completion/method_protected_16.png"; //NOI18N |
1402 |
private static final String METHOD_PROTECTED = "org/netbeans/modules/editor/resources/completion/method_protected_16.png"; //NOI18N |
1403 |
private static final String METHOD_PACKAGE = "org/netbeans/modules/editor/resources/completion/method_package_private_16.png"; //NOI18N |
1403 |
private static final String METHOD_PACKAGE = "org/netbeans/modules/editor/resources/completion/method_package_private_16.png"; //NOI18N |
1404 |
private static final String METHOD_PRIVATE = "org/netbeans/modules/editor/resources/completion/method_private_16.png"; //NOI18N |
1404 |
private static final String METHOD_PRIVATE = "org/netbeans/modules/editor/resources/completion/method_private_16.png"; //NOI18N |
1405 |
private static final String METHOD_ST_PUBLIC = "org/netbeans/modules/editor/resources/completion/method_static_16.png"; //NOI18N |
1405 |
private static final String METHOD_ST_PUBLIC = "org/netbeans/modules/editor/resources/completion/method_static_16.png"; //NOI18N |
1406 |
private static final String METHOD_ST_PROTECTED = "org/netbeans/modules/editor/resources/completion/method_static_protected_16.png"; //NOI18N |
1406 |
private static final String METHOD_ST_PROTECTED = "org/netbeans/modules/editor/resources/completion/method_static_protected_16.png"; //NOI18N |
1407 |
private static final String METHOD_ST_PRIVATE = "org/netbeans/modules/editor/resources/completion/method_static_private_16.png"; //NOI18N |
1407 |
private static final String METHOD_ST_PRIVATE = "org/netbeans/modules/editor/resources/completion/method_static_private_16.png"; //NOI18N |
1408 |
private static final String METHOD_ST_PACKAGE = "org/netbeans/modules/editor/resources/completion/method_static_package_private_16.png"; //NOI18N |
1408 |
private static final String METHOD_ST_PACKAGE = "org/netbeans/modules/editor/resources/completion/method_static_package_private_16.png"; //NOI18N |
1409 |
private static final String METHOD_COLOR = "<font color=#000000>"; //NOI18N |
|
|
1410 |
private static final String PARAMETER_NAME_COLOR = "<font color=#a06001>"; //NOI18N |
1409 |
private static final String PARAMETER_NAME_COLOR = "<font color=#a06001>"; //NOI18N |
1411 |
private static ImageIcon icon[][] = new ImageIcon[2][4]; |
1410 |
private static ImageIcon icon[][] = new ImageIcon[2][4]; |
1412 |
|
1411 |
|
Lines 1426-1432
Link Here
|
1426 |
private CharSequence enclSortText; |
1425 |
private CharSequence enclSortText; |
1427 |
private int assignToVarPos; |
1426 |
private int assignToVarPos; |
1428 |
private String assignToVarText; |
1427 |
private String assignToVarText; |
1429 |
|
1428 |
|
1430 |
private MethodItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean inImport, boolean addSemicolon, boolean smartType, int assignToVarPos, WhiteListQuery.WhiteList whiteList) { |
1429 |
private MethodItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, ReferencesCount referencesCount, boolean isInherited, boolean isDeprecated, boolean inImport, boolean addSemicolon, boolean smartType, int assignToVarPos, WhiteListQuery.WhiteList whiteList) { |
1431 |
super(substitutionOffset, ElementHandle.create(elem), whiteList); |
1430 |
super(substitutionOffset, ElementHandle.create(elem), whiteList); |
1432 |
this.isInherited = isInherited; |
1431 |
this.isInherited = isInherited; |
Lines 1456-1466
Link Here
|
1456 |
this.assignToVarPos = type.getReturnType().getKind() == TypeKind.VOID ? -1 : assignToVarPos; |
1455 |
this.assignToVarPos = type.getReturnType().getKind() == TypeKind.VOID ? -1 : assignToVarPos; |
1457 |
this.assignToVarText = this.assignToVarPos < 0 ? null : getAssignToVarText(info, type.getReturnType(), this.simpleName); |
1456 |
this.assignToVarText = this.assignToVarPos < 0 ? null : getAssignToVarText(info, type.getReturnType(), this.simpleName); |
1458 |
} |
1457 |
} |
1459 |
|
1458 |
|
1460 |
public int getSortPriority() { |
1459 |
public int getSortPriority() { |
1461 |
return smartType ? 500 - SMART_TYPE : 500; |
1460 |
return smartType ? 500 - SMART_TYPE : 500; |
1462 |
} |
1461 |
} |
1463 |
|
1462 |
|
1464 |
public CharSequence getSortText() { |
1463 |
public CharSequence getSortText() { |
1465 |
if (sortText == null) { |
1464 |
if (sortText == null) { |
1466 |
StringBuilder sortParams = new StringBuilder(); |
1465 |
StringBuilder sortParams = new StringBuilder(); |
Lines 1479-1493
Link Here
|
1479 |
} |
1478 |
} |
1480 |
return sortText; |
1479 |
return sortText; |
1481 |
} |
1480 |
} |
1482 |
|
1481 |
|
1483 |
public CharSequence getInsertPrefix() { |
1482 |
public CharSequence getInsertPrefix() { |
1484 |
return simpleName; |
1483 |
return simpleName; |
1485 |
} |
1484 |
} |
1486 |
|
1485 |
|
1487 |
protected String getLeftHtmlText() { |
1486 |
protected String getLeftHtmlText() { |
1488 |
if (leftText == null) { |
1487 |
if (leftText == null) { |
1489 |
StringBuilder lText = new StringBuilder(); |
1488 |
StringBuilder lText = new StringBuilder(); |
1490 |
lText.append(METHOD_COLOR); |
1489 |
lText.append(LFCustoms.getTextFgColorHTML()); |
1491 |
if (!isInherited) |
1490 |
if (!isInherited) |
1492 |
lText.append(BOLD); |
1491 |
lText.append(BOLD); |
1493 |
if (isDeprecated || isBlackListed()) |
1492 |
if (isDeprecated || isBlackListed()) |
Lines 1521-1527
Link Here
|
1521 |
rightText = escape(typeName); |
1520 |
rightText = escape(typeName); |
1522 |
return rightText; |
1521 |
return rightText; |
1523 |
} |
1522 |
} |
1524 |
|
1523 |
|
1525 |
public CompletionTask createDocumentationTask() { |
1524 |
public CompletionTask createDocumentationTask() { |
1526 |
return JavaCompletionProvider.createDocTask(getElementHandle()); |
1525 |
return JavaCompletionProvider.createDocTask(getElementHandle()); |
1527 |
} |
1526 |
} |
Lines 1532-1539
Link Here
|
1532 |
ImageIcon cachedIcon = icon[isStatic?1:0][level]; |
1531 |
ImageIcon cachedIcon = icon[isStatic?1:0][level]; |
1533 |
if (cachedIcon != null) |
1532 |
if (cachedIcon != null) |
1534 |
return cachedIcon; |
1533 |
return cachedIcon; |
1535 |
|
1534 |
|
1536 |
String iconPath = METHOD_PUBLIC; |
1535 |
String iconPath = METHOD_PUBLIC; |
1537 |
if (isStatic) { |
1536 |
if (isStatic) { |
1538 |
switch (level) { |
1537 |
switch (level) { |
1539 |
case PRIVATE_LEVEL: |
1538 |
case PRIVATE_LEVEL: |
Lines 1573-1581
Link Here
|
1573 |
} |
1572 |
} |
1574 |
ImageIcon newIcon = ImageUtilities.loadImageIcon(iconPath, false); |
1573 |
ImageIcon newIcon = ImageUtilities.loadImageIcon(iconPath, false); |
1575 |
icon[isStatic?1:0][level] = newIcon; |
1574 |
icon[isStatic?1:0][level] = newIcon; |
1576 |
return newIcon; |
1575 |
return newIcon; |
1577 |
} |
1576 |
} |
1578 |
|
1577 |
|
1579 |
@Override |
1578 |
@Override |
1580 |
protected void substituteText(final JTextComponent c, final int offset, int len, String toAdd, final boolean assignToVar) { |
1579 |
protected void substituteText(final JTextComponent c, final int offset, int len, String toAdd, final boolean assignToVar) { |
1581 |
try { |
1580 |
try { |
Lines 1613-1619
Link Here
|
1613 |
AutoImport.resolveImport(controller, controller.getTreeUtilities().pathFor(embeddedOffset), ee.getEnclosingElement().asType()); |
1612 |
AutoImport.resolveImport(controller, controller.getTreeUtilities().pathFor(embeddedOffset), ee.getEnclosingElement().asType()); |
1614 |
} |
1613 |
} |
1615 |
}); |
1614 |
}); |
1616 |
} catch (ParseException pe) { |
1615 |
} catch (ParseException pe) { |
1617 |
} |
1616 |
} |
1618 |
} |
1617 |
} |
1619 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-import_resolve"), cancel, false); //NOI18N |
1618 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-import_resolve"), cancel, false); //NOI18N |
Lines 1686-1692
Link Here
|
1686 |
Position semiPosition = semiPos > -1 ? doc.createPosition(semiPos) : null; |
1685 |
Position semiPosition = semiPos > -1 ? doc.createPosition(semiPos) : null; |
1687 |
String textToReplace = doc.getText(pos.getOffset(), length); |
1686 |
String textToReplace = doc.getText(pos.getOffset(), length); |
1688 |
if (textToReplace.contentEquals(getInsertPrefix() + sb.toString())) { |
1687 |
if (textToReplace.contentEquals(getInsertPrefix() + sb.toString())) { |
1689 |
c.setCaretPosition(c.getCaretPosition() + sb.length()); |
1688 |
c.setCaretPosition(c.getCaretPosition() + sb.length()); |
1690 |
sb.delete(0, sb.length()); |
1689 |
sb.delete(0, sb.length()); |
1691 |
} else { |
1690 |
} else { |
1692 |
if (length > 0) |
1691 |
if (length > 0) |
Lines 1724-1730
Link Here
|
1724 |
AutoImport.resolveImport(controller, controller.getTreeUtilities().pathFor(embeddedOffset), ee.getEnclosingElement().asType()); |
1723 |
AutoImport.resolveImport(controller, controller.getTreeUtilities().pathFor(embeddedOffset), ee.getEnclosingElement().asType()); |
1725 |
} |
1724 |
} |
1726 |
}); |
1725 |
}); |
1727 |
} catch (ParseException pe) { |
1726 |
} catch (ParseException pe) { |
1728 |
} |
1727 |
} |
1729 |
} |
1728 |
} |
1730 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-import_resolve"), cancel, false); //NOI18N |
1729 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-import_resolve"), cancel, false); //NOI18N |
Lines 1770-1776
Link Here
|
1770 |
} |
1769 |
} |
1771 |
} catch (BadLocationException ex) { |
1770 |
} catch (BadLocationException ex) { |
1772 |
} |
1771 |
} |
1773 |
} |
1772 |
} |
1774 |
|
1773 |
|
1775 |
public String toString() { |
1774 |
public String toString() { |
1776 |
StringBuilder sb = new StringBuilder(); |
1775 |
StringBuilder sb = new StringBuilder(); |
Lines 1794-1822
Link Here
|
1794 |
sb.append(')'); |
1793 |
sb.append(')'); |
1795 |
return sb.toString(); |
1794 |
return sb.toString(); |
1796 |
} |
1795 |
} |
1797 |
} |
1796 |
} |
1798 |
|
1797 |
|
1799 |
static class OverrideMethodItem extends MethodItem { |
1798 |
static class OverrideMethodItem extends MethodItem { |
1800 |
|
1799 |
|
1801 |
private static final String IMPL_BADGE_PATH = "org/netbeans/modules/java/editor/resources/implement_badge.png"; |
1800 |
private static final String IMPL_BADGE_PATH = "org/netbeans/modules/java/editor/resources/implement_badge.png"; |
1802 |
private static final String OVRD_BADGE_PATH = "org/netbeans/modules/java/editor/resources/override_badge.png"; |
1801 |
private static final String OVRD_BADGE_PATH = "org/netbeans/modules/java/editor/resources/override_badge.png"; |
1803 |
|
1802 |
|
1804 |
private static final String OVERRIDE_TEXT = NbBundle.getMessage(JavaCompletionItem.class, "override_Lbl"); |
1803 |
private static final String OVERRIDE_TEXT = NbBundle.getMessage(JavaCompletionItem.class, "override_Lbl"); |
1805 |
private static final String IMPLEMENT_TEXT = NbBundle.getMessage(JavaCompletionItem.class, "implement_Lbl"); |
1804 |
private static final String IMPLEMENT_TEXT = NbBundle.getMessage(JavaCompletionItem.class, "implement_Lbl"); |
1806 |
|
1805 |
|
1807 |
private static ImageIcon implementBadge = ImageUtilities.loadImageIcon(IMPL_BADGE_PATH, false); |
1806 |
private static ImageIcon implementBadge = ImageUtilities.loadImageIcon(IMPL_BADGE_PATH, false); |
1808 |
private static ImageIcon overrideBadge = ImageUtilities.loadImageIcon(OVRD_BADGE_PATH, false); |
1807 |
private static ImageIcon overrideBadge = ImageUtilities.loadImageIcon(OVRD_BADGE_PATH, false); |
1809 |
private static ImageIcon merged_icon[][] = new ImageIcon[2][4]; |
1808 |
private static ImageIcon merged_icon[][] = new ImageIcon[2][4]; |
1810 |
|
1809 |
|
1811 |
|
1810 |
|
1812 |
private boolean implement; |
1811 |
private boolean implement; |
1813 |
private String leftText; |
1812 |
private String leftText; |
1814 |
|
1813 |
|
1815 |
private OverrideMethodItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean implement, WhiteListQuery.WhiteList whiteList) { |
1814 |
private OverrideMethodItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean implement, WhiteListQuery.WhiteList whiteList) { |
1816 |
super(info, elem, type, substitutionOffset, null, false, false, false, false, false, -1, whiteList); |
1815 |
super(info, elem, type, substitutionOffset, null, false, false, false, false, false, -1, whiteList); |
1817 |
this.implement = implement; |
1816 |
this.implement = implement; |
1818 |
} |
1817 |
} |
1819 |
|
1818 |
|
1820 |
protected String getLeftHtmlText() { |
1819 |
protected String getLeftHtmlText() { |
1821 |
if (leftText == null) { |
1820 |
if (leftText == null) { |
1822 |
leftText = super.getLeftHtmlText() + " - "; |
1821 |
leftText = super.getLeftHtmlText() + " - "; |
Lines 1824-1830
Link Here
|
1824 |
} |
1823 |
} |
1825 |
return leftText; |
1824 |
return leftText; |
1826 |
} |
1825 |
} |
1827 |
|
1826 |
|
1828 |
@Override |
1827 |
@Override |
1829 |
protected ImageIcon getBaseIcon() { |
1828 |
protected ImageIcon getBaseIcon() { |
1830 |
int level = getProtectionLevel(modifiers); |
1829 |
int level = getProtectionLevel(modifiers); |
Lines 1832-1849
Link Here
|
1832 |
if ( merged != null ) { |
1831 |
if ( merged != null ) { |
1833 |
return merged; |
1832 |
return merged; |
1834 |
} |
1833 |
} |
1835 |
ImageIcon superIcon = super.getBaseIcon(); |
1834 |
ImageIcon superIcon = super.getBaseIcon(); |
1836 |
merged = new ImageIcon( ImageUtilities.mergeImages( |
1835 |
merged = new ImageIcon( ImageUtilities.mergeImages( |
1837 |
superIcon.getImage(), |
1836 |
superIcon.getImage(), |
1838 |
implement ? implementBadge.getImage() : overrideBadge.getImage(), |
1837 |
implement ? implementBadge.getImage() : overrideBadge.getImage(), |
1839 |
16 - 8, |
1838 |
16 - 8, |
1840 |
16 - 8) ); |
1839 |
16 - 8) ); |
1841 |
|
1840 |
|
1842 |
merged_icon[implement? 0 : 1][level] = merged; |
1841 |
merged_icon[implement? 0 : 1][level] = merged; |
1843 |
return merged; |
1842 |
return merged; |
1844 |
} |
1843 |
} |
1845 |
|
1844 |
|
1846 |
|
1845 |
|
1847 |
@Override |
1846 |
@Override |
1848 |
protected void substituteText(final JTextComponent c, final int offset, final int len, String toAdd, final boolean assignToVar) { |
1847 |
protected void substituteText(final JTextComponent c, final int offset, final int len, String toAdd, final boolean assignToVar) { |
1849 |
final BaseDocument doc = (BaseDocument)c.getDocument(); |
1848 |
final BaseDocument doc = (BaseDocument)c.getDocument(); |
Lines 1912-1927
Link Here
|
1912 |
} |
1911 |
} |
1913 |
|
1912 |
|
1914 |
static class GetterSetterMethodItem extends JavaCompletionItem { |
1913 |
static class GetterSetterMethodItem extends JavaCompletionItem { |
1915 |
|
1914 |
|
1916 |
private static final String METHOD_PUBLIC = "org/netbeans/modules/editor/resources/completion/method_16.png"; //NOI18N |
1915 |
private static final String METHOD_PUBLIC = "org/netbeans/modules/editor/resources/completion/method_16.png"; //NOI18N |
1917 |
private static final String GETTER_BADGE_PATH = "org/netbeans/modules/java/editor/resources/getter_badge.png"; //NOI18N |
1916 |
private static final String GETTER_BADGE_PATH = "org/netbeans/modules/java/editor/resources/getter_badge.png"; //NOI18N |
1918 |
private static final String SETTER_BADGE_PATH = "org/netbeans/modules/java/editor/resources/setter_badge.png"; //NOI18N |
1917 |
private static final String SETTER_BADGE_PATH = "org/netbeans/modules/java/editor/resources/setter_badge.png"; //NOI18N |
1919 |
private static final String METHOD_COLOR = "<font color=#000000>"; //NOI18N |
|
|
1920 |
private static final String PARAMETER_NAME_COLOR = "<font color=#a06001>"; //NOI18N |
1918 |
private static final String PARAMETER_NAME_COLOR = "<font color=#a06001>"; //NOI18N |
1921 |
|
1919 |
|
1922 |
private static ImageIcon superIcon; |
1920 |
private static ImageIcon superIcon; |
1923 |
private static ImageIcon[] merged_icons = new ImageIcon[2]; |
1921 |
private static ImageIcon[] merged_icons = new ImageIcon[2]; |
1924 |
|
1922 |
|
1925 |
protected ElementHandle<VariableElement> elementHandle; |
1923 |
protected ElementHandle<VariableElement> elementHandle; |
1926 |
private boolean setter; |
1924 |
private boolean setter; |
1927 |
private String simpleName; |
1925 |
private String simpleName; |
Lines 1930-1939
Link Here
|
1930 |
private String sortText; |
1928 |
private String sortText; |
1931 |
private String leftText; |
1929 |
private String leftText; |
1932 |
private String rightText; |
1930 |
private String rightText; |
1933 |
|
1931 |
|
1934 |
private GetterSetterMethodItem(CompilationInfo info, VariableElement elem, TypeMirror type, int substitutionOffset, boolean setter) { |
1932 |
private GetterSetterMethodItem(CompilationInfo info, VariableElement elem, TypeMirror type, int substitutionOffset, boolean setter) { |
1935 |
super(substitutionOffset); |
1933 |
super(substitutionOffset); |
1936 |
this.elementHandle = ElementHandle.create(elem); |
1934 |
this.elementHandle = ElementHandle.create(elem); |
1937 |
this.setter = setter; |
1935 |
this.setter = setter; |
1938 |
this.simpleName = elem.getSimpleName().toString(); |
1936 |
this.simpleName = elem.getSimpleName().toString(); |
1939 |
if (setter) |
1937 |
if (setter) |
Lines 1942-1952
Link Here
|
1942 |
this.name = (elem.asType().getKind() == TypeKind.BOOLEAN ? "is" : "get") + GeneratorUtils.getCapitalizedName(simpleName); //NOI18N |
1940 |
this.name = (elem.asType().getKind() == TypeKind.BOOLEAN ? "is" : "get") + GeneratorUtils.getCapitalizedName(simpleName); //NOI18N |
1943 |
this.typeName = Utilities.getTypeName(info, type, false).toString(); |
1941 |
this.typeName = Utilities.getTypeName(info, type, false).toString(); |
1944 |
} |
1942 |
} |
1945 |
|
1943 |
|
1946 |
public int getSortPriority() { |
1944 |
public int getSortPriority() { |
1947 |
return 500; |
1945 |
return 500; |
1948 |
} |
1946 |
} |
1949 |
|
1947 |
|
1950 |
public CharSequence getSortText() { |
1948 |
public CharSequence getSortText() { |
1951 |
if (sortText == null) { |
1949 |
if (sortText == null) { |
1952 |
StringBuilder sortParams = new StringBuilder(); |
1950 |
StringBuilder sortParams = new StringBuilder(); |
Lines 1958-1973
Link Here
|
1958 |
} |
1956 |
} |
1959 |
return sortText; |
1957 |
return sortText; |
1960 |
} |
1958 |
} |
1961 |
|
1959 |
|
1962 |
public CharSequence getInsertPrefix() { |
1960 |
public CharSequence getInsertPrefix() { |
1963 |
return name; |
1961 |
return name; |
1964 |
} |
1962 |
} |
1965 |
|
1963 |
|
1966 |
@Override |
1964 |
@Override |
1967 |
protected String getLeftHtmlText() { |
1965 |
protected String getLeftHtmlText() { |
1968 |
if (leftText == null) { |
1966 |
if (leftText == null) { |
1969 |
StringBuilder lText = new StringBuilder(); |
1967 |
StringBuilder lText = new StringBuilder(); |
1970 |
lText.append(METHOD_COLOR); |
1968 |
lText.append(LFCustoms.getTextFgColorHTML()); |
1971 |
lText.append(BOLD); |
1969 |
lText.append(BOLD); |
1972 |
lText.append(name); |
1970 |
lText.append(name); |
1973 |
lText.append(BOLD_END); |
1971 |
lText.append(BOLD_END); |
Lines 1986-1999
Link Here
|
1986 |
} |
1984 |
} |
1987 |
return leftText; |
1985 |
return leftText; |
1988 |
} |
1986 |
} |
1989 |
|
1987 |
|
1990 |
@Override |
1988 |
@Override |
1991 |
protected String getRightHtmlText() { |
1989 |
protected String getRightHtmlText() { |
1992 |
if (rightText == null) |
1990 |
if (rightText == null) |
1993 |
rightText = setter ? "void" : escape(typeName); |
1991 |
rightText = setter ? "void" : escape(typeName); |
1994 |
return rightText; |
1992 |
return rightText; |
1995 |
} |
1993 |
} |
1996 |
|
1994 |
|
1997 |
@Override |
1995 |
@Override |
1998 |
protected ImageIcon getIcon() { |
1996 |
protected ImageIcon getIcon() { |
1999 |
if (merged_icons[setter ? 1 : 0] == null) { |
1997 |
if (merged_icons[setter ? 1 : 0] == null) { |
Lines 2011-2017
Link Here
|
2011 |
} |
2009 |
} |
2012 |
return merged_icons[setter ? 1 : 0]; |
2010 |
return merged_icons[setter ? 1 : 0]; |
2013 |
} |
2011 |
} |
2014 |
|
2012 |
|
2015 |
@Override |
2013 |
@Override |
2016 |
protected void substituteText(final JTextComponent c, final int offset, final int len, String toAdd, final boolean assignToVar) { |
2014 |
protected void substituteText(final JTextComponent c, final int offset, final int len, String toAdd, final boolean assignToVar) { |
2017 |
final BaseDocument doc = (BaseDocument)c.getDocument(); |
2015 |
final BaseDocument doc = (BaseDocument)c.getDocument(); |
Lines 2038-2044
Link Here
|
2038 |
public void run(ResultIterator resultIterator) throws Exception { |
2036 |
public void run(ResultIterator resultIterator) throws Exception { |
2039 |
WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult()); |
2037 |
WorkingCopy copy = WorkingCopy.get(resultIterator.getParserResult()); |
2040 |
copy.toPhase(Phase.ELEMENTS_RESOLVED); |
2038 |
copy.toPhase(Phase.ELEMENTS_RESOLVED); |
2041 |
VariableElement ve = elementHandle.resolve(copy); |
2039 |
VariableElement ve = elementHandle.resolve(copy); |
2042 |
if (ve == null) |
2040 |
if (ve == null) |
2043 |
return; |
2041 |
return; |
2044 |
final int embeddedOffset = copy.getSnapshot().getEmbeddedOffset(pos.getOffset()); |
2042 |
final int embeddedOffset = copy.getSnapshot().getEmbeddedOffset(pos.getOffset()); |
Lines 2094-2100
Link Here
|
2094 |
} |
2092 |
} |
2095 |
|
2093 |
|
2096 |
static class ConstructorItem extends WhiteListJavaCompletionItem<ExecutableElement> { |
2094 |
static class ConstructorItem extends WhiteListJavaCompletionItem<ExecutableElement> { |
2097 |
|
2095 |
|
2098 |
private static final String CONSTRUCTOR_PUBLIC = "org/netbeans/modules/editor/resources/completion/constructor_16.png"; //NOI18N |
2096 |
private static final String CONSTRUCTOR_PUBLIC = "org/netbeans/modules/editor/resources/completion/constructor_16.png"; //NOI18N |
2099 |
private static final String CONSTRUCTOR_PROTECTED = "org/netbeans/modules/editor/resources/completion/constructor_protected_16.png"; //NOI18N |
2097 |
private static final String CONSTRUCTOR_PROTECTED = "org/netbeans/modules/editor/resources/completion/constructor_protected_16.png"; //NOI18N |
2100 |
private static final String CONSTRUCTOR_PACKAGE = "org/netbeans/modules/editor/resources/completion/constructor_package_private_16.png"; //NOI18N |
2098 |
private static final String CONSTRUCTOR_PACKAGE = "org/netbeans/modules/editor/resources/completion/constructor_package_private_16.png"; //NOI18N |
Lines 2112-2118
Link Here
|
2112 |
private boolean insertName; |
2110 |
private boolean insertName; |
2113 |
private String sortText; |
2111 |
private String sortText; |
2114 |
private String leftText; |
2112 |
private String leftText; |
2115 |
|
2113 |
|
2116 |
private ConstructorItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, boolean smartType, String name, WhiteListQuery.WhiteList whiteList) { |
2114 |
private ConstructorItem(CompilationInfo info, ExecutableElement elem, ExecutableType type, int substitutionOffset, boolean isDeprecated, boolean smartType, String name, WhiteListQuery.WhiteList whiteList) { |
2117 |
super(substitutionOffset, ElementHandle.create(elem), whiteList); |
2115 |
super(substitutionOffset, ElementHandle.create(elem), whiteList); |
2118 |
this.isDeprecated = isDeprecated; |
2116 |
this.isDeprecated = isDeprecated; |
Lines 2131-2141
Link Here
|
2131 |
} |
2129 |
} |
2132 |
this.isAbstract = !insertName && elem.getEnclosingElement().getModifiers().contains(Modifier.ABSTRACT); |
2130 |
this.isAbstract = !insertName && elem.getEnclosingElement().getModifiers().contains(Modifier.ABSTRACT); |
2133 |
} |
2131 |
} |
2134 |
|
2132 |
|
2135 |
public int getSortPriority() { |
2133 |
public int getSortPriority() { |
2136 |
return insertName ? 550 : smartType ? 650 - SMART_TYPE : 650; |
2134 |
return insertName ? 550 : smartType ? 650 - SMART_TYPE : 650; |
2137 |
} |
2135 |
} |
2138 |
|
2136 |
|
2139 |
public CharSequence getSortText() { |
2137 |
public CharSequence getSortText() { |
2140 |
if (sortText == null) { |
2138 |
if (sortText == null) { |
2141 |
StringBuilder sortParams = new StringBuilder(); |
2139 |
StringBuilder sortParams = new StringBuilder(); |
Lines 2154-2164
Link Here
|
2154 |
} |
2152 |
} |
2155 |
return sortText; |
2153 |
return sortText; |
2156 |
} |
2154 |
} |
2157 |
|
2155 |
|
2158 |
public CharSequence getInsertPrefix() { |
2156 |
public CharSequence getInsertPrefix() { |
2159 |
return simpleName; |
2157 |
return simpleName; |
2160 |
} |
2158 |
} |
2161 |
|
2159 |
|
2162 |
protected String getLeftHtmlText() { |
2160 |
protected String getLeftHtmlText() { |
2163 |
if (leftText == null) { |
2161 |
if (leftText == null) { |
2164 |
StringBuilder lText = new StringBuilder(); |
2162 |
StringBuilder lText = new StringBuilder(); |
Lines 2199-2206
Link Here
|
2199 |
ImageIcon cachedIcon = icon[level]; |
2197 |
ImageIcon cachedIcon = icon[level]; |
2200 |
if (cachedIcon != null) |
2198 |
if (cachedIcon != null) |
2201 |
return cachedIcon; |
2199 |
return cachedIcon; |
2202 |
|
2200 |
|
2203 |
String iconPath = CONSTRUCTOR_PUBLIC; |
2201 |
String iconPath = CONSTRUCTOR_PUBLIC; |
2204 |
switch (level) { |
2202 |
switch (level) { |
2205 |
case PRIVATE_LEVEL: |
2203 |
case PRIVATE_LEVEL: |
2206 |
iconPath = CONSTRUCTOR_PRIVATE; |
2204 |
iconPath = CONSTRUCTOR_PRIVATE; |
Lines 2220-2228
Link Here
|
2220 |
} |
2218 |
} |
2221 |
ImageIcon newIcon = ImageUtilities.loadImageIcon(iconPath, false); |
2219 |
ImageIcon newIcon = ImageUtilities.loadImageIcon(iconPath, false); |
2222 |
icon[level] = newIcon; |
2220 |
icon[level] = newIcon; |
2223 |
return newIcon; |
2221 |
return newIcon; |
2224 |
} |
2222 |
} |
2225 |
|
2223 |
|
2226 |
@Override |
2224 |
@Override |
2227 |
protected void substituteText(final JTextComponent c, int offset, int len, String toAdd, final boolean assignToVar) { |
2225 |
protected void substituteText(final JTextComponent c, int offset, int len, String toAdd, final boolean assignToVar) { |
2228 |
if (!insertName) { |
2226 |
if (!insertName) { |
Lines 2315-2325
Link Here
|
2315 |
TreePath path = copy.getTreeUtilities().pathFor(embeddedOffset); |
2313 |
TreePath path = copy.getTreeUtilities().pathFor(embeddedOffset); |
2316 |
while (path.getLeaf() != path.getCompilationUnit()) { |
2314 |
while (path.getLeaf() != path.getCompilationUnit()) { |
2317 |
Tree tree = path.getLeaf(); |
2315 |
Tree tree = path.getLeaf(); |
2318 |
Tree parentTree = path.getParentPath().getLeaf(); |
2316 |
Tree parentTree = path.getParentPath().getLeaf(); |
2319 |
if (parentTree.getKind() == Tree.Kind.NEW_CLASS && TreeUtilities.CLASS_TREE_KINDS.contains(tree.getKind())) { |
2317 |
if (parentTree.getKind() == Tree.Kind.NEW_CLASS && TreeUtilities.CLASS_TREE_KINDS.contains(tree.getKind())) { |
2320 |
GeneratorUtils.generateAllAbstractMethodImplementations(copy, path); |
2318 |
GeneratorUtils.generateAllAbstractMethodImplementations(copy, path); |
2321 |
break; |
2319 |
break; |
2322 |
} |
2320 |
} |
2323 |
path = path.getParentPath(); |
2321 |
path = path.getParentPath(); |
2324 |
} |
2322 |
} |
2325 |
} |
2323 |
} |
Lines 2364-2370
Link Here
|
2364 |
Completion.get().showToolTip(); |
2362 |
Completion.get().showToolTip(); |
2365 |
} |
2363 |
} |
2366 |
} |
2364 |
} |
2367 |
} |
2365 |
} |
2368 |
|
2366 |
|
2369 |
public String toString() { |
2367 |
public String toString() { |
2370 |
StringBuilder sb = new StringBuilder(); |
2368 |
StringBuilder sb = new StringBuilder(); |
Lines 2387-2399
Link Here
|
2387 |
return sb.toString(); |
2385 |
return sb.toString(); |
2388 |
} |
2386 |
} |
2389 |
} |
2387 |
} |
2390 |
|
2388 |
|
2391 |
static class DefaultConstructorItem extends JavaCompletionItem { |
2389 |
static class DefaultConstructorItem extends JavaCompletionItem { |
2392 |
|
2390 |
|
2393 |
private static final String CONSTRUCTOR = "org/netbeans/modules/java/editor/resources/new_constructor_16.png"; //NOI18N |
2391 |
private static final String CONSTRUCTOR = "org/netbeans/modules/java/editor/resources/new_constructor_16.png"; //NOI18N |
2394 |
private static final String CONSTRUCTOR_COLOR = "<font color=#b28b00>"; //NOI18N |
2392 |
private static final String CONSTRUCTOR_COLOR = "<font color=#b28b00>"; //NOI18N |
2395 |
private static ImageIcon icon; |
2393 |
private static ImageIcon icon; |
2396 |
|
2394 |
|
2397 |
private boolean smartType; |
2395 |
private boolean smartType; |
2398 |
private String simpleName; |
2396 |
private String simpleName; |
2399 |
private boolean isAbstract; |
2397 |
private boolean isAbstract; |
Lines 2420-2435
Link Here
|
2420 |
sortText = simpleName + "#0#"; //NOI18N |
2418 |
sortText = simpleName + "#0#"; //NOI18N |
2421 |
return sortText; |
2419 |
return sortText; |
2422 |
} |
2420 |
} |
2423 |
|
2421 |
|
2424 |
protected String getLeftHtmlText() { |
2422 |
protected String getLeftHtmlText() { |
2425 |
if (leftText == null) |
2423 |
if (leftText == null) |
2426 |
leftText = CONSTRUCTOR_COLOR + simpleName + "()" + COLOR_END; //NOI18N |
2424 |
leftText = CONSTRUCTOR_COLOR + simpleName + "()" + COLOR_END; //NOI18N |
2427 |
return leftText; |
2425 |
return leftText; |
2428 |
} |
2426 |
} |
2429 |
|
2427 |
|
2430 |
protected ImageIcon getIcon() { |
2428 |
protected ImageIcon getIcon() { |
2431 |
if (icon == null) icon = ImageUtilities.loadImageIcon(CONSTRUCTOR, false); |
2429 |
if (icon == null) icon = ImageUtilities.loadImageIcon(CONSTRUCTOR, false); |
2432 |
return icon; |
2430 |
return icon; |
2433 |
} |
2431 |
} |
2434 |
|
2432 |
|
2435 |
@Override |
2433 |
@Override |
Lines 2517-2527
Link Here
|
2517 |
TreePath path = copy.getTreeUtilities().pathFor(embeddedOffset); |
2515 |
TreePath path = copy.getTreeUtilities().pathFor(embeddedOffset); |
2518 |
while (path.getLeaf() != path.getCompilationUnit()) { |
2516 |
while (path.getLeaf() != path.getCompilationUnit()) { |
2519 |
Tree tree = path.getLeaf(); |
2517 |
Tree tree = path.getLeaf(); |
2520 |
Tree parentTree = path.getParentPath().getLeaf(); |
2518 |
Tree parentTree = path.getParentPath().getLeaf(); |
2521 |
if (parentTree.getKind() == Tree.Kind.NEW_CLASS && TreeUtilities.CLASS_TREE_KINDS.contains(tree.getKind())) { |
2519 |
if (parentTree.getKind() == Tree.Kind.NEW_CLASS && TreeUtilities.CLASS_TREE_KINDS.contains(tree.getKind())) { |
2522 |
GeneratorUtils.generateAllAbstractMethodImplementations(copy, path); |
2520 |
GeneratorUtils.generateAllAbstractMethodImplementations(copy, path); |
2523 |
break; |
2521 |
break; |
2524 |
} |
2522 |
} |
2525 |
path = path.getParentPath(); |
2523 |
path = path.getParentPath(); |
2526 |
} |
2524 |
} |
2527 |
} |
2525 |
} |
Lines 2532-2547
Link Here
|
2532 |
} |
2530 |
} |
2533 |
} |
2531 |
} |
2534 |
} |
2532 |
} |
2535 |
|
2533 |
|
2536 |
public String toString() { |
2534 |
public String toString() { |
2537 |
return simpleName + "()"; |
2535 |
return simpleName + "()"; |
2538 |
} |
2536 |
} |
2539 |
} |
2537 |
} |
2540 |
|
2538 |
|
2541 |
static class ParametersItem extends JavaCompletionItem { |
2539 |
static class ParametersItem extends JavaCompletionItem { |
2542 |
|
2540 |
|
2543 |
private static final String PARAMETERS_COLOR = "<font color=#808080>"; //NOI18N |
2541 |
private static final String PARAMETERS_COLOR = "<font color=#808080>"; //NOI18N |
2544 |
private static final String ACTIVE_PARAMETER_COLOR = "<font color=#000000>"; //NOI18N |
|
|
2545 |
|
2542 |
|
2546 |
protected ElementHandle<ExecutableElement> elementHandle; |
2543 |
protected ElementHandle<ExecutableElement> elementHandle; |
2547 |
private boolean isDeprecated; |
2544 |
private boolean isDeprecated; |
Lines 2598-2604
Link Here
|
2598 |
public CharSequence getInsertPrefix() { |
2595 |
public CharSequence getInsertPrefix() { |
2599 |
return ""; //NOI18N |
2596 |
return ""; //NOI18N |
2600 |
} |
2597 |
} |
2601 |
|
2598 |
|
2602 |
protected String getLeftHtmlText() { |
2599 |
protected String getLeftHtmlText() { |
2603 |
if (leftText == null) { |
2600 |
if (leftText == null) { |
2604 |
StringBuilder lText = new StringBuilder(); |
2601 |
StringBuilder lText = new StringBuilder(); |
Lines 2612-2625
Link Here
|
2612 |
for (int i = 0; i < params.size(); i++) { |
2609 |
for (int i = 0; i < params.size(); i++) { |
2613 |
ParamDesc paramDesc = params.get(i); |
2610 |
ParamDesc paramDesc = params.get(i); |
2614 |
if (i == activeParamsIndex) |
2611 |
if (i == activeParamsIndex) |
2615 |
lText.append(COLOR_END).append(ACTIVE_PARAMETER_COLOR).append(BOLD); |
2612 |
lText.append(COLOR_END).append(LFCustoms.getTextFgColorHTML()).append(BOLD); |
2616 |
lText.append(escape(paramDesc.typeName)); |
2613 |
lText.append(escape(paramDesc.typeName)); |
2617 |
lText.append(' '); |
2614 |
lText.append(' '); |
2618 |
lText.append(paramDesc.name); |
2615 |
lText.append(paramDesc.name); |
2619 |
if (i < params.size() - 1) |
2616 |
if (i < params.size() - 1) |
2620 |
lText.append(", "); //NOI18N |
2617 |
lText.append(", "); //NOI18N |
2621 |
else |
2618 |
else |
2622 |
lText.append(BOLD_END).append(COLOR_END).append(PARAMETERS_COLOR); |
2619 |
lText.append(BOLD_END).append(COLOR_END).append(PARAMETERS_COLOR); |
2623 |
} |
2620 |
} |
2624 |
lText.append(')'); |
2621 |
lText.append(')'); |
2625 |
lText.append(COLOR_END); |
2622 |
lText.append(COLOR_END); |
Lines 2627-2639
Link Here
|
2627 |
} |
2624 |
} |
2628 |
return leftText; |
2625 |
return leftText; |
2629 |
} |
2626 |
} |
2630 |
|
2627 |
|
2631 |
protected String getRightHtmlText() { |
2628 |
protected String getRightHtmlText() { |
2632 |
if (rightText == null) |
2629 |
if (rightText == null) |
2633 |
rightText = PARAMETERS_COLOR + escape(typeName) + COLOR_END; |
2630 |
rightText = PARAMETERS_COLOR + escape(typeName) + COLOR_END; |
2634 |
return rightText; |
2631 |
return rightText; |
2635 |
} |
2632 |
} |
2636 |
|
2633 |
|
2637 |
public CompletionTask createDocumentationTask() { |
2634 |
public CompletionTask createDocumentationTask() { |
2638 |
return JavaCompletionProvider.createDocTask(elementHandle); |
2635 |
return JavaCompletionProvider.createDocTask(elementHandle); |
2639 |
} |
2636 |
} |
Lines 2641-2654
Link Here
|
2641 |
public boolean instantSubstitution(JTextComponent component) { |
2638 |
public boolean instantSubstitution(JTextComponent component) { |
2642 |
return false; |
2639 |
return false; |
2643 |
} |
2640 |
} |
2644 |
|
2641 |
|
2645 |
protected void substituteText(final JTextComponent c, final int offset, int len, String toAdd, final boolean assignToVar) { |
2642 |
protected void substituteText(final JTextComponent c, final int offset, int len, String toAdd, final boolean assignToVar) { |
2646 |
String add = ")"; //NOI18N |
2643 |
String add = ")"; //NOI18N |
2647 |
if (toAdd != null && !add.startsWith(toAdd)) |
2644 |
if (toAdd != null && !add.startsWith(toAdd)) |
2648 |
add += toAdd; |
2645 |
add += toAdd; |
2649 |
if (params.isEmpty()) { |
2646 |
if (params.isEmpty()) { |
2650 |
super.substituteText(c, offset, len, add, assignToVar); |
2647 |
super.substituteText(c, offset, len, add, assignToVar); |
2651 |
} else { |
2648 |
} else { |
2652 |
final BaseDocument doc = (BaseDocument)c.getDocument(); |
2649 |
final BaseDocument doc = (BaseDocument)c.getDocument(); |
2653 |
String text = ""; //NOI18N |
2650 |
String text = ""; //NOI18N |
2654 |
final int semiPos = add.endsWith(";") ? findPositionForSemicolon(c) : -2; //NOI18N |
2651 |
final int semiPos = add.endsWith(";") ? findPositionForSemicolon(c) : -2; //NOI18N |
Lines 2719-2725
Link Here
|
2719 |
Completion.get().showToolTip(); |
2716 |
Completion.get().showToolTip(); |
2720 |
} |
2717 |
} |
2721 |
} |
2718 |
} |
2722 |
} |
2719 |
} |
2723 |
|
2720 |
|
2724 |
public String toString() { |
2721 |
public String toString() { |
2725 |
StringBuilder sb = new StringBuilder(); |
2722 |
StringBuilder sb = new StringBuilder(); |
Lines 2740-2748
Link Here
|
2740 |
return sb.toString(); |
2737 |
return sb.toString(); |
2741 |
} |
2738 |
} |
2742 |
} |
2739 |
} |
2743 |
|
2740 |
|
2744 |
static class AnnotationItem extends AnnotationTypeItem { |
2741 |
static class AnnotationItem extends AnnotationTypeItem { |
2745 |
|
2742 |
|
2746 |
private AnnotationItem(CompilationInfo info, TypeElement elem, DeclaredType type, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean smartType, WhiteListQuery.WhiteList whiteList) { |
2743 |
private AnnotationItem(CompilationInfo info, TypeElement elem, DeclaredType type, int substitutionOffset, ReferencesCount referencesCount, boolean isDeprecated, boolean smartType, WhiteListQuery.WhiteList whiteList) { |
2747 |
super(info, elem, type, 0, substitutionOffset, referencesCount, isDeprecated, false, false, smartType, false, whiteList); |
2744 |
super(info, elem, type, 0, substitutionOffset, referencesCount, isDeprecated, false, false, smartType, false, whiteList); |
2748 |
} |
2745 |
} |
Lines 2832-2844
Link Here
|
2832 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-import_resolve"), cancel, false); //NOI18N |
2829 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-import_resolve"), cancel, false); //NOI18N |
2833 |
} |
2830 |
} |
2834 |
} |
2831 |
} |
2835 |
|
2832 |
|
2836 |
static class AttributeItem extends JavaCompletionItem { |
2833 |
static class AttributeItem extends JavaCompletionItem { |
2837 |
|
2834 |
|
2838 |
private static final String ATTRIBUTE = "org/netbeans/modules/java/editor/resources/attribute_16.png"; // NOI18N |
2835 |
private static final String ATTRIBUTE = "org/netbeans/modules/java/editor/resources/attribute_16.png"; // NOI18N |
2839 |
private static final String ATTRIBUTE_COLOR = "<font color=#404040>"; //NOI18N |
2836 |
private static final String ATTRIBUTE_COLOR = "<font color=#404040>"; //NOI18N |
2840 |
private static ImageIcon icon; |
2837 |
private static ImageIcon icon; |
2841 |
|
2838 |
|
2842 |
private ElementHandle<ExecutableElement> elementHandle; |
2839 |
private ElementHandle<ExecutableElement> elementHandle; |
2843 |
private boolean isDeprecated; |
2840 |
private boolean isDeprecated; |
2844 |
private String simpleName; |
2841 |
private String simpleName; |
Lines 2856-2870
Link Here
|
2856 |
AnnotationValue value = elem.getDefaultValue(); |
2853 |
AnnotationValue value = elem.getDefaultValue(); |
2857 |
this.defaultValue = value != null ? value.toString() : null; |
2854 |
this.defaultValue = value != null ? value.toString() : null; |
2858 |
} |
2855 |
} |
2859 |
|
2856 |
|
2860 |
public int getSortPriority() { |
2857 |
public int getSortPriority() { |
2861 |
return 100; |
2858 |
return 100; |
2862 |
} |
2859 |
} |
2863 |
|
2860 |
|
2864 |
public CharSequence getSortText() { |
2861 |
public CharSequence getSortText() { |
2865 |
return simpleName; |
2862 |
return simpleName; |
2866 |
} |
2863 |
} |
2867 |
|
2864 |
|
2868 |
public CharSequence getInsertPrefix() { |
2865 |
public CharSequence getInsertPrefix() { |
2869 |
return simpleName; |
2866 |
return simpleName; |
2870 |
} |
2867 |
} |
Lines 2875-2883
Link Here
|
2875 |
|
2872 |
|
2876 |
protected ImageIcon getIcon(){ |
2873 |
protected ImageIcon getIcon(){ |
2877 |
if (icon == null) icon = ImageUtilities.loadImageIcon(ATTRIBUTE, false); |
2874 |
if (icon == null) icon = ImageUtilities.loadImageIcon(ATTRIBUTE, false); |
2878 |
return icon; |
2875 |
return icon; |
2879 |
} |
2876 |
} |
2880 |
|
2877 |
|
2881 |
protected String getLeftHtmlText() { |
2878 |
protected String getLeftHtmlText() { |
2882 |
if (leftText == null) { |
2879 |
if (leftText == null) { |
2883 |
StringBuilder sb = new StringBuilder(); |
2880 |
StringBuilder sb = new StringBuilder(); |
Lines 2900-2912
Link Here
|
2900 |
} |
2897 |
} |
2901 |
return leftText; |
2898 |
return leftText; |
2902 |
} |
2899 |
} |
2903 |
|
2900 |
|
2904 |
protected String getRightHtmlText() { |
2901 |
protected String getRightHtmlText() { |
2905 |
if (rightText == null) |
2902 |
if (rightText == null) |
2906 |
rightText = escape(typeName); |
2903 |
rightText = escape(typeName); |
2907 |
return rightText; |
2904 |
return rightText; |
2908 |
} |
2905 |
} |
2909 |
|
2906 |
|
2910 |
@Override |
2907 |
@Override |
2911 |
protected void substituteText(JTextComponent c, int offset, int len, String toAdd, boolean assignToVar) { |
2908 |
protected void substituteText(JTextComponent c, int offset, int len, String toAdd, boolean assignToVar) { |
2912 |
super.substituteText(c, offset, len, toAdd != null ? toAdd : "=", assignToVar); //NOI18N |
2909 |
super.substituteText(c, offset, len, toAdd != null ? toAdd : "=", assignToVar); //NOI18N |
Lines 2914-2920
Link Here
|
2914 |
|
2911 |
|
2915 |
public String toString() { |
2912 |
public String toString() { |
2916 |
return simpleName; |
2913 |
return simpleName; |
2917 |
} |
2914 |
} |
2918 |
} |
2915 |
} |
2919 |
|
2916 |
|
2920 |
static class AttributeValueItem extends WhiteListJavaCompletionItem<TypeElement> { |
2917 |
static class AttributeValueItem extends WhiteListJavaCompletionItem<TypeElement> { |
Lines 2955-2961
Link Here
|
2955 |
return delegate != null ? delegate.getInsertPrefix() : value; //NOI18N |
2952 |
return delegate != null ? delegate.getInsertPrefix() : value; //NOI18N |
2956 |
} |
2953 |
} |
2957 |
|
2954 |
|
2958 |
public CompletionTask createDocumentationTask() { |
2955 |
public CompletionTask createDocumentationTask() { |
2959 |
return documentation == null ? null : new CompletionTask() { |
2956 |
return documentation == null ? null : new CompletionTask() { |
2960 |
|
2957 |
|
2961 |
private CompletionDocumentation cd = new CompletionDocumentation() { |
2958 |
private CompletionDocumentation cd = new CompletionDocumentation() { |
Lines 2980-2986
Link Here
|
2980 |
return null; |
2977 |
return null; |
2981 |
} |
2978 |
} |
2982 |
}; |
2979 |
}; |
2983 |
|
2980 |
|
2984 |
@Override |
2981 |
@Override |
2985 |
public void query(CompletionResultSet resultSet) { |
2982 |
public void query(CompletionResultSet resultSet) { |
2986 |
resultSet.setDocumentation(cd); |
2983 |
resultSet.setDocumentation(cd); |
Lines 3050-3056
Link Here
|
3050 |
} |
3047 |
} |
3051 |
|
3048 |
|
3052 |
static class StaticMemberItem extends WhiteListJavaCompletionItem<Element> { |
3049 |
static class StaticMemberItem extends WhiteListJavaCompletionItem<Element> { |
3053 |
|
3050 |
|
3054 |
private static final String FIELD_ST_PUBLIC = "org/netbeans/modules/editor/resources/completion/field_static_16.png"; //NOI18N |
3051 |
private static final String FIELD_ST_PUBLIC = "org/netbeans/modules/editor/resources/completion/field_static_16.png"; //NOI18N |
3055 |
private static final String FIELD_ST_PROTECTED = "org/netbeans/modules/editor/resources/completion/field_static_protected_16.png"; //NOI18N |
3052 |
private static final String FIELD_ST_PROTECTED = "org/netbeans/modules/editor/resources/completion/field_static_protected_16.png"; //NOI18N |
3056 |
private static final String FIELD_ST_PACKAGE = "org/netbeans/modules/editor/resources/completion/field_static_package_private_16.png"; //NOI18N |
3053 |
private static final String FIELD_ST_PACKAGE = "org/netbeans/modules/editor/resources/completion/field_static_package_private_16.png"; //NOI18N |
Lines 3063-3069
Link Here
|
3063 |
private static final String METHOD_COLOR = "<font color=#7c0000>"; //NOI18N |
3060 |
private static final String METHOD_COLOR = "<font color=#7c0000>"; //NOI18N |
3064 |
private static final String PARAMETER_NAME_COLOR = "<font color=#b200b2>"; //NOI18N |
3061 |
private static final String PARAMETER_NAME_COLOR = "<font color=#b200b2>"; //NOI18N |
3065 |
private static ImageIcon icon[][] = new ImageIcon[2][4]; |
3062 |
private static ImageIcon icon[][] = new ImageIcon[2][4]; |
3066 |
|
3063 |
|
3067 |
private TypeMirrorHandle<DeclaredType> typeHandle; |
3064 |
private TypeMirrorHandle<DeclaredType> typeHandle; |
3068 |
private boolean isDeprecated; |
3065 |
private boolean isDeprecated; |
3069 |
private String typeName; |
3066 |
private String typeName; |
Lines 3074-3080
Link Here
|
3074 |
private String sortText; |
3071 |
private String sortText; |
3075 |
private String leftText; |
3072 |
private String leftText; |
3076 |
private String rightText; |
3073 |
private String rightText; |
3077 |
|
3074 |
|
3078 |
private StaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, int substitutionOffset, boolean isDeprecated, WhiteListQuery.WhiteList whiteList) { |
3075 |
private StaticMemberItem(CompilationInfo info, DeclaredType type, Element memberElem, TypeMirror memberType, int substitutionOffset, boolean isDeprecated, WhiteListQuery.WhiteList whiteList) { |
3079 |
super(substitutionOffset, ElementHandle.create(memberElem), whiteList); |
3076 |
super(substitutionOffset, ElementHandle.create(memberElem), whiteList); |
3080 |
type = (DeclaredType) info.getTypes().erasure(type); |
3077 |
type = (DeclaredType) info.getTypes().erasure(type); |
Lines 3094-3104
Link Here
|
3094 |
} |
3091 |
} |
3095 |
} |
3092 |
} |
3096 |
} |
3093 |
} |
3097 |
|
3094 |
|
3098 |
public int getSortPriority() { |
3095 |
public int getSortPriority() { |
3099 |
return (params == null ? 700 : 750) - SMART_TYPE; |
3096 |
return (params == null ? 700 : 750) - SMART_TYPE; |
3100 |
} |
3097 |
} |
3101 |
|
3098 |
|
3102 |
public CharSequence getSortText() { |
3099 |
public CharSequence getSortText() { |
3103 |
if (sortText == null) { |
3100 |
if (sortText == null) { |
3104 |
if (params == null) { |
3101 |
if (params == null) { |
Lines 3121-3127
Link Here
|
3121 |
} |
3118 |
} |
3122 |
return sortText; |
3119 |
return sortText; |
3123 |
} |
3120 |
} |
3124 |
|
3121 |
|
3125 |
public CharSequence getInsertPrefix() { |
3122 |
public CharSequence getInsertPrefix() { |
3126 |
return typeName + "." + memberName; //NOI18N |
3123 |
return typeName + "." + memberName; //NOI18N |
3127 |
} |
3124 |
} |
Lines 3167-3179
Link Here
|
3167 |
rightText = escape(memberTypeName); |
3164 |
rightText = escape(memberTypeName); |
3168 |
return rightText; |
3165 |
return rightText; |
3169 |
} |
3166 |
} |
3170 |
|
3167 |
|
3171 |
protected ImageIcon getBaseIcon(){ |
3168 |
protected ImageIcon getBaseIcon(){ |
3172 |
int level = getProtectionLevel(modifiers); |
3169 |
int level = getProtectionLevel(modifiers); |
3173 |
boolean isField = getElementHandle().getKind().isField(); |
3170 |
boolean isField = getElementHandle().getKind().isField(); |
3174 |
ImageIcon cachedIcon = icon[isField ? 0 : 1][level]; |
3171 |
ImageIcon cachedIcon = icon[isField ? 0 : 1][level]; |
3175 |
if (cachedIcon != null) |
3172 |
if (cachedIcon != null) |
3176 |
return cachedIcon; |
3173 |
return cachedIcon; |
3177 |
|
3174 |
|
3178 |
String iconPath = null; |
3175 |
String iconPath = null; |
3179 |
if (isField) { |
3176 |
if (isField) { |
Lines 3217-3223
Link Here
|
3217 |
return null; |
3214 |
return null; |
3218 |
ImageIcon newIcon = ImageUtilities.loadImageIcon(iconPath, false); |
3215 |
ImageIcon newIcon = ImageUtilities.loadImageIcon(iconPath, false); |
3219 |
icon[isField ? 0 : 1][level] = newIcon; |
3216 |
icon[isField ? 0 : 1][level] = newIcon; |
3220 |
return newIcon; |
3217 |
return newIcon; |
3221 |
} |
3218 |
} |
3222 |
|
3219 |
|
3223 |
@Override |
3220 |
@Override |
Lines 3394-3407
Link Here
|
3394 |
return sb.toString(); |
3391 |
return sb.toString(); |
3395 |
} |
3392 |
} |
3396 |
} |
3393 |
} |
3397 |
|
3394 |
|
3398 |
static class InitializeAllConstructorItem extends JavaCompletionItem { |
3395 |
static class InitializeAllConstructorItem extends JavaCompletionItem { |
3399 |
|
3396 |
|
3400 |
private static final String CONSTRUCTOR_PUBLIC = "org/netbeans/modules/java/editor/resources/new_constructor_16.png"; //NOI18N |
3397 |
private static final String CONSTRUCTOR_PUBLIC = "org/netbeans/modules/java/editor/resources/new_constructor_16.png"; //NOI18N |
3401 |
private static final String CONSTRUCTOR_COLOR = "<font color=#b28b00>"; //NOI18N |
3398 |
private static final String CONSTRUCTOR_COLOR = "<font color=#b28b00>"; //NOI18N |
3402 |
private static final String PARAMETER_NAME_COLOR = "<font color=#b200b2>"; //NOI18N |
3399 |
private static final String PARAMETER_NAME_COLOR = "<font color=#b200b2>"; //NOI18N |
3403 |
private static ImageIcon icon; |
3400 |
private static ImageIcon icon; |
3404 |
|
3401 |
|
3405 |
private List<ElementHandle<VariableElement>> fieldHandles; |
3402 |
private List<ElementHandle<VariableElement>> fieldHandles; |
3406 |
private ElementHandle<TypeElement> parentHandle; |
3403 |
private ElementHandle<TypeElement> parentHandle; |
3407 |
private ElementHandle<ExecutableElement> superConstructorHandle; |
3404 |
private ElementHandle<ExecutableElement> superConstructorHandle; |
Lines 3409-3415
Link Here
|
3409 |
private List<ParamDesc> params; |
3406 |
private List<ParamDesc> params; |
3410 |
private String sortText; |
3407 |
private String sortText; |
3411 |
private String leftText; |
3408 |
private String leftText; |
3412 |
|
3409 |
|
3413 |
private InitializeAllConstructorItem(CompilationInfo info, Iterable<? extends VariableElement> fields, ExecutableElement superConstructor, TypeElement parent, int substitutionOffset) { |
3410 |
private InitializeAllConstructorItem(CompilationInfo info, Iterable<? extends VariableElement> fields, ExecutableElement superConstructor, TypeElement parent, int substitutionOffset) { |
3414 |
super(substitutionOffset); |
3411 |
super(substitutionOffset); |
3415 |
this.fieldHandles = new ArrayList<ElementHandle<VariableElement>>(); |
3412 |
this.fieldHandles = new ArrayList<ElementHandle<VariableElement>>(); |
Lines 3422-3439
Link Here
|
3422 |
if (superConstructor != null) { |
3419 |
if (superConstructor != null) { |
3423 |
this.superConstructorHandle = ElementHandle.create(superConstructor); |
3420 |
this.superConstructorHandle = ElementHandle.create(superConstructor); |
3424 |
for (VariableElement ve : superConstructor.getParameters()) { |
3421 |
for (VariableElement ve : superConstructor.getParameters()) { |
3425 |
this.params.add(new ParamDesc(null, Utilities.getTypeName(info, ve.asType(), false).toString(), ve.getSimpleName().toString())); |
3422 |
this.params.add(new ParamDesc(null, Utilities.getTypeName(info, ve.asType(), false).toString(), ve.getSimpleName().toString())); |
3426 |
} |
3423 |
} |
3427 |
} else { |
3424 |
} else { |
3428 |
this.superConstructorHandle = null; |
3425 |
this.superConstructorHandle = null; |
3429 |
} |
3426 |
} |
3430 |
this.simpleName = parent.getSimpleName().toString(); |
3427 |
this.simpleName = parent.getSimpleName().toString(); |
3431 |
} |
3428 |
} |
3432 |
|
3429 |
|
3433 |
public int getSortPriority() { |
3430 |
public int getSortPriority() { |
3434 |
return 400; |
3431 |
return 400; |
3435 |
} |
3432 |
} |
3436 |
|
3433 |
|
3437 |
public CharSequence getSortText() { |
3434 |
public CharSequence getSortText() { |
3438 |
if (sortText == null) { |
3435 |
if (sortText == null) { |
3439 |
StringBuilder sortParams = new StringBuilder(); |
3436 |
StringBuilder sortParams = new StringBuilder(); |
Lines 3452-3458
Link Here
|
3452 |
} |
3449 |
} |
3453 |
return sortText; |
3450 |
return sortText; |
3454 |
} |
3451 |
} |
3455 |
|
3452 |
|
3456 |
protected String getLeftHtmlText() { |
3453 |
protected String getLeftHtmlText() { |
3457 |
if (leftText == null) { |
3454 |
if (leftText == null) { |
3458 |
StringBuilder lText = new StringBuilder(); |
3455 |
StringBuilder lText = new StringBuilder(); |
Lines 3477-3493
Link Here
|
3477 |
} |
3474 |
} |
3478 |
return leftText; |
3475 |
return leftText; |
3479 |
} |
3476 |
} |
3480 |
|
3477 |
|
3481 |
protected ImageIcon getIcon() { |
3478 |
protected ImageIcon getIcon() { |
3482 |
if (icon == null) |
3479 |
if (icon == null) |
3483 |
icon = ImageUtilities.loadImageIcon(CONSTRUCTOR_PUBLIC, false); |
3480 |
icon = ImageUtilities.loadImageIcon(CONSTRUCTOR_PUBLIC, false); |
3484 |
return icon; |
3481 |
return icon; |
3485 |
} |
3482 |
} |
3486 |
|
3483 |
|
3487 |
public CharSequence getInsertPrefix() { |
3484 |
public CharSequence getInsertPrefix() { |
3488 |
return simpleName; |
3485 |
return simpleName; |
3489 |
} |
3486 |
} |
3490 |
|
3487 |
|
3491 |
@Override |
3488 |
@Override |
3492 |
protected void substituteText(final JTextComponent c, final int offset, final int len, String toAdd, final boolean assignToVar) { |
3489 |
protected void substituteText(final JTextComponent c, final int offset, final int len, String toAdd, final boolean assignToVar) { |
3493 |
final BaseDocument doc = (BaseDocument)c.getDocument(); |
3490 |
final BaseDocument doc = (BaseDocument)c.getDocument(); |
Lines 3523-3534
Link Here
|
3523 |
break; |
3520 |
break; |
3524 |
} |
3521 |
} |
3525 |
ExecutableElement superConstructor = superConstructorHandle != null ? superConstructorHandle.resolve(copy) : null; |
3522 |
ExecutableElement superConstructor = superConstructorHandle != null ? superConstructorHandle.resolve(copy) : null; |
3526 |
|
3523 |
|
3527 |
TreeMaker make = copy.getTreeMaker(); |
3524 |
TreeMaker make = copy.getTreeMaker(); |
3528 |
ClassTree clazz = (ClassTree) tp.getLeaf(); |
3525 |
ClassTree clazz = (ClassTree) tp.getLeaf(); |
3529 |
GeneratorUtilities gu = GeneratorUtilities.get(copy); |
3526 |
GeneratorUtilities gu = GeneratorUtilities.get(copy); |
3530 |
ClassTree decl = make.insertClassMember(clazz, idx, gu.createConstructor(parent, fieldElements, superConstructor)); //NOI18N |
3527 |
ClassTree decl = make.insertClassMember(clazz, idx, gu.createConstructor(parent, fieldElements, superConstructor)); //NOI18N |
3531 |
|
3528 |
|
3532 |
copy.rewrite(clazz, decl); |
3529 |
copy.rewrite(clazz, decl); |
3533 |
} |
3530 |
} |
3534 |
} |
3531 |
} |
Lines 3558-3564
Link Here
|
3558 |
sb.append(GENERATE_TEXT); |
3555 |
sb.append(GENERATE_TEXT); |
3559 |
return sb.toString(); |
3556 |
return sb.toString(); |
3560 |
} |
3557 |
} |
3561 |
|
3558 |
|
3562 |
public boolean instantSubstitution(JTextComponent component) { |
3559 |
public boolean instantSubstitution(JTextComponent component) { |
3563 |
return false; //no instant substitution for create constructor item |
3560 |
return false; //no instant substitution for create constructor item |
3564 |
} |
3561 |
} |
Lines 3568-3574
Link Here
|
3568 |
private static final int PROTECTED_LEVEL = 2; |
3565 |
private static final int PROTECTED_LEVEL = 2; |
3569 |
private static final int PACKAGE_LEVEL = 1; |
3566 |
private static final int PACKAGE_LEVEL = 1; |
3570 |
private static final int PRIVATE_LEVEL = 0; |
3567 |
private static final int PRIVATE_LEVEL = 0; |
3571 |
|
3568 |
|
3572 |
private static int getProtectionLevel(Set<Modifier> modifiers) { |
3569 |
private static int getProtectionLevel(Set<Modifier> modifiers) { |
3573 |
if(modifiers.contains(Modifier.PUBLIC)) |
3570 |
if(modifiers.contains(Modifier.PUBLIC)) |
3574 |
return PUBLIC_LEVEL; |
3571 |
return PUBLIC_LEVEL; |
Lines 3578-3584
Link Here
|
3578 |
return PRIVATE_LEVEL; |
3575 |
return PRIVATE_LEVEL; |
3579 |
return PACKAGE_LEVEL; |
3576 |
return PACKAGE_LEVEL; |
3580 |
} |
3577 |
} |
3581 |
|
3578 |
|
3582 |
private static String escape(String s) { |
3579 |
private static String escape(String s) { |
3583 |
if (s != null) { |
3580 |
if (s != null) { |
3584 |
try { |
3581 |
try { |
Lines 3587-3593
Link Here
|
3587 |
} |
3584 |
} |
3588 |
return s; |
3585 |
return s; |
3589 |
} |
3586 |
} |
3590 |
|
3587 |
|
3591 |
private static int findPositionForSemicolon(JTextComponent c) { |
3588 |
private static int findPositionForSemicolon(JTextComponent c) { |
3592 |
final int[] ret = new int[] {-2}; |
3589 |
final int[] ret = new int[] {-2}; |
3593 |
final int offset = c.getSelectionEnd(); |
3590 |
final int offset = c.getSelectionEnd(); |
Lines 3611-3617
Link Here
|
3611 |
while (t == null && tp != null) { |
3608 |
while (t == null && tp != null) { |
3612 |
switch(tp.getLeaf().getKind()) { |
3609 |
switch(tp.getLeaf().getKind()) { |
3613 |
case EXPRESSION_STATEMENT: |
3610 |
case EXPRESSION_STATEMENT: |
3614 |
case IMPORT: |
3611 |
case IMPORT: |
3615 |
t = tp.getLeaf(); |
3612 |
t = tp.getLeaf(); |
3616 |
break; |
3613 |
break; |
3617 |
case RETURN: |
3614 |
case RETURN: |
Lines 3631-3637
Link Here
|
3631 |
if (ts.token().id() == JavaTokenId.SEMICOLON) { |
3628 |
if (ts.token().id() == JavaTokenId.SEMICOLON) { |
3632 |
ret[0] = -1; |
3629 |
ret[0] = -1; |
3633 |
} else if (ts.moveNext()) { |
3630 |
} else if (ts.moveNext()) { |
3634 |
ret[0] = ts.token().id() == JavaTokenId.LINE_COMMENT || ts.token().id() == JavaTokenId.WHITESPACE && ts.token().text().toString().contains("\n") ? ts.offset() : offset; |
3631 |
ret[0] = ts.token().id() == JavaTokenId.LINE_COMMENT || ts.token().id() == JavaTokenId.WHITESPACE && ts.token().text().toString().contains("\n") ? ts.offset() : offset; |
3635 |
} else { |
3632 |
} else { |
3636 |
ret[0] = ts.offset() + ts.token().length(); |
3633 |
ret[0] = ts.offset() + ts.token().length(); |
3637 |
} |
3634 |
} |
Lines 3650-3656
Link Here
|
3650 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-find_semicolon_pos"), cancel, false); //NOI18N |
3647 |
}, NbBundle.getMessage(JavaCompletionItem.class, "JCI-find_semicolon_pos"), cancel, false); //NOI18N |
3651 |
return ret[0]; |
3648 |
return ret[0]; |
3652 |
} |
3649 |
} |
3653 |
|
3650 |
|
3654 |
private static TokenSequence<JavaTokenId> findLastNonWhitespaceToken(CompilationInfo info, int startPos, int endPos) { |
3651 |
private static TokenSequence<JavaTokenId> findLastNonWhitespaceToken(CompilationInfo info, int startPos, int endPos) { |
3655 |
TokenSequence<JavaTokenId> ts = info.getTokenHierarchy().tokenSequence(JavaTokenId.language()); |
3652 |
TokenSequence<JavaTokenId> ts = info.getTokenHierarchy().tokenSequence(JavaTokenId.language()); |
3656 |
ts.move(endPos); |
3653 |
ts.move(endPos); |
Lines 3670-3676
Link Here
|
3670 |
} |
3667 |
} |
3671 |
return null; |
3668 |
return null; |
3672 |
} |
3669 |
} |
3673 |
|
3670 |
|
3674 |
private static String getAssignToVarText(CompilationInfo info, TypeMirror type, String name) { |
3671 |
private static String getAssignToVarText(CompilationInfo info, TypeMirror type, String name) { |
3675 |
name = adjustName(name); |
3672 |
name = adjustName(name); |
3676 |
StringBuilder sb = new StringBuilder(); |
3673 |
StringBuilder sb = new StringBuilder(); |
Lines 3686-3717
Link Here
|
3686 |
sb.append("\"} = "); //NOI18N |
3683 |
sb.append("\"} = "); //NOI18N |
3687 |
return sb.toString(); |
3684 |
return sb.toString(); |
3688 |
} |
3685 |
} |
3689 |
|
3686 |
|
3690 |
private static String adjustName(String name) { |
3687 |
private static String adjustName(String name) { |
3691 |
if (name == null) |
3688 |
if (name == null) |
3692 |
return null; |
3689 |
return null; |
3693 |
|
3690 |
|
3694 |
String shortName = null; |
3691 |
String shortName = null; |
3695 |
|
3692 |
|
3696 |
if (name.startsWith("get") && name.length() > 3) { //NOI18N |
3693 |
if (name.startsWith("get") && name.length() > 3) { //NOI18N |
3697 |
shortName = name.substring(3); |
3694 |
shortName = name.substring(3); |
3698 |
} |
3695 |
} |
3699 |
|
3696 |
|
3700 |
if (name.startsWith("is") && name.length() > 2) { //NOI18N |
3697 |
if (name.startsWith("is") && name.length() > 2) { //NOI18N |
3701 |
shortName = name.substring(2); |
3698 |
shortName = name.substring(2); |
3702 |
} |
3699 |
} |
3703 |
|
3700 |
|
3704 |
if (shortName != null) { |
3701 |
if (shortName != null) { |
3705 |
return firstToLower(shortName); |
3702 |
return firstToLower(shortName); |
3706 |
} |
3703 |
} |
3707 |
|
3704 |
|
3708 |
if (SourceVersion.isKeyword(name)) { |
3705 |
if (SourceVersion.isKeyword(name)) { |
3709 |
return "a" + Character.toUpperCase(name.charAt(0)) + name.substring(1); //NOI18N |
3706 |
return "a" + Character.toUpperCase(name.charAt(0)) + name.substring(1); //NOI18N |
3710 |
} else { |
3707 |
} else { |
3711 |
return name; |
3708 |
return name; |
3712 |
} |
3709 |
} |
3713 |
} |
3710 |
} |
3714 |
|
3711 |
|
3715 |
private static String firstToLower(String name) { |
3712 |
private static String firstToLower(String name) { |
3716 |
if (name.length() == 0) |
3713 |
if (name.length() == 0) |
3717 |
return null; |
3714 |
return null; |
Lines 3732-3750
Link Here
|
3732 |
} |
3729 |
} |
3733 |
|
3730 |
|
3734 |
result.append(last); |
3731 |
result.append(last); |
3735 |
|
3732 |
|
3736 |
if (SourceVersion.isKeyword(result)) { |
3733 |
if (SourceVersion.isKeyword(result)) { |
3737 |
return "a" + name; //NOI18N |
3734 |
return "a" + name; //NOI18N |
3738 |
} else { |
3735 |
} else { |
3739 |
return result.toString(); |
3736 |
return result.toString(); |
3740 |
} |
3737 |
} |
3741 |
} |
3738 |
} |
3742 |
|
3739 |
|
3743 |
static class ParamDesc { |
3740 |
static class ParamDesc { |
3744 |
private String fullTypeName; |
3741 |
private String fullTypeName; |
3745 |
private String typeName; |
3742 |
private String typeName; |
3746 |
private String name; |
3743 |
private String name; |
3747 |
|
3744 |
|
3748 |
public ParamDesc(String fullTypeName, String typeName, String name) { |
3745 |
public ParamDesc(String fullTypeName, String typeName, String name) { |
3749 |
this.fullTypeName = fullTypeName; |
3746 |
this.fullTypeName = fullTypeName; |
3750 |
this.typeName = typeName; |
3747 |
this.typeName = typeName; |