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


Java Signature类代码示例

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


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

示例1: execute

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {

	final IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
	final ICompilationUnit icu = JavaUI.getWorkingCopyManager().getWorkingCopy(editorPart.getEditorInput());

	try {
		final IType type = icu.getTypes()[0];
		final List<Field> fields = new ArrayList<>();
		for (final IField field : type.getFields()) {
			final String fieldName = field.getElementName();
			final String fieldType = Signature.getSignatureSimpleName(field.getTypeSignature());
			fields.add(new Field(fieldName, fieldType));
		}

		new WizardDialog(HandlerUtil.getActiveShell(event), new BuilderGeneratorWizard(icu, fields)).open();

	}
	catch (final JavaModelException e) {
		e.printStackTrace();
	}

	return null;
}
 
开发者ID:khabali,项目名称:java-builders-generator,代码行数:25,代码来源:GenerateBuildersHandler.java

示例2: resolveMethodSignature

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
/**
 * Copied from org.eclipse.jdt.internal.debug.ui.actions.ToggleBreakpointAdapter
 * TODO: is there a public API to do this?
 *
 * Returns the resolved signature of the given method
 * @param method method to resolve
 * @return the resolved method signature or <code>null</code> if none
 * @throws JavaModelException
 * @since 3.4
 */
public static String resolveMethodSignature(IMethod method) throws JavaModelException {
	String signature = method.getSignature();
	String[] parameterTypes = Signature.getParameterTypes(signature);
	int length = parameterTypes.length;
	String[] resolvedParameterTypes = new String[length];
	for (int i = 0; i < length; i++) {
		resolvedParameterTypes[i] = resolveTypeSignature(method, parameterTypes[i]);
		if (resolvedParameterTypes[i] == null) {
			return null;
		}
	}
	String resolvedReturnType = resolveTypeSignature(method, Signature.getReturnType(signature));
	if (resolvedReturnType == null) {
		return null;
	}
	return Signature.createMethodSignature(resolvedParameterTypes, resolvedReturnType);
}
 
开发者ID:VisuFlow,项目名称:visuflow-plugin,代码行数:28,代码来源:BreakpointLocator.java

示例3: getInvocationExpression

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
public String getInvocationExpression() {
	String[] values = getValues();
	String[] parameterTypes = method.getParameterTypes();

	for(int i = 0; i < values.length; i++) {
		String pType = Signature.getSignatureSimpleName(parameterTypes[i]);
		values[i] = convertForTypedInvocation(values[i], pType);
	}

	try {
		return (method.isConstructor() ? "new " + method.getElementName() : methodName) + "(" + String.join(", ", values) + ")";
	} catch (JavaModelException e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:17,代码来源:StaticInvocationWidget.java

示例4: resolveParameterType

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
private static final void resolveParameterType(final IMethod method,
    final String parameterType, final StringBuilder result)
    throws JavaModelException {
  final char kind = parameterType.charAt(0);
  switch (kind) {
  case Signature.C_UNRESOLVED:
    final String identifier = parameterType.substring(1,
        parameterType.length() - 1);
    if (resolveType(method.getDeclaringType(), identifier, result)) {
      return;
    }
    if (resolveTypeParameter(method, identifier, result)) {
      return;
    }
    break;
  }
  result.append(parameterType);
}
 
开发者ID:eclipse,项目名称:eclemma,代码行数:19,代码来源:SignatureResolver.java

示例5: resolveType

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
private static final boolean resolveType(final IType scope,
    final String identifier, final StringBuilder result)
    throws JavaModelException {
  final String[][] types = scope.resolveType(Signature
      .getTypeErasure(identifier));
  if (types == null || types.length != 1) {
    return false;
  }
  result.append(Signature.C_RESOLVED);
  final String qualifier = types[0][0];
  if (qualifier.length() > 0) {
    replace(qualifier, Signature.C_DOT, SLASH, result);
    result.append(SLASH);
  }
  replace(types[0][1], Signature.C_DOT, Signature.C_DOLLAR, result);
  result.append(Signature.C_SEMICOLON);
  return true;
}
 
开发者ID:eclipse,项目名称:eclemma,代码行数:19,代码来源:SignatureResolver.java

示例6: toLaunchableResource

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
private LaunchableResource toLaunchableResource(IResource resource) {
  if (resource == null) {
    return null;
  }
  IJavaElement javaElement = resource.getAdapter(IJavaElement.class);
  if (javaElement != null && javaElement.exists() && javaElement instanceof ICompilationUnit) {
    ICompilationUnit compilationUnit = (ICompilationUnit) javaElement;
    IType javaType = compilationUnit.findPrimaryType();
    if (javaType == null) {
      return null;
    }
    IMethod mainMethod = javaType.getMethod(
        "main", new String[] {Signature.createTypeSignature("String[]", false)});
    return new LaunchableResource(resource, mainMethod, javaType);
  }
  return new LaunchableResource(resource);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-eclipse,代码行数:18,代码来源:LaunchPipelineShortcut.java

示例7: appendUnboundedParameterList

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
/**
 * Appends the parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param methodProposal the method proposal
 * @return the modified <code>buffer</code>
 */
private StringBuilder appendUnboundedParameterList(StringBuilder buffer, CompletionProposal methodProposal) {
	// TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
	// gets fixed.
	char[] signature= SignatureUtil.fix83600(methodProposal.getSignature());
	char[][] parameterNames= methodProposal.findParameterNames(null);
	char[][] parameterTypes= Signature.getParameterTypes(signature);

	for (int i= 0; i < parameterTypes.length; i++) {
		parameterTypes[i]= createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i]));
	}

	if (Flags.isVarargs(methodProposal.getFlags())) {
		int index= parameterTypes.length - 1;
		parameterTypes[index]= convertToVararg(parameterTypes[index]);
	}
	return appendParameterSignature(buffer, parameterTypes, parameterNames);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:CompletionProposalDescriptionProvider.java

示例8: createTypeDisplayName

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
/**
 * Returns the display string for a java type signature.
 *
 * @param typeSignature the type signature to create a display name for
 * @return the display name for <code>typeSignature</code>
 * @throws IllegalArgumentException if <code>typeSignature</code> is not a
 *         valid signature
 * @see Signature#toCharArray(char[])
 * @see Signature#getSimpleName(char[])
 */
private char[] createTypeDisplayName(char[] typeSignature) throws IllegalArgumentException {
	char[] displayName= Signature.getSimpleName(Signature.toCharArray(typeSignature));

	// XXX see https://bugs.eclipse.org/bugs/show_bug.cgi?id=84675
	boolean useShortGenerics= false;
	if (useShortGenerics) {
		StringBuilder buf= new StringBuilder();
		buf.append(displayName);
		int pos;
		do {
			pos= buf.indexOf("? extends "); //$NON-NLS-1$
			if (pos >= 0) {
				buf.replace(pos, pos + 10, "+"); //$NON-NLS-1$
			} else {
				pos= buf.indexOf("? super "); //$NON-NLS-1$
				if (pos >= 0)
				{
					buf.replace(pos, pos + 8, "-"); //$NON-NLS-1$
				}
			}
		} while (pos >= 0);
		return buf.toString().toCharArray();
	}
	return displayName;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:36,代码来源:CompletionProposalDescriptionProvider.java

示例9: createAnonymousTypeLabel

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
private void createAnonymousTypeLabel(CompletionProposal proposal, CompletionItem item) {
	char[] declaringTypeSignature= proposal.getDeclarationSignature();
	declaringTypeSignature= Signature.getTypeErasure(declaringTypeSignature);
	String name = new String(Signature.getSignatureSimpleName(declaringTypeSignature));
	item.setInsertText(name);
	StringBuilder buf= new StringBuilder();
	buf.append(name);
	buf.append('(');
	appendUnboundedParameterList(buf, proposal);
	buf.append(')');
	buf.append("  "); //$NON-NLS-1$
	buf.append("Anonymous Inner Type"); //TODO: consider externalization
	item.setLabel(buf.toString());

	if (proposal.getRequiredProposals() != null) {
		char[] signatureQualifier= Signature.getSignatureQualifier(declaringTypeSignature);
		if (signatureQualifier.length > 0) {
			item.setDetail(String.valueOf(signatureQualifier));
		}
	}
	setDeclarationSignature(item, String.valueOf(declaringTypeSignature));
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:CompletionProposalDescriptionProvider.java

示例10: appendMethodOverrideReplacement

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
/**
 * @param completionBuffer
 * @param proposal
 */
private void appendMethodOverrideReplacement(StringBuilder completionBuffer, CompletionProposal proposal) {
	IDocument document;
	try {
		document = JsonRpcHelpers.toDocument(this.compilationUnit.getBuffer());
		String signature = String.valueOf(proposal.getSignature());
		String[] types = Stream.of(Signature.getParameterTypes(signature)).map(t -> Signature.toString(t))
				.toArray(String[]::new);
		String methodName = String.valueOf(proposal.getName());
		int offset = proposal.getReplaceStart();
		String completion = new String(proposal.getCompletion());
		OverrideCompletionProposal overrider = new OverrideCompletionProposal(compilationUnit, methodName, types,
				completion);
		String replacement = overrider.updateReplacementString(document, offset, importRewrite,
				client.isCompletionSnippetsSupported());
		completionBuffer.append(replacement);
	} catch (BadLocationException | CoreException e) {
		JavaLanguageServerPlugin.logException("Failed to compute override replacement", e);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:CompletionProposalReplacementProvider.java

示例11: createDummyType

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
private String createDummyType(String name) throws JavaModelException {
	StringBuffer buffer = new StringBuffer();
	buffer.append("abstract class "); //$NON-NLS-1$
	buffer.append(name);
	if (fSuperType.isInterface()) {
		buffer.append(" implements "); //$NON-NLS-1$
	} else {
		buffer.append(" extends "); //$NON-NLS-1$
	}
	if (fDeclarationSignature != null) {
		buffer.append(Signature.toString(fDeclarationSignature));
	} else {
		buffer.append(fSuperType.getFullyQualifiedParameterizedName());
	}
	buffer.append(" {"); //$NON-NLS-1$
	buffer.append("\n"); //$NON-NLS-1$
	buffer.append("}"); //$NON-NLS-1$
	return buffer.toString();
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:AnonymousTypeCompletionProposal.java

示例12: getParameterTypeNamesForSeeTag

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
private static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
	try {
		ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
		parser.setProject(overridden.getJavaProject());
		IBinding[] bindings = parser.createBindings(new IJavaElement[] { overridden }, null);
		if (bindings.length == 1 && bindings[0] instanceof IMethodBinding) {
			return getParameterTypeNamesForSeeTag((IMethodBinding) bindings[0]);
		}
	} catch (IllegalStateException e) {
		// method does not exist
	}
	// fall back code. Not good for generic methods!
	String[] paramTypes = overridden.getParameterTypes();
	String[] paramTypeNames = new String[paramTypes.length];
	for (int i = 0; i < paramTypes.length; i++) {
		paramTypeNames[i] = Signature.toString(Signature.getTypeErasure(paramTypes[i]));
	}
	return paramTypeNames;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:StubUtility.java

示例13: appendAnnotationLabel

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException {
	fBuilder.append('@');
	appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags);
	IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs();
	if (memberValuePairs.length == 0) {
		return;
	}
	fBuilder.append('(');
	for (int i= 0; i < memberValuePairs.length; i++) {
		if (i > 0) {
			fBuilder.append(JavaElementLabels.COMMA_STRING);
		}
		IMemberValuePair memberValuePair= memberValuePairs[i];
		fBuilder.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName()));
		fBuilder.append('=');
		appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags);
	}
	fBuilder.append(')');
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:JavaElementLabelComposer.java

示例14: addNewJavadoc

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
private void addNewJavadoc(ASTRewrite rewrite, MethodDeclaration decl, ImportRewriteContext context) throws CoreException {
	IType parentType = fField.getDeclaringType();

	String typeName = Signature.toString(fField.getTypeSignature());
	String accessorName = StubUtility.getBaseName(fField);
	String lineDelim = "\n";

	String comment = null;
	String name = getFunctionName();
	if (isGetter) {
		comment = CodeGeneration.getGetterComment(fField.getCompilationUnit(), parentType.getTypeQualifiedName('.'), name, fField.getElementName(), typeName, accessorName, lineDelim);
	} else {
		String argname = getArgumentName();
		comment = CodeGeneration.getSetterComment(fField.getCompilationUnit(), parentType.getTypeQualifiedName('.'), name, fField.getElementName(), typeName, argname, accessorName, lineDelim);
	}
	comment = comment.substring(0, comment.lastIndexOf(lineDelim));

	if (comment != null) {
		Javadoc javadoc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
		decl.setJavadoc(javadoc);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:SelfEncapsulateFieldProposal.java

示例15: displayTraceItem

import org.eclipse.jdt.core.Signature; //导入依赖的package包/类
private String displayTraceItem(BaseTraceability traceItem) {
	StringBuffer sb = new StringBuffer();
	
	AstNode expr = traceItem.getExpression();
	if (expr != null) {
		BodyDeclaration enclDecl = expr.enclosingDeclaration;
		
		// Inline this?
		TypeDeclaration enclTypeDeclaration = MiniAstUtils.getEnclosingTypeDeclaration(expr);
		
		String type = Signature.getSimpleName(enclTypeDeclaration.getFullyQualifiedName());
		sb.append(type);
		sb.append("\t");
		if (enclDecl instanceof MethodDeclaration) {
			MethodDeclaration md = (MethodDeclaration) enclDecl;
			sb.append(md.methodName);
		}
		if (enclDecl instanceof FieldDeclaration) {
			FieldDeclaration fd = (FieldDeclaration)enclDecl;
			sb.append(fd.fieldName);
		}
		sb.append("\t");
		sb.append(expr);
	}
	return sb.toString();
}
 
开发者ID:aroog,项目名称:code,代码行数:27,代码来源:SecurityAnalysis.java


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