當前位置: 首頁>>代碼示例>>Java>>正文


Java SingleVariableDeclaration類代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.SingleVariableDeclaration的典型用法代碼示例。如果您正苦於以下問題:Java SingleVariableDeclaration類的具體用法?Java SingleVariableDeclaration怎麽用?Java SingleVariableDeclaration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SingleVariableDeclaration類屬於org.eclipse.jdt.core.dom包,在下文中一共展示了SingleVariableDeclaration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: locationNeedsParentheses

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
	if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
		// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
		return false;
	}
	if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
			|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
			|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
			|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
			|| locationInParent == ForStatement.EXPRESSION_PROPERTY
			|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
			|| locationInParent == DoStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.MESSAGE_PROPERTY
			|| locationInParent == IfStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
			|| locationInParent == ArrayAccess.INDEX_PROPERTY
			|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
			|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
			|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		return false;
	}
	return true;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:26,代碼來源:NecessaryParenthesesChecker.java

示例2: ensureParameterFromSingleVariableDeclaration

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
public Parameter ensureParameterFromSingleVariableDeclaration(SingleVariableDeclaration variableDeclaration,
		Method method) {
	String name = variableDeclaration.getName().toString();
	String qualifiedName = Famix.qualifiedNameOf(method) + NAME_SEPARATOR + name;
	if (parameters.has(qualifiedName)) 
		return parameters.named(qualifiedName);
	Parameter parameter = new Parameter();
	parameters.add(qualifiedName, parameter);
	parameter.setName(name);
	parameter.setParentBehaviouralEntity(method);
	parameter.setDeclaredType(ensureTypeFromDomType(variableDeclaration.getType()));
	IVariableBinding binding = variableDeclaration.resolveBinding();
	if (binding != null) {
		createAnnotationInstancesToEntityFromAnnotationBinding(parameter, binding.getAnnotations());
		//We only recover the final modifier
		if (Modifier.isFinal(binding.getModifiers())) parameter.addModifiers("final");
	}
	return parameter;
}
 
開發者ID:feenkcom,項目名稱:jdt2famix,代碼行數:20,代碼來源:InJavaImporter.java

示例3: asClosure

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
public static Optional<GroovyClosure> asClosure(ASTNodeFactory nodeFactory, GroovyClosureBuilder groovyClosureBuilder,
                                      Expression expression, String methodName) {
    if (expression instanceof ClassInstanceCreation) {
        ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
        if (classInstanceCreation.getAnonymousClassDeclaration() != null) {
            AnonymousClassDeclaration classDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
            if (classDeclaration.bodyDeclarations().size() == 1 &&
                    classDeclaration.bodyDeclarations().get(0) instanceof MethodDeclaration &&
                    ((MethodDeclaration) classDeclaration.bodyDeclarations().get(0))
                            .getName().getIdentifier().equals(methodName)) {
                MethodDeclaration methodDeclaration = (MethodDeclaration) classDeclaration.bodyDeclarations().get(0);
                List<Statement> statements = nodeFactory.clone(methodDeclaration.getBody()).statements();
                GroovyClosure closure = groovyClosureBuilder.aClosure()
                        .withBodyStatements(statements)
                        .withTypeLiteral(nodeFactory.typeLiteral(type(nodeFactory, classInstanceCreation)))
                        .withArgument(nodeFactory.clone((SingleVariableDeclaration) methodDeclaration.parameters().get(0)))
                        .build();
                return Optional.of(closure);
            }
        }
    }
    return empty();
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:24,代碼來源:ClosureHelper.java

示例4: getSignatureFromMethodDeclaration

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
public static String getSignatureFromMethodDeclaration(MethodDeclaration methodDeclaration) {
		String methodName = methodDeclaration.isConstructor() ? "" : methodDeclaration.getName().getIdentifier();
//		if (methodName.equals("allObjectsSorted")) {
//			System.out.println();
//		}
		StringBuilder sb = new StringBuilder();
		sb.append(methodName);
		sb.append('(');
		@SuppressWarnings("unchecked")
        Iterator<SingleVariableDeclaration> parameters = methodDeclaration.parameters().iterator();
		while (parameters.hasNext()) {
			SingleVariableDeclaration parameter = parameters.next();
			Type parameterType = parameter.getType();
			String typeName = normalizeTypeName(parameterType, parameter.getExtraDimensions(), parameter.isVarargs());
			sb.append(typeName);
			if (parameters.hasNext()) {
				sb.append(", ");
			}
		}
		sb.append(')');
		String methodSignature = sb.toString();
		return methodSignature;
	}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:24,代碼來源:AstUtils.java

示例5: createNewWithMethod

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
private MethodDeclaration createNewWithMethod(AST ast, String fieldName, Block newBlock,
        SingleVariableDeclaration methodParameterDeclaration, TypeDeclaration builderType,
        BuilderField builderField) {
    MethodDeclaration builderMethod = ast.newMethodDeclaration();
    builderMethod.setName(ast.newSimpleName(builderClassMethodNameGeneratorService.build(fieldName)));
    builderMethod.setReturnType2(ast.newSimpleType(
            ast.newName(builderType.getName().getIdentifier())));
    builderMethod.setBody(newBlock);
    builderMethod.parameters().add(methodParameterDeclaration);

    javadocAdder.addJavadocForWithMethod(ast, fieldName, builderMethod);
    if (preferencesManager.getPreferenceValue(ADD_NONNULL_ON_RETURN)) {
        markerAnnotationAttacher.attachNonNull(ast, builderMethod);
    }
    builderMethod.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));

    return builderMethod;
}
 
開發者ID:helospark,項目名稱:SparkBuilderGenerator,代碼行數:19,代碼來源:RegularBuilderWithMethodAdderFragment.java

示例6: createPrivateConstructorDefinition

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public MethodDeclaration createPrivateConstructorDefinition(AST ast, TypeDeclaration originalType, TypeDeclaration builderType,
        List<BuilderField> builderFields) {

    MethodDeclaration method = ast.newMethodDeclaration();
    method.setConstructor(true);
    method.setName(ast.newSimpleName(originalType.getName().toString()));
    if (preferencesManager.getPreferenceValue(ADD_GENERATED_ANNOTATION)) {
        generatedAnnotationPopulator.addGeneratedAnnotation(ast, method);
    }
    method.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));

    SingleVariableDeclaration methodParameterDeclaration = ast.newSingleVariableDeclaration();
    methodParameterDeclaration.setType(ast.newSimpleType(ast.newName(builderType.getName().toString())));
    methodParameterDeclaration.setName(ast.newSimpleName(camelCaseConverter.toLowerCamelCase(builderType.getName().toString())));

    method.parameters().add(methodParameterDeclaration);
    return method;
}
 
開發者ID:helospark,項目名稱:SparkBuilderGenerator,代碼行數:20,代碼來源:PrivateConstructorMethodDefinitionCreationFragment.java

示例7: getType

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
/**
 * Returns the type node for the given declaration.
 *
 * @param declaration the declaration
 * @return the type node or <code>null</code> if the given declaration represents a type
 *         inferred parameter in lambda expression
 */
public static Type getType(VariableDeclaration declaration) {
	if (declaration instanceof SingleVariableDeclaration) {
		return ((SingleVariableDeclaration)declaration).getType();
	} else if (declaration instanceof VariableDeclarationFragment) {
		ASTNode parent= ((VariableDeclarationFragment)declaration).getParent();
		if (parent instanceof VariableDeclarationExpression) {
			return ((VariableDeclarationExpression)parent).getType();
		} else if (parent instanceof VariableDeclarationStatement) {
			return ((VariableDeclarationStatement)parent).getType();
		} else if (parent instanceof FieldDeclaration) {
			return ((FieldDeclaration)parent).getType();
		} else if (parent instanceof LambdaExpression) {
			return null;
		}
	}
	Assert.isTrue(false, "Unknown VariableDeclaration"); //$NON-NLS-1$
	return null;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:26,代碼來源:ASTNodes.java

示例8: isExceptionCaught

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
boolean isExceptionCaught(ITypeBinding excpetionType) {
	for (Iterator<List<CatchClause>> exceptions= fExceptionStack.iterator(); exceptions.hasNext(); ) {
		for (Iterator<CatchClause> catchClauses= exceptions.next().iterator(); catchClauses.hasNext(); ) {
			SingleVariableDeclaration caughtException= catchClauses.next().getException();
			IVariableBinding binding= caughtException.resolveBinding();
			if (binding == null) {
				continue;
			}
			ITypeBinding caughtype= binding.getType();
			while (caughtype != null) {
				if (caughtype == excpetionType) {
					return true;
				}
				caughtype= caughtype.getSuperclass();
			}
		}
	}
	return false;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:20,代碼來源:FlowContext.java

示例9: initializeParameterInfos

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
private void initializeParameterInfos() {
	IVariableBinding[] arguments = fAnalyzer.getArguments();
	fParameterInfos = new ArrayList<>(arguments.length);
	ASTNode root = fAnalyzer.getEnclosingBodyDeclaration();
	ParameterInfo vararg = null;
	for (int i = 0; i < arguments.length; i++) {
		IVariableBinding argument = arguments[i];
		if (argument == null) {
			continue;
		}
		VariableDeclaration declaration = ASTNodes.findVariableDeclaration(argument, root);
		boolean isVarargs = declaration instanceof SingleVariableDeclaration ? ((SingleVariableDeclaration) declaration).isVarargs() : false;
		ParameterInfo info = new ParameterInfo(argument, getType(declaration, isVarargs), argument.getName(), i);
		if (isVarargs) {
			vararg = info;
		} else {
			fParameterInfos.add(info);
		}
	}
	if (vararg != null) {
		fParameterInfos.add(vararg);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:24,代碼來源:ExtractMethodRefactoring.java

示例10: addEnhancedForWithoutTypeProposals

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
private static void addEnhancedForWithoutTypeProposals(ICompilationUnit cu, ASTNode selectedNode,
		Collection<CUCorrectionProposal> proposals) {
	if (selectedNode instanceof SimpleName && (selectedNode.getLocationInParent() == SimpleType.NAME_PROPERTY || selectedNode.getLocationInParent() == NameQualifiedType.NAME_PROPERTY)) {
		ASTNode type= selectedNode.getParent();
		if (type.getLocationInParent() == SingleVariableDeclaration.TYPE_PROPERTY) {
			SingleVariableDeclaration svd= (SingleVariableDeclaration) type.getParent();
			if (svd.getLocationInParent() == EnhancedForStatement.PARAMETER_PROPERTY) {
				if (svd.getName().getLength() == 0) {
					SimpleName simpleName= (SimpleName) selectedNode;
					String name= simpleName.getIdentifier();
					int relevance= StubUtility.hasLocalVariableName(cu.getJavaProject(), name) ? 10 : 7;
					String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_create_loop_variable_description, BasicElementLabels.getJavaElementName(name));

					proposals.add(new NewVariableCorrectionProposal(label, cu, NewVariableCorrectionProposal.LOCAL,
							simpleName, null, relevance));
				}
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:21,代碼來源:UnresolvedElementsSubProcessor.java

示例11: addNewParameters

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
@Override
protected void addNewParameters(ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params, ImportRewriteContext context) throws CoreException {
	AST ast= rewrite.getAST();

	List<Expression> arguments= fArguments;

	for (int i= 0; i < arguments.size(); i++) {
		Expression elem= arguments.get(i);
		SingleVariableDeclaration param= ast.newSingleVariableDeclaration();

		// argument type
		String argTypeKey= "arg_type_" + i; //$NON-NLS-1$
		Type type= evaluateParameterType(ast, elem, argTypeKey, context);
		param.setType(type);

		// argument name
		String argNameKey= "arg_name_" + i; //$NON-NLS-1$
		String name= evaluateParameterName(takenNames, elem, type, argNameKey);
		param.setName(ast.newSimpleName(name));

		params.add(param);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:24,代碼來源:NewMethodCorrectionProposal.java

示例12: extractParametersFromSource

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
private void extractParametersFromSource(List<Variable> parametersVarList,
		IMethod javaElement) {
	Option<MethodDeclaration> mDecl = WorkspaceUtilities.getMethodDeclFromModel(javaElement);
	MethodDeclaration mmDecl = mDecl.unwrap();

	List<SingleVariableDeclaration> parameters = mmDecl.parameters();
	for (SingleVariableDeclaration param : parameters) {
		IVariableBinding paramBinding = param.resolveBinding();
		if(!paramBinding.getType().isPrimitive()){
			Variable paramVariable = this.tm.getVariableFromBindingKey(paramBinding.getKey());
			if(paramVariable!=null){
				parametersVarList.add(paramVariable);
			}
		}
	}
}
 
開發者ID:aroog,項目名稱:code,代碼行數:17,代碼來源:PushIntoOwnedTransferFunctions.java

示例13: getFieldName

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
private String getFieldName(org.eclipse.jdt.core.dom.FieldDeclaration fieldDeclaration) {
	String name = null;

	List fragments = fieldDeclaration.fragments();
	Iterator iterator = fragments.iterator();
	while (iterator.hasNext()) {
		Object next = iterator.next();
		if (next instanceof SingleVariableDeclaration) {
			SingleVariableDeclaration svdecl = (SingleVariableDeclaration) next;
			name = svdecl.getName().getIdentifier();
			break;
		}
		else if (next instanceof VariableDeclarationFragment) {
			VariableDeclarationFragment vdf = (VariableDeclarationFragment) next;
			name = vdf.getName().getIdentifier();
			break;
		}
	}
	
	return name;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:22,代碼來源:SummaryView.java

示例14: getMethodParameters

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
/**
 * returns the method Parameters as a list of ast.VariableDeclarataion 
 * */
public static List<ast.VariableDeclaration> getMethodParameters(MethodDeclaration md) {
	List<ast.VariableDeclaration> params = new ArrayList<ast.VariableDeclaration>();
	IMethodBinding methodBinding = md.resolveBinding();
	if(methodBinding != null ) {
		ITypeBinding[] typeParameters = methodBinding.getTypeParameters();
		List<SingleVariableDeclaration> svdList = md.parameters();
		for (SingleVariableDeclaration svd : svdList) {
			ast.Type type = getType(svd.getType().resolveBinding());
			ast.VariableDeclaration vd = VariableDeclaration.createFrom(svd);
			vd.varType = type;
			vd.varName = svd.getName().getFullyQualifiedName();
			params.add(vd);
		}
	}
	return params;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:20,代碼來源:TraceabilityFactory.java

示例15: getParameters

import org.eclipse.jdt.core.dom.SingleVariableDeclaration; //導入依賴的package包/類
private List<IType> getParameters(List list) {
	List<IType> params = new ArrayList<IType>();
	for (Object elem : list) {
		if (elem instanceof SingleVariableDeclaration) {
			SingleVariableDeclaration param = (SingleVariableDeclaration) elem;
			Type type = param.getType();
			if (type != null && type.resolveBinding() != null && type.resolveBinding().getJavaElement() instanceof IType) {
				params.add((IType) type.resolveBinding().getJavaElement());
			} else {
				if (type.resolveBinding() != null && type.isPrimitiveType()) {
					params.add(new PrimitiveTypeHack(type.resolveBinding().getName()));
				}
			}
		}
	}
	return params;
}
 
開發者ID:ioanaverebi,項目名稱:Sparrow,代碼行數:18,代碼來源:OutCodeVisitor.java


注:本文中的org.eclipse.jdt.core.dom.SingleVariableDeclaration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。