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


Java Name类代码示例

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


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

示例1: createUnobservedInitStmt

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
@SuppressWarnings("unchecked")
	@Override
	public void createUnobservedInitStmt(CaptureLog log, int logRecNo) 
	{
		PostProcessor.notifyRecentlyProcessedLogRecNo(logRecNo);
		
		// NOTE: PLAIN INIT: has always one non-null param
		// TODO: use primitives
		final int    oid     = log.objectIds.get(logRecNo);
//		final String type    = log.oidClassNames.get(log.oidRecMapping.get(oid));
		final Object value   = log.params.get(logRecNo)[0];
		this.isXStreamNeeded = true;
		
		final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
		// handling because there must always be a new instantiation statement for pseudo inits
		this.oidToVarMapping.remove(oid);
		vd.setName(ast.newSimpleName(this.createNewVarName(oid, log.oidClassNames.get(log.oidRecMapping.get(oid)), true)));
		
		final MethodInvocation methodInvocation = ast.newMethodInvocation();
		final Name name = ast.newSimpleName("XSTREAM");
		methodInvocation.setExpression(name);
		methodInvocation.setName(ast.newSimpleName("fromXML")); 
		
		final StringLiteral xmlParam = ast.newStringLiteral();
		xmlParam.setLiteralValue((String) value);
		methodInvocation.arguments().add(xmlParam);
		
//		final CastExpression castExpr = ast.newCastExpression();
//		castExpr.setType(this.createAstType(type, ast));
//		castExpr.setExpression(methodInvocation);
		
//		vd.setInitializer(castExpr);
		vd.setInitializer(methodInvocation);
		
		final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
		vs.setType(this.createAstType("Object", ast));
				
		methodBlock.statements().add(vs);
	}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:40,代码来源:JUnitCodeGenerator.java

示例2: createUnobservedInitStmt

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void createUnobservedInitStmt(final int logRecNo, final Block methodBlock, final AST ast)
{
	// NOTE: PLAIN INIT: has always one non-null param
	// TODO: use primitives
	final int    oid     = this.log.objectIds.get(logRecNo);
	final String type    = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
	final Object value   = this.log.params.get(logRecNo)[0];
	this.isXStreamNeeded = true;
	
	final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
	// handling because there must always be a new instantiation statement for pseudo inits
	this.oidToVarMapping.remove(oid);
	vd.setName(ast.newSimpleName(this.createNewVarName(oid, type)));
	
	final MethodInvocation methodInvocation = ast.newMethodInvocation();
	final Name name = ast.newSimpleName("XSTREAM");
	methodInvocation.setExpression(name);
	methodInvocation.setName(ast.newSimpleName("fromXML")); 
	
	final StringLiteral xmlParam = ast.newStringLiteral();
	xmlParam.setLiteralValue((String) value);
	methodInvocation.arguments().add(xmlParam);
	
	final CastExpression castExpr = ast.newCastExpression();
	castExpr.setType(this.createAstType(type, ast));
	castExpr.setExpression(methodInvocation);
	
	vd.setInitializer(castExpr);
	
	final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
	vs.setType(this.createAstType(type, ast));
			
	methodBlock.statements().add(vs);
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:36,代码来源:CodeGenerator.java

示例3: getLeftMostSimpleName

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
public static SimpleName getLeftMostSimpleName(Name name) {
	if (name instanceof SimpleName) {
		return (SimpleName)name;
	} else {
		final SimpleName[] result= new SimpleName[1];
		ASTVisitor visitor= new ASTVisitor() {
			@Override
			public boolean visit(QualifiedName qualifiedName) {
				Name left= qualifiedName.getQualifier();
				if (left instanceof SimpleName) {
					result[0]= (SimpleName)left;
				} else {
					left.accept(this);
				}
				return false;
			}
		};
		name.accept(visitor);
		return result[0];
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:ASTNodes.java

示例4: getFullName

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
/**
 * Evaluates fully qualified name of the Name object.
 */
private static String getFullName(Name name) {
    // check if the root node is a CompilationUnit
    if (name.getRoot().getClass() != CompilationUnit.class) {
        // cannot resolve a full name, CompilationUnit root node is missing
        return name.getFullyQualifiedName();
    }
    // get the root node
    CompilationUnit root = (CompilationUnit) name.getRoot();
    // check if the name is declared in the same file
    TypeDeclVisitor tdVisitor = new TypeDeclVisitor(name.getFullyQualifiedName());
    root.accept(tdVisitor);
    if (tdVisitor.getFound()) {
        // the name is the use of the TypeDeclaration in the same file
        return getFullName(tdVisitor.getTypeDecl());
    }
    // check if the name is declared in the same package or imported
    PckgImprtVisitor piVisitor = new PckgImprtVisitor(name.getFullyQualifiedName());
    root.accept(piVisitor);
    if (piVisitor.getFound()) {
        // the name is declared in the same package or imported
        return piVisitor.getFullName();
    }
    // could be a class from the java.lang (String) or a param name (T, E,...)
    return name.getFullyQualifiedName();
}
 
开发者ID:linzeqipku,项目名称:SnowGraph,代码行数:29,代码来源:NameResolver.java

示例5: getTopMostType

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
/**
 * Returns the topmost ancestor of <code>node</code> that is a {@link Type} (but not a {@link UnionType}).
 * <p>
 * <b>Note:</b> The returned node often resolves to a different binding than the given <code>node</code>!
 *
 * @param node the starting node, can be <code>null</code>
 * @return the topmost type or <code>null</code> if the node is not a descendant of a type node
 * @see #getNormalizedNode(ASTNode)
 */
public static Type getTopMostType(ASTNode node) {
	ASTNode result= null;
	while (node instanceof Type && !(node instanceof UnionType)
			|| node instanceof Name
			|| node instanceof Annotation || node instanceof MemberValuePair
			|| node instanceof Expression) { // Expression could maybe be reduced to expression node types that can appear in an annotation
		result= node;
		node= node.getParent();
	}

	if (result instanceof Type) {
		return (Type) result;
	}

	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:26,代码来源:ASTNodes.java

示例6: visit

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
@Override
public boolean visit(TagElement node) {
	String tagName= node.getTagName();
	List<? extends ASTNode> list= node.fragments();
	int idx= 0;
	if (tagName != null && !list.isEmpty()) {
		Object first= list.get(0);
		if (first instanceof Name) {
			if ("@throws".equals(tagName) || "@exception".equals(tagName)) {  //$NON-NLS-1$//$NON-NLS-2$
				typeRefFound((Name) first);
			} else if ("@see".equals(tagName) || "@link".equals(tagName) || "@linkplain".equals(tagName)) {  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
				Name name= (Name) first;
				possibleTypeRefFound(name);
			}
			idx++;
		}
	}
	for (int i= idx; i < list.size(); i++) {
		doVisitNode(list.get(i));
	}
	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:ImportReferencesCollector.java

示例7: getArgument

import org.eclipse.jdt.core.dom.Name; //导入依赖的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,项目名称:eclipse.jdt.ls,代码行数:22,代码来源:JavadocTagsSubProcessor.java

示例8: getInvalidQualificationProposals

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
public static void getInvalidQualificationProposals(IInvocationContext context, IProblemLocation problem,
		Collection<CUCorrectionProposal> proposals) {
	ASTNode node= problem.getCoveringNode(context.getASTRoot());
	if (!(node instanceof Name)) {
		return;
	}
	Name name= (Name) node;
	IBinding binding= name.resolveBinding();
	if (!(binding instanceof ITypeBinding)) {
		return;
	}
	ITypeBinding typeBinding= (ITypeBinding)binding;

	AST ast= node.getAST();
	ASTRewrite rewrite= ASTRewrite.create(ast);
	rewrite.replace(name, ast.newName(typeBinding.getQualifiedName()), null);

	String label= CorrectionMessages.JavadocTagsSubProcessor_qualifylinktoinner_description;
	ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(),
			rewrite, IProposalRelevance.QUALIFY_INNER_TYPE_NAME);

	proposals.add(proposal);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:JavadocTagsSubProcessor.java

示例9: hasImportDeclaration

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
private boolean hasImportDeclaration(CompilationUnit unit) {
   List imports = unit.imports();
for(Iterator iter = imports.iterator(); iter.hasNext() ; ) {
	Object next = iter.next();
	if (next instanceof ImportDeclaration ) {
		ImportDeclaration importDecl = (ImportDeclaration)next;
		Name name = importDecl.getName();
		if (name instanceof QualifiedName ) {
			QualifiedName qName = (QualifiedName)name;
			String qNameString = qName.getFullyQualifiedName();
			if (qNameString.startsWith("edu.cmu.cs.aliasjava.annotations") ) {
				return true;
			}
		}
	}
}
   return false;
  }
 
开发者ID:aroog,项目名称:code,代码行数:19,代码来源:SaveAnnotations.java

示例10: rewriteReference

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
private RefactoringStatus rewriteReference(ASTRewrite astRewrite,
		ImportRewrite importRewrite, SimpleName name,
		String fullyQualifiedTypeName) {
	final RefactoringStatus status = new RefactoringStatus();

	// get the node to replace.
	final Name nodeToReplace = Util.getTopmostName(name);

	// If its in a case statement.
	if (Util.isContainedInCaseLabel(name)) {
		if (!nodeToReplace.isSimpleName()) // Need to remove prefix.
			astRewrite.replace(nodeToReplace, name, null);
		return status;
	}

	// Make a copy of the simple name.
	final AST ast = name.getAST();
	final SimpleName nameCopy = (SimpleName) ASTNode.copySubtree(ast, name);

	final String typeName = importRewrite.addImport(fullyQualifiedTypeName);
	final QualifiedName newNameNode = ast.newQualifiedName(
			ast.newName(typeName), nameCopy);

	astRewrite.replace(nodeToReplace, newNameNode, null);
	return status;
}
 
开发者ID:ponder-lab,项目名称:Constants-to-Enum-Eclipse-Plugin,代码行数:27,代码来源:ConvertConstantsToEnumRefactoring.java

示例11: replace

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
public void replace(ASTRewrite rewrite, ASTNode replacement, TextEditGroup textEditGroup) {
  ASTNode groupNode = getGroupRoot();

  List<Expression> allOperands = findGroupMembersInOrderFor(getGroupRoot());
  if (allOperands.size() == fOperands.size()) {
    if (replacement instanceof Name && groupNode.getParent() instanceof ParenthesizedExpression) {
      // replace including the parenthesized expression around it
      rewrite.replace(groupNode.getParent(), replacement, textEditGroup);
    } else {
      rewrite.replace(groupNode, replacement, textEditGroup);
    }
    return;
  }

  rewrite.replace(fOperands.get(0), replacement, textEditGroup);
  int first = allOperands.indexOf(fOperands.get(0));
  int after = first + fOperands.size();
  for (int i = first + 1; i < after; i++) {
    rewrite.remove(allOperands.get(i), textEditGroup);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:AssociativeInfixExpressionFragment.java

示例12: visit

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
@Override
public boolean visit(TagElement node) {
  String tagName = node.getTagName();
  List<? extends ASTNode> list = node.fragments();
  int idx = 0;
  if (tagName != null && !list.isEmpty()) {
    Object first = list.get(0);
    if (first instanceof Name) {
      if ("@throws".equals(tagName) || "@exception".equals(tagName)) { // $NON-NLS-1$//$NON-NLS-2$
        typeRefFound((Name) first);
      } else if ("@see".equals(tagName)
          || "@link".equals(tagName)
          || "@linkplain".equals(tagName)) { // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        Name name = (Name) first;
        possibleTypeRefFound(name);
      }
      idx++;
    }
  }
  for (int i = idx; i < list.size(); i++) {
    doVisitNode(list.get(i));
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ImportReferencesCollector.java

示例13: hasNullAnnotation

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
private static boolean hasNullAnnotation(MethodDeclaration decl) {
  List<IExtendedModifier> modifiers = decl.modifiers();
  String nonnull =
      NullAnnotationsFix.getNonNullAnnotationName(decl.resolveBinding().getJavaElement(), false);
  String nullable =
      NullAnnotationsFix.getNullableAnnotationName(decl.resolveBinding().getJavaElement(), false);
  for (Object mod : modifiers) {
    if (mod instanceof Annotation) {
      Name annotationName = ((Annotation) mod).getTypeName();
      String fullyQualifiedName = annotationName.getFullyQualifiedName();
      if (annotationName.isSimpleName()
          ? nonnull.endsWith(fullyQualifiedName)
          : fullyQualifiedName.equals(nonnull)) return true;
      if (annotationName.isSimpleName()
          ? nullable.endsWith(fullyQualifiedName)
          : fullyQualifiedName.equals(nullable)) return true;
    }
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:NullAnnotationsRewriteOperations.java

示例14: findTempDeclaration

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
/**
 * @return <code>null</code> if the selection is invalid or does not cover a temp declaration or
 *     reference.
 */
public static VariableDeclaration findTempDeclaration(
    CompilationUnit cu, int selectionOffset, int selectionLength) {
  TempSelectionAnalyzer analyzer = new TempSelectionAnalyzer(selectionOffset, selectionLength);
  cu.accept(analyzer);

  ASTNode[] selected = analyzer.getSelectedNodes();
  if (selected == null || selected.length != 1) return null;

  ASTNode selectedNode = selected[0];
  if (selectedNode instanceof VariableDeclaration) return (VariableDeclaration) selectedNode;

  if (selectedNode instanceof Name) {
    Name reference = (Name) selectedNode;
    IBinding binding = reference.resolveBinding();
    if (binding == null) return null;
    ASTNode declaringNode = cu.findDeclaringNode(binding);
    if (declaringNode instanceof VariableDeclaration) return (VariableDeclaration) declaringNode;
    else return null;
  } else if (selectedNode instanceof VariableDeclarationStatement) {
    VariableDeclarationStatement vds = (VariableDeclarationStatement) selectedNode;
    if (vds.fragments().size() != 1) return null;
    return (VariableDeclaration) vds.fragments().get(0);
  }
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:30,代码来源:TempDeclarationFinder.java

示例15: checkExpressionIsRValue

import org.eclipse.jdt.core.dom.Name; //导入依赖的package包/类
/**
 * @param e
 * @return int Checks.IS_RVALUE if e is an rvalue Checks.IS_RVALUE_GUESSED if e is guessed as an
 *     rvalue Checks.NOT_RVALUE_VOID if e is not an rvalue because its type is void
 *     Checks.NOT_RVALUE_MISC if e is not an rvalue for some other reason
 */
public static int checkExpressionIsRValue(Expression e) {
  if (e instanceof Name) {
    if (!(((Name) e).resolveBinding() instanceof IVariableBinding)) {
      return NOT_RVALUE_MISC;
    }
  }
  if (e instanceof Annotation) return NOT_RVALUE_MISC;

  ITypeBinding tb = e.resolveTypeBinding();
  boolean guessingRequired = false;
  if (tb == null) {
    guessingRequired = true;
    tb = ASTResolving.guessBindingForReference(e);
  }
  if (tb == null) return NOT_RVALUE_MISC;
  else if (tb.getName().equals("void")) // $NON-NLS-1$
  return NOT_RVALUE_VOID;

  return guessingRequired ? IS_RVALUE_GUESSED : IS_RVALUE;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:Checks.java


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