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


Java IField.getTypeSignature方法代码示例

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


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

示例1: isGeneralizeTypeAvailable

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static boolean isGeneralizeTypeAvailable(final IJavaElement element)
    throws JavaModelException {
  if (element != null && element.exists()) {
    String type = null;
    if (element instanceof IMethod) type = ((IMethod) element).getReturnType();
    else if (element instanceof IField) {
      final IField field = (IField) element;
      if (JdtFlags.isEnum(field)) return false;
      type = field.getTypeSignature();
    } else if (element instanceof ILocalVariable) return true;
    else if (element instanceof IType) {
      final IType clazz = (IType) element;
      if (JdtFlags.isEnum(clazz)) return false;
      return true;
    }
    if (type == null || PrimitiveType.toCode(Signature.toString(type)) != null) return false;
    return true;
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:RefactoringAvailabilityTester.java

示例2: getFieldTypeFiltered

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public IType getFieldTypeFiltered(IField field) {
    String signature;
    try {
        signature = field.getTypeSignature();
        IType primaryType = field.getTypeRoot().findPrimaryType();
        String name = JavaModelUtil.getResolvedTypeName(signature, primaryType);

        if (name == null || isFiltered(name)) {
            return null;
        }
        return field.getJavaProject().findType(name);
    } catch (JavaModelException e) {
        DataHierarchyPlugin.logError("getUnfilteredFieldType() failed for field: " + field, e);
    }
    return null;
}
 
开发者ID:iloveeclipse,项目名称:datahierarchy,代码行数:17,代码来源:FieldReferencesRequestor.java

示例3: getModelByFields

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
/**
 * @return an empty optional if the given type does not have any field,
 *         otherwise the name of the model package and its java project
 *         respectively, which contains the types of the given diagramType
 */
public static Optional<Pair<String, String>> getModelByFields(IType diagramType) {
	try {
		List<String> referencedProjects = new ArrayList<>(
				Arrays.asList(diagramType.getJavaProject().getRequiredProjectNames()));
		referencedProjects.add(diagramType.getJavaProject().getElementName());

		for (IField field : diagramType.getFields()) {
			String typeSignature = field.getTypeSignature();
			String[][] resolvedTypes = resolveType(diagramType,
					typeSignature.substring(1, typeSignature.length() - 1));
			List<String[]> resolvedTypeList = new ArrayList<>(Arrays.asList(resolvedTypes));

			for (String[] type : resolvedTypeList) {
				Optional<Pair<String, String>> model = ModelUtils.getModelOf(type[0], referencedProjects);
				if (model.isPresent()) {
					return model;
				}
			}
		}
	} catch (JavaModelException | NoSuchElementException e) {
	}

	return Optional.empty();
}
 
开发者ID:ELTE-Soft,项目名称:txtUML,代码行数:30,代码来源:WizardUtils.java

示例4: appendFieldDeclaration

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
protected void appendFieldDeclaration(final IField field) throws JavaModelException {
  appendFlags(field);
  fBuffer.append(" "); // $NON-NLS-1$
  final String signature = field.getTypeSignature();
  fBuffer.append(Signature.toString(signature));
  fBuffer.append(" "); // $NON-NLS-1$
  fBuffer.append(field.getElementName());
  if (Flags.isFinal(field.getFlags())) {
    fBuffer.append("="); // $NON-NLS-1$
    appendExpression(signature);
  }
  fBuffer.append(";"); // $NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:StubCreator.java

示例5: getTypeSignature

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static String getTypeSignature(IField field) {
    String signature = null;
    try {
        // XXX seems not to work properly with inner *binary* types like
        // java.util.zip.ZipFile$1 (line 212)
        // the field info for fields in inner member types seems not to be
        // present in java model at all...
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=237200
        signature = field.getTypeSignature();
    } catch (JavaModelException e) {
        DataHierarchyPlugin.logError("getTypeSignature() failed for field: " + field, e);
    }
    return signature;
}
 
开发者ID:iloveeclipse,项目名称:datahierarchy,代码行数:15,代码来源:SearchUtils.java

示例6: getFieldType

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static IType getFieldType(IField field) {
    String signature;
    try {
        signature = field.getTypeSignature();
        IType primaryType = field.getTypeRoot().findPrimaryType();
        String name = JavaModelUtil.getResolvedTypeName(signature, primaryType);
        if (name == null) {
            return null;
        }
        return field.getJavaProject().findType(name);
    } catch (JavaModelException e) {
        DataHierarchyPlugin.logError("getFieldType() failed for field: " + field, e);
    }
    return null;
}
 
开发者ID:iloveeclipse,项目名称:datahierarchy,代码行数:16,代码来源:FieldReferencesRequestor.java

示例7: createFieldElement

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
protected FieldElement createFieldElement(IField field) throws JavaModelException {
	return new FieldElement(getFullyQualifiedClassName(field), field.getElementName(), field.getTypeSignature(),
			getLineNumber(field));
}
 
开发者ID:CenterDevice,项目名称:ClassCleaner,代码行数:5,代码来源:JavaElementConverter.java

示例8: getSetter

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static IMethod getSetter(IField field) throws JavaModelException {
	String[] args = new String[] { field.getTypeSignature() };
	return JavaModelUtil.findMethod(getSetterName(field, EMPTY), args, false, field.getDeclaringType());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:5,代码来源:GetterSetterUtil.java

示例9: getSetterStub

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
/**
 * Create a stub for a getter of the given field using getter/setter
 * templates. The resulting code has to be formatted and indented.
 *
 * @param field
 *            The field to create a getter for
 * @param setterName
 *            The chosen name for the setter
 * @param addComments
 *            If <code>true</code>, comments will be added.
 * @param flags
 *            The flags signaling visibility, if static, synchronized or
 *            final
 * @return Returns the generated stub.
 * @throws CoreException
 *             when stub creation failed
 */
public static String getSetterStub(IField field, String setterName, boolean addComments, int flags) throws CoreException {

	String fieldName = field.getElementName();
	IType parentType = field.getDeclaringType();

	String returnSig = field.getTypeSignature();
	String typeName = Signature.toString(returnSig);

	IJavaProject project = field.getJavaProject();

	String accessorName = StubUtility.getBaseName(field);
	String argname = StubUtility.suggestArgumentName(project, accessorName, EMPTY);

	boolean isStatic = Flags.isStatic(flags);
	boolean isSync = Flags.isSynchronized(flags);
	boolean isFinal = Flags.isFinal(flags);

	String lineDelim = "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$
	StringBuffer buf = new StringBuffer();
	if (addComments) {
		String comment = CodeGeneration.getSetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, field.getElementName(), typeName, argname, accessorName, lineDelim);
		if (comment != null) {
			buf.append(comment);
		}
	}
	buf.append(JdtFlags.getVisibilityString(flags));
	buf.append(' ');
	if (isStatic) {
		buf.append("static "); //$NON-NLS-1$
	}
	if (isSync) {
		buf.append("synchronized "); //$NON-NLS-1$
	}
	if (isFinal) {
		buf.append("final "); //$NON-NLS-1$
	}

	buf.append("void "); //$NON-NLS-1$
	buf.append(setterName);
	buf.append('(');
	buf.append(typeName);
	buf.append(' ');
	buf.append(argname);
	buf.append(") {"); //$NON-NLS-1$
	buf.append(lineDelim);

	if (argname.equals(fieldName) || !isStatic) {
		if (isStatic) {
			fieldName = parentType.getElementName() + '.' + fieldName;
		} else {
			fieldName = "this." + fieldName; //$NON-NLS-1$
		}
	}
	String body = CodeGeneration.getSetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, fieldName, argname, lineDelim);
	if (body != null) {
		buf.append(body);
	}
	buf.append("}"); //$NON-NLS-1$
	return buf.toString();
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:78,代码来源:GetterSetterUtil.java

示例10: getSetter

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public static IMethod getSetter(IField field) throws JavaModelException {
  String[] args = new String[] {field.getTypeSignature()};
  return JavaModelUtil.findMethod(
      getSetterName(field, EMPTY), args, false, field.getDeclaringType());
}
 
开发者ID:eclipse,项目名称:che,代码行数:6,代码来源:GetterSetterUtil.java

示例11: createVariable

import org.eclipse.jdt.core.IField; //导入方法依赖的package包/类
public Variable createVariable(
    IJavaElement element, IType enclosingType, String expectedType, int positionScore)
    throws JavaModelException {
  int variableType;
  int elementType = element.getElementType();
  String elementName = element.getElementName();

  String typeSignature;
  switch (elementType) {
    case IJavaElement.FIELD:
      {
        IField field = (IField) element;
        if (field.getDeclaringType().equals(enclosingType)) {
          variableType = Variable.FIELD;
        } else {
          variableType = Variable.INHERITED_FIELD;
        }
        if (field.isResolved()) {
          typeSignature = new BindingKey(field.getKey()).toSignature();
        } else {
          typeSignature = field.getTypeSignature();
        }
        break;
      }
    case IJavaElement.LOCAL_VARIABLE:
      {
        ILocalVariable locVar = (ILocalVariable) element;
        variableType = Variable.LOCAL;
        typeSignature = locVar.getTypeSignature();
        break;
      }
    case IJavaElement.METHOD:
      {
        IMethod method = (IMethod) element;
        if (isMethodToSuggest(method)) {
          if (method.getDeclaringType().equals(enclosingType)) {
            variableType = Variable.METHOD;
          } else {
            variableType = Variable.INHERITED_METHOD;
          }
          if (method.isResolved()) {
            typeSignature =
                Signature.getReturnType(new BindingKey(method.getKey()).toSignature());
          } else {
            typeSignature = method.getReturnType();
          }
          elementName = elementName + "()"; // $NON-NLS-1$
        } else {
          return null;
        }
        break;
      }
    default:
      return null;
  }
  String type = Signature.toString(typeSignature);

  boolean isAutoboxMatch = isPrimitiveType(expectedType) != isPrimitiveType(type);
  return new Variable(
      type,
      elementName,
      variableType,
      isAutoboxMatch,
      positionScore,
      NO_TRIGGERS,
      getImageDescriptor(element));
}
 
开发者ID:eclipse,项目名称:che,代码行数:68,代码来源:ParameterGuesser.java


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