当前位置: 首页>>代码示例>>Java>>正文


Java CompletionProposal.METHOD_IMPORT属性代码示例

本文整理汇总了Java中org.eclipse.jdt.core.CompletionProposal.METHOD_IMPORT属性的典型用法代码示例。如果您正苦于以下问题:Java CompletionProposal.METHOD_IMPORT属性的具体用法?Java CompletionProposal.METHOD_IMPORT怎么用?Java CompletionProposal.METHOD_IMPORT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.eclipse.jdt.core.CompletionProposal的用法示例。


在下文中一共展示了CompletionProposal.METHOD_IMPORT属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ignoreAll

private void ignoreAll() {
  int[] ignoredKinds = new int[] {
      CompletionProposal.ANONYMOUS_CLASS_DECLARATION,
      CompletionProposal.FIELD_REF, CompletionProposal.KEYWORD,
      CompletionProposal.LABEL_REF, CompletionProposal.LOCAL_VARIABLE_REF,
      CompletionProposal.METHOD_REF, CompletionProposal.METHOD_DECLARATION,
      CompletionProposal.PACKAGE_REF, CompletionProposal.TYPE_REF,
      CompletionProposal.VARIABLE_DECLARATION,
      CompletionProposal.POTENTIAL_METHOD_DECLARATION,
      CompletionProposal.METHOD_NAME_REFERENCE,
      CompletionProposal.ANNOTATION_ATTRIBUTE_REF,
      CompletionProposal.JAVADOC_FIELD_REF,
      CompletionProposal.JAVADOC_METHOD_REF,
      CompletionProposal.JAVADOC_TYPE_REF,
      CompletionProposal.JAVADOC_VALUE_REF,
      CompletionProposal.JAVADOC_PARAM_REF,
      CompletionProposal.JAVADOC_BLOCK_TAG,
      CompletionProposal.JAVADOC_INLINE_TAG, CompletionProposal.FIELD_IMPORT,
      CompletionProposal.METHOD_IMPORT, CompletionProposal.TYPE_IMPORT};

  for (int kind : ignoredKinds) {
    setIgnored(kind, true);
  }
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:24,代码来源:ProposalGeneratingCompletionRequestor.java

示例2: mapKind

private CompletionItemKind mapKind(final int kind) {
	switch (kind) {
	case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
	case CompletionProposal.CONSTRUCTOR_INVOCATION:
		return CompletionItemKind.Constructor;
	case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
	case CompletionProposal.TYPE_REF:
		return CompletionItemKind.Class;
	case CompletionProposal.FIELD_IMPORT:
	case CompletionProposal.METHOD_IMPORT:
	case CompletionProposal.METHOD_NAME_REFERENCE:
	case CompletionProposal.PACKAGE_REF:
	case CompletionProposal.TYPE_IMPORT:
		return CompletionItemKind.Module;
	case CompletionProposal.FIELD_REF:
	case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER:
		return CompletionItemKind.Field;
	case CompletionProposal.KEYWORD:
		return CompletionItemKind.Keyword;
	case CompletionProposal.LABEL_REF:
		return CompletionItemKind.Reference;
	case CompletionProposal.LOCAL_VARIABLE_REF:
	case CompletionProposal.VARIABLE_DECLARATION:
		return CompletionItemKind.Variable;
	case CompletionProposal.METHOD_DECLARATION:
	case CompletionProposal.METHOD_REF:
	case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER:
	case CompletionProposal.POTENTIAL_METHOD_DECLARATION:
		return CompletionItemKind.Function;
		//text
	case CompletionProposal.ANNOTATION_ATTRIBUTE_REF:
	case CompletionProposal.JAVADOC_BLOCK_TAG:
	case CompletionProposal.JAVADOC_FIELD_REF:
	case CompletionProposal.JAVADOC_INLINE_TAG:
	case CompletionProposal.JAVADOC_METHOD_REF:
	case CompletionProposal.JAVADOC_PARAM_REF:
	case CompletionProposal.JAVADOC_TYPE_REF:
	case CompletionProposal.JAVADOC_VALUE_REF:
	default:
		return CompletionItemKind.Text;
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:42,代码来源:CompletionProposalRequestor.java

示例3: updateReplacement

/**
 * Updates the replacement and any additional replacement for the given item.
 *
 * @param proposal
 * @param item
 * @param trigger
 */
public void updateReplacement(CompletionProposal proposal, CompletionItem item, char trigger) {
	// reset importRewrite
	this.importRewrite = TypeProposalUtils.createImportRewrite(compilationUnit);

	List<org.eclipse.lsp4j.TextEdit> additionalTextEdits = new ArrayList<>();

	StringBuilder completionBuffer = new StringBuilder();
	Range range = null;
	if (isSupportingRequiredProposals(proposal)) {
		CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
		if (requiredProposals != null) {
			for (CompletionProposal requiredProposal : requiredProposals) {
				switch(requiredProposal.getKind()) {
				case CompletionProposal.TYPE_IMPORT:
				case CompletionProposal.METHOD_IMPORT:
				case CompletionProposal.FIELD_IMPORT:
					appendImportProposal(completionBuffer, requiredProposal, proposal.getKind());
					break;
				case CompletionProposal.TYPE_REF:
					org.eclipse.lsp4j.TextEdit edit = toRequiredTypeEdit(requiredProposal, trigger, proposal.canUseDiamond(context));
						if (proposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION || proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION
								|| proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_DECLARATION) {
						completionBuffer.append(edit.getNewText());
						range = edit.getRange();
					} else {
						additionalTextEdits.add(edit);
					}
					break;
				default:
					/*
					 * In 3.3 we only support the above required proposals, see
					 * CompletionProposal#getRequiredProposals()
					 */
					Assert.isTrue(false);
				}
			}
		}
	}

	if (range == null) {
		range = toReplacementRange(proposal);
	}
	if(proposal.getKind() == CompletionProposal.METHOD_DECLARATION){
		appendMethodOverrideReplacement(completionBuffer, proposal);
	} else if (proposal.getKind() == CompletionProposal.POTENTIAL_METHOD_DECLARATION && proposal instanceof GetterSetterCompletionProposal) {
		appendMethodPotentialReplacement(completionBuffer, (GetterSetterCompletionProposal) proposal);
	} else if (proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION || proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_DECLARATION) {
		appendAnonymousClass(completionBuffer, proposal, range);
	} else {
		appendReplacementString(completionBuffer, proposal);
	}
	//select insertTextFormat.
	if( client.isCompletionSnippetsSupported()){
		item.setInsertTextFormat(InsertTextFormat.Snippet);
	}else{
		item.setInsertTextFormat(InsertTextFormat.PlainText);
	}
	String text = completionBuffer.toString();
	if(range != null){
		item.setTextEdit(new org.eclipse.lsp4j.TextEdit(range, text));
	}else{
		// fallback
		item.setInsertText(text);
	}
	addImports(additionalTextEdits);
	if(!additionalTextEdits.isEmpty()){
		item.setAdditionalTextEdits(additionalTextEdits);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:76,代码来源:CompletionProposalReplacementProvider.java

示例4: appendImportProposal

private StringBuilder appendImportProposal(StringBuilder buffer, CompletionProposal proposal, int coreKind) {
	int proposalKind= proposal.getKind();
	String qualifiedTypeName= null;
	char[] qualifiedType= null;
	if (proposalKind == CompletionProposal.TYPE_IMPORT) {
		qualifiedType= proposal.getSignature();
		qualifiedTypeName= String.valueOf(Signature.toCharArray(qualifiedType));
	} else if (proposalKind == CompletionProposal.METHOD_IMPORT || proposalKind == CompletionProposal.FIELD_IMPORT) {
		qualifiedType= Signature.getTypeErasure(proposal.getDeclarationSignature());
		qualifiedTypeName= String.valueOf(Signature.toCharArray(qualifiedType));
	} else {
		/*
		 * In 3.3 we only support the above import proposals, see
		 * CompletionProposal#getRequiredProposals()
		 */
		Assert.isTrue(false);
	}

	/* Add imports if the preference is on. */
	if (importRewrite != null) {
		if (proposalKind == CompletionProposal.TYPE_IMPORT) {
			String simpleType= importRewrite.addImport(qualifiedTypeName, null);
			if (coreKind == CompletionProposal.METHOD_REF) {
				buffer.append(simpleType);
				buffer.append(COMMA);
				return buffer;
			}
		} else {
			String res= importRewrite.addStaticImport(qualifiedTypeName, String.valueOf(proposal.getName()), proposalKind == CompletionProposal.FIELD_IMPORT, null);
			int dot= res.lastIndexOf('.');
			if (dot != -1) {
				buffer.append(importRewrite.addImport(res.substring(0, dot), null));
				buffer.append('.');
				return buffer;
			}
		}
		return buffer;
	}

	// Case where we don't have an import rewrite (see allowAddingImports)

	if (compilationUnit != null && isImplicitImport(Signature.getQualifier(qualifiedTypeName), compilationUnit)) {
		/* No imports for implicit imports. */

		if (proposal.getKind() == CompletionProposal.TYPE_IMPORT && coreKind == CompletionProposal.FIELD_REF) {
			return buffer;
		}
		qualifiedTypeName= String.valueOf(Signature.getSignatureSimpleName(qualifiedType));
	}
	buffer.append(qualifiedTypeName);
	buffer.append('.');
	return buffer;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:53,代码来源:CompletionProposalReplacementProvider.java

示例5: getStaticImportFavorites

public static String[] getStaticImportFavorites(ICompilationUnit cu, final String elementName, boolean isMethod, String[] favorites) throws JavaModelException {
	StringBuffer dummyCU= new StringBuffer();
	String packName= cu.getParent().getElementName();
	IType type= cu.findPrimaryType();
	if (type == null) {
		return new String[0];
	}

	if (packName.length() > 0) {
		dummyCU.append("package ").append(packName).append(';'); //$NON-NLS-1$
	}
	dummyCU.append("public class ").append(type.getElementName()).append("{\n static {\n").append(elementName); // static initializer  //$NON-NLS-1$//$NON-NLS-2$
	int offset= dummyCU.length();
	dummyCU.append("\n}\n }"); //$NON-NLS-1$

	ICompilationUnit newCU= null;
	try {
		newCU= cu.getWorkingCopy(null);
		newCU.getBuffer().setContents(dummyCU.toString());

		final HashSet<String> result= new HashSet<>();

		CompletionRequestor requestor= new CompletionRequestor(true) {
			@Override
			public void accept(CompletionProposal proposal) {
				if (elementName.equals(new String(proposal.getName()))) {
					CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
					for (int i= 0; i < requiredProposals.length; i++) {
						CompletionProposal curr= requiredProposals[i];
						if (curr.getKind() == CompletionProposal.METHOD_IMPORT || curr.getKind() == CompletionProposal.FIELD_IMPORT) {
							result.add(JavaModelUtil.concatenateName(Signature.toCharArray(curr.getDeclarationSignature()), curr.getName()));
						}
					}
				}
			}
		};

		if (isMethod) {
			requestor.setIgnored(CompletionProposal.METHOD_REF, false);
			requestor.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true);
		} else {
			requestor.setIgnored(CompletionProposal.FIELD_REF, false);
			requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true);
		}
		requestor.setFavoriteReferences(favorites);

		newCU.codeComplete(offset, requestor);

		return result.toArray(new String[result.size()]);
	} finally {
		if (newCU != null) {
			newCU.discardWorkingCopy();
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:55,代码来源:SimilarElementsRequestor.java

示例6: computeReplacementString

/**
 * Computes the replacement string.
 *
 * @return the replacement string
 */
private String computeReplacementString() {
  int proposalKind = fProposal.getKind();
  String qualifiedTypeName = null;
  char[] qualifiedType = null;
  if (proposalKind == CompletionProposal.TYPE_IMPORT) {
    qualifiedType = fProposal.getSignature();
    qualifiedTypeName = String.valueOf(Signature.toCharArray(qualifiedType));
  } else if (proposalKind == CompletionProposal.METHOD_IMPORT
      || proposalKind == CompletionProposal.FIELD_IMPORT) {
    qualifiedType = Signature.getTypeErasure(fProposal.getDeclarationSignature());
    qualifiedTypeName = String.valueOf(Signature.toCharArray(qualifiedType));
  } else {
    /*
     * In 3.3 we only support the above import proposals, see
     * CompletionProposal#getRequiredProposals()
     */
    Assert.isTrue(false);
  }

  /* Add imports if the preference is on. */
  fImportRewrite = createImportRewrite();
  if (fImportRewrite != null) {
    if (proposalKind == CompletionProposal.TYPE_IMPORT) {
      String simpleType = fImportRewrite.addImport(qualifiedTypeName, fImportContext);
      if (fParentProposalKind == CompletionProposal.METHOD_REF)
        return simpleType + "."; // $NON-NLS-1$
    } else {
      String res =
          fImportRewrite.addStaticImport(
              qualifiedTypeName,
              String.valueOf(fProposal.getName()),
              proposalKind == CompletionProposal.FIELD_IMPORT,
              fImportContext);
      int dot = res.lastIndexOf('.');
      if (dot != -1) {
        String typeName = fImportRewrite.addImport(res.substring(0, dot), fImportContext);
        return typeName + '.';
      }
    }
    return ""; // $NON-NLS-1$
  }

  // Case where we don't have an import rewrite (see allowAddingImports)

  if (fCompilationUnit != null
      && JavaModelUtil.isImplicitImport(
          Signature.getQualifier(qualifiedTypeName), fCompilationUnit)) {
    /* No imports for implicit imports. */

    if (fProposal.getKind() == CompletionProposal.TYPE_IMPORT
        && fParentProposalKind == CompletionProposal.FIELD_REF) return ""; // $NON-NLS-1$
    qualifiedTypeName = String.valueOf(Signature.getSignatureSimpleName(qualifiedType));
  }

  return qualifiedTypeName + "."; // $NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:che,代码行数:61,代码来源:ImportCompletionProposal.java

示例7: getStaticImportFavorites

public static String[] getStaticImportFavorites(
    ICompilationUnit cu, final String elementName, boolean isMethod, String[] favorites)
    throws JavaModelException {
  StringBuffer dummyCU = new StringBuffer();
  String packName = cu.getParent().getElementName();
  IType type = cu.findPrimaryType();
  if (type == null) return new String[0];

  if (packName.length() > 0) {
    dummyCU.append("package ").append(packName).append(';'); // $NON-NLS-1$
  }
  dummyCU
      .append("public class ")
      .append(type.getElementName())
      .append("{\n static {\n")
      .append(elementName); // static initializer  //$NON-NLS-1$//$NON-NLS-2$
  int offset = dummyCU.length();
  dummyCU.append("\n}\n }"); // $NON-NLS-1$

  ICompilationUnit newCU = null;
  try {
    newCU = cu.getWorkingCopy(null);
    newCU.getBuffer().setContents(dummyCU.toString());

    final HashSet<String> result = new HashSet<String>();

    CompletionRequestor requestor =
        new CompletionRequestor(true) {
          @Override
          public void accept(CompletionProposal proposal) {
            if (elementName.equals(new String(proposal.getName()))) {
              CompletionProposal[] requiredProposals = proposal.getRequiredProposals();
              for (int i = 0; i < requiredProposals.length; i++) {
                CompletionProposal curr = requiredProposals[i];
                if (curr.getKind() == CompletionProposal.METHOD_IMPORT
                    || curr.getKind() == CompletionProposal.FIELD_IMPORT) {
                  result.add(
                      JavaModelUtil.concatenateName(
                          Signature.toCharArray(curr.getDeclarationSignature()), curr.getName()));
                }
              }
            }
          }
        };

    if (isMethod) {
      requestor.setIgnored(CompletionProposal.METHOD_REF, false);
      requestor.setAllowsRequiredProposals(
          CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true);
    } else {
      requestor.setIgnored(CompletionProposal.FIELD_REF, false);
      requestor.setAllowsRequiredProposals(
          CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true);
    }
    requestor.setFavoriteReferences(favorites);

    newCU.codeComplete(offset, requestor);

    return result.toArray(new String[result.size()]);
  } finally {
    if (newCU != null) {
      newCU.discardWorkingCopy();
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:65,代码来源:SimilarElementsRequestor.java


注:本文中的org.eclipse.jdt.core.CompletionProposal.METHOD_IMPORT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。