Cosmetics in code(remove duplicates, not nessery array creationg, etc)

I work on plugins and find very interest duplicates.


     ArrayFactory<PsiTypeParameter> ARRAY_FACTORY = new ArrayFactory<PsiTypeParameter>()      {           @Override           public PsiTypeParameter[] create(final int count)           {                return count == 0 ? EMPTY_ARRAY : new PsiTypeParameter[count];           }      };      PsiElementArrayConstructor<PsiTypeElement> PSI_TYPE_ELEMENT_ARRAY_CONSTRUCTOR = new PsiElementArrayConstructor<PsiTypeElement>()      {           @Override           public PsiTypeElement[] newPsiElementArray(int length)           {                return length > 0 ? new PsiTypeElement[length] : PsiTypeElement.EMPTY_ARRAY;           }      };




Two classes with the same fuctional(diff generic params - but its easy to change)

JavaCompletionUtil.java

  static final NullableLazyKey<ExpectedTypeInfo[], CompletionLocation> EXPECTED_TYPES = NullableLazyKey.create("expectedTypes", new NullableFunction<CompletionLocation, ExpectedTypeInfo[]>() {     @Nullable     public ExpectedTypeInfo[] fun(final CompletionLocation location) {       if (PsiJavaPatterns.psiElement().beforeLeaf(PsiJavaPatterns.psiElement().withText("."))         .accepts(location.getCompletionParameters().getPosition())) {         return new ExpectedTypeInfo[0];       }       return JavaSmartCompletionContributor.getExpectedTypes(location.getCompletionParameters());     }   });




return new ExpectedTypeInfo[0]; - can use ExpectedTypeInfo.EMPTY_ARRAY


And many others, i dont post that was i find at work. I dont want to create 1 ticket as http://youtrack.jetbrains.com/issue/IDEA-81896. Its only cosmetics & api cleanup

2 comments
Comment actions Permalink

The first code example is actually correct code (it's not possible to create an array of a generic type in Java). The second is indeed a valid issue; I've corrected it.

You're welcome to file YouTrack issues or submit patches for issues like these, but in fact there are tens of thousands of possible improvements like these that could be made to the IntelliJ IDEA codebase.

0

Please sign in to leave a comment.