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


Java ASTNodes.getSimpleNameIdentifier方法代码示例

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


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

示例1: getArgument

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static String getArgument(TagElement curr) {
  List<? extends ASTNode> fragments = curr.fragments();
  if (!fragments.isEmpty()) {
    Object first = fragments.get(0);
    if (first instanceof Name) {
      return ASTNodes.getSimpleNameIdentifier((Name) first);
    } else if (first instanceof TextElement && TagElement.TAG_PARAM.equals(curr.getTagName())) {
      String text = ((TextElement) first).getText();
      if ("<".equals(text) && fragments.size() >= 3) { // $NON-NLS-1$
        Object second = fragments.get(1);
        Object third = fragments.get(2);
        if (second instanceof Name
            && third instanceof TextElement
            && ">".equals(((TextElement) third).getText())) { // $NON-NLS-1$
          return '<' + ASTNodes.getSimpleNameIdentifier((Name) second) + '>';
        }
      } else if (text.startsWith(String.valueOf('<'))
          && text.endsWith(String.valueOf('>'))
          && text.length() > 2) {
        return text.substring(1, text.length() - 1);
      }
    }
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:JavadocTagsSubProcessor.java

示例2: getTypeName

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static String getTypeName(int typeKind, Name node) {
  String name = ASTNodes.getSimpleNameIdentifier(node);

  if (typeKind == K_CLASS || typeKind == K_INTERFACE) {
    ASTNode parent = node.getParent();
    if (parent.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) {
      String typeArgBaseName =
          name.startsWith(String.valueOf('T'))
              ? String.valueOf('S')
              : String.valueOf('T'); // use 'S' or 'T'

      int nTypeArgs = ((ParameterizedType) parent.getParent()).typeArguments().size();
      StringBuffer buf = new StringBuffer(name);
      buf.append('<');
      if (nTypeArgs == 1) {
        buf.append(typeArgBaseName);
      } else {
        for (int i = 0; i < nTypeArgs; i++) {
          if (i != 0) buf.append(", "); // $NON-NLS-1$
          buf.append(typeArgBaseName).append(i + 1);
        }
      }
      buf.append('>');
      return buf.toString();
    }
  }
  return name;
}
 
开发者ID:eclipse,项目名称:che,代码行数:29,代码来源:NewCUUsingWizardProposal.java

示例3: computeTypeNameWithParameters

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private String computeTypeNameWithParameters() {
  StringBuilder sb = new StringBuilder();

  if (syncTypeBinding.getTypeParameters().length > 0) {
    sb.append("<");
    ITypeBinding[] typeParameters = syncTypeBinding.getTypeParameters();
    for (int i = 0; i < typeParameters.length; ++i) {
      if (i != 0) {
        sb.append(", ");
      }
      sb.append(typeParameters[i].getName());
      sb.append(" extends ");
      ITypeBinding[] typeBounds = typeParameters[i].getTypeBounds();
      for (int j = 0; j < typeBounds.length; ++j) {
        if (j != 0) {
          sb.append(" & ");
        }

        sb.append(typeBounds[i].getQualifiedName());
      }
    }
    sb.append(">");
  }

  // TODO: Factor out access to internal class, does it even matter now?
  return ASTNodes.getSimpleNameIdentifier(node) + sb.toString();
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:28,代码来源:CreateAsyncInterfaceProposal.java

示例4: getBaseNameFromExpression

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static String getBaseNameFromExpression(IJavaProject project, Expression assignedExpression, int variableKind) {
	String name= null;
	if (assignedExpression instanceof CastExpression) {
		assignedExpression= ((CastExpression)assignedExpression).getExpression();
	}
	if (assignedExpression instanceof Name) {
		Name simpleNode= (Name)assignedExpression;
		IBinding binding= simpleNode.resolveBinding();
		if (binding instanceof IVariableBinding) {
			return getBaseName((IVariableBinding)binding, project);
		}

		return ASTNodes.getSimpleNameIdentifier(simpleNode);
	} else if (assignedExpression instanceof MethodInvocation) {
		name= ((MethodInvocation)assignedExpression).getName().getIdentifier();
	} else if (assignedExpression instanceof SuperMethodInvocation) {
		name= ((SuperMethodInvocation)assignedExpression).getName().getIdentifier();
	} else if (assignedExpression instanceof FieldAccess) {
		return ((FieldAccess)assignedExpression).getName().getIdentifier();
	} else if (variableKind == NamingConventions.VK_STATIC_FINAL_FIELD && (assignedExpression instanceof StringLiteral || assignedExpression instanceof NumberLiteral)) {
		String string= assignedExpression instanceof StringLiteral ? ((StringLiteral)assignedExpression).getLiteralValue() : ((NumberLiteral)assignedExpression).getToken();
		StringBuffer res= new StringBuffer();
		boolean needsUnderscore= false;
		for (int i= 0; i < string.length(); i++) {
			char ch= string.charAt(i);
			if (Character.isJavaIdentifierPart(ch)) {
				if (res.length() == 0 && !Character.isJavaIdentifierStart(ch) || needsUnderscore) {
					res.append('_');
				}
				res.append(ch);
				needsUnderscore= false;
			} else {
				needsUnderscore= res.length() > 0;
			}
		}
		if (res.length() > 0) {
			return res.toString();
		}
	}
	if (name != null) {
		for (int i= 0; i < KNOWN_METHOD_NAME_PREFIXES.length; i++) {
			String curr= KNOWN_METHOD_NAME_PREFIXES[i];
			if (name.startsWith(curr)) {
				if (name.equals(curr)) {
					return null; // don't suggest 'get' as variable name
				} else if (Character.isUpperCase(name.charAt(curr.length()))) {
					return name.substring(curr.length());
				}
			}
		}
	}
	return name;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:54,代码来源:StubUtility.java

示例5: getBaseNameFromExpression

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static String getBaseNameFromExpression(
    IJavaProject project, Expression assignedExpression, int variableKind) {
  String name = null;
  if (assignedExpression instanceof CastExpression) {
    assignedExpression = ((CastExpression) assignedExpression).getExpression();
  }
  if (assignedExpression instanceof Name) {
    Name simpleNode = (Name) assignedExpression;
    IBinding binding = simpleNode.resolveBinding();
    if (binding instanceof IVariableBinding)
      return getBaseName((IVariableBinding) binding, project);

    return ASTNodes.getSimpleNameIdentifier(simpleNode);
  } else if (assignedExpression instanceof MethodInvocation) {
    name = ((MethodInvocation) assignedExpression).getName().getIdentifier();
  } else if (assignedExpression instanceof SuperMethodInvocation) {
    name = ((SuperMethodInvocation) assignedExpression).getName().getIdentifier();
  } else if (assignedExpression instanceof FieldAccess) {
    return ((FieldAccess) assignedExpression).getName().getIdentifier();
  } else if (variableKind == NamingConventions.VK_STATIC_FINAL_FIELD
      && (assignedExpression instanceof StringLiteral
          || assignedExpression instanceof NumberLiteral)) {
    String string =
        assignedExpression instanceof StringLiteral
            ? ((StringLiteral) assignedExpression).getLiteralValue()
            : ((NumberLiteral) assignedExpression).getToken();
    StringBuffer res = new StringBuffer();
    boolean needsUnderscore = false;
    for (int i = 0; i < string.length(); i++) {
      char ch = string.charAt(i);
      if (Character.isJavaIdentifierPart(ch)) {
        if (res.length() == 0 && !Character.isJavaIdentifierStart(ch) || needsUnderscore) {
          res.append('_');
        }
        res.append(ch);
        needsUnderscore = false;
      } else {
        needsUnderscore = res.length() > 0;
      }
    }
    if (res.length() > 0) {
      return res.toString();
    }
  }
  if (name != null) {
    for (int i = 0; i < KNOWN_METHOD_NAME_PREFIXES.length; i++) {
      String curr = KNOWN_METHOD_NAME_PREFIXES[i];
      if (name.startsWith(curr)) {
        if (name.equals(curr)) {
          return null; // don't suggest 'get' as variable name
        } else if (Character.isUpperCase(name.charAt(curr.length()))) {
          return name.substring(curr.length());
        }
      }
    }
  }
  return name;
}
 
开发者ID:eclipse,项目名称:che,代码行数:59,代码来源:StubUtility.java

示例6: getConvertAnonymousToNestedProposal

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
private static boolean getConvertAnonymousToNestedProposal(
    IInvocationContext context, final ASTNode node, Collection<ICommandAccess> proposals)
    throws CoreException {
  if (!(node instanceof Name)) return false;

  ASTNode normalized = ASTNodes.getNormalizedNode(node);
  if (normalized.getLocationInParent() != ClassInstanceCreation.TYPE_PROPERTY) return false;

  final AnonymousClassDeclaration anonymTypeDecl =
      ((ClassInstanceCreation) normalized.getParent()).getAnonymousClassDeclaration();
  if (anonymTypeDecl == null || anonymTypeDecl.resolveBinding() == null) {
    return false;
  }

  if (proposals == null) {
    return true;
  }

  final ICompilationUnit cu = context.getCompilationUnit();
  final ConvertAnonymousToNestedRefactoring refactoring =
      new ConvertAnonymousToNestedRefactoring(anonymTypeDecl);

  String extTypeName = ASTNodes.getSimpleNameIdentifier((Name) node);
  ITypeBinding anonymTypeBinding = anonymTypeDecl.resolveBinding();
  String className;
  if (anonymTypeBinding.getInterfaces().length == 0) {
    className =
        Messages.format(
            CorrectionMessages.QuickAssistProcessor_name_extension_from_interface, extTypeName);
  } else {
    className =
        Messages.format(
            CorrectionMessages.QuickAssistProcessor_name_extension_from_class, extTypeName);
  }
  String[][] existingTypes = ((IType) anonymTypeBinding.getJavaElement()).resolveType(className);
  int i = 1;
  while (existingTypes != null) {
    i++;
    existingTypes = ((IType) anonymTypeBinding.getJavaElement()).resolveType(className + i);
  }
  refactoring.setClassName(i == 1 ? className : className + i);

  if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) {
    LinkedProposalModel linkedProposalModel = new LinkedProposalModel();
    refactoring.setLinkedProposalModel(linkedProposalModel);

    String label = CorrectionMessages.QuickAssistProcessor_convert_anonym_to_nested;
    Image image =
        JavaPlugin.getImageDescriptorRegistry()
            .get(
                JavaElementImageProvider.getTypeImageDescriptor(
                    true, false, Flags.AccPrivate, false));
    RefactoringCorrectionProposal proposal =
        new RefactoringCorrectionProposal(
            label, cu, refactoring, IProposalRelevance.CONVERT_ANONYMOUS_TO_NESTED, image);
    proposal.setLinkedProposalModel(linkedProposalModel);
    proposal.setCommandId(CONVERT_ANONYMOUS_TO_LOCAL_ID);
    proposals.add(proposal);
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:62,代码来源:QuickAssistProcessor.java

示例7: findSimilarElement

import org.eclipse.jdt.internal.corext.dom.ASTNodes; //导入方法依赖的package包/类
public static SimilarElement[] findSimilarElement(ICompilationUnit cu, Name name, int kind)
    throws JavaModelException {
  int pos = name.getStartPosition();
  int nArguments = -1;

  String identifier = ASTNodes.getSimpleNameIdentifier(name);
  String returnType = null;
  ICompilationUnit preparedCU = null;

  try {
    if (name.isQualifiedName()) {
      pos = ((QualifiedName) name).getName().getStartPosition();
    } else {
      pos = name.getStartPosition() + 1; // first letter must be included, other
    }
    Javadoc javadoc = (Javadoc) ASTNodes.getParent(name, ASTNode.JAVADOC);
    if (javadoc != null) {
      preparedCU = createPreparedCU(cu, javadoc, name.getStartPosition());
      cu = preparedCU;
    }

    SimilarElementsRequestor requestor =
        new SimilarElementsRequestor(identifier, kind, nArguments, returnType);
    requestor.setIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, true);
    requestor.setIgnored(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, true);
    requestor.setIgnored(CompletionProposal.KEYWORD, true);
    requestor.setIgnored(CompletionProposal.LABEL_REF, true);
    requestor.setIgnored(CompletionProposal.METHOD_DECLARATION, true);
    requestor.setIgnored(CompletionProposal.PACKAGE_REF, true);
    requestor.setIgnored(CompletionProposal.VARIABLE_DECLARATION, true);
    requestor.setIgnored(CompletionProposal.METHOD_REF, true);
    requestor.setIgnored(CompletionProposal.CONSTRUCTOR_INVOCATION, true);
    requestor.setIgnored(CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER, true);
    requestor.setIgnored(CompletionProposal.FIELD_REF, true);
    requestor.setIgnored(CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER, true);
    requestor.setIgnored(CompletionProposal.LOCAL_VARIABLE_REF, true);
    requestor.setIgnored(CompletionProposal.VARIABLE_DECLARATION, true);
    requestor.setIgnored(CompletionProposal.VARIABLE_DECLARATION, true);
    requestor.setIgnored(CompletionProposal.POTENTIAL_METHOD_DECLARATION, true);
    requestor.setIgnored(CompletionProposal.METHOD_NAME_REFERENCE, true);
    return requestor.process(cu, pos);
  } finally {
    if (preparedCU != null) {
      preparedCU.discardWorkingCopy();
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:48,代码来源:SimilarElementsRequestor.java


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