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


Java TypeDeclaration.getFields方法代碼示例

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


在下文中一共展示了TypeDeclaration.getFields方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hasFieldInitializers

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
private static boolean hasFieldInitializers(TypeDeclaration typeDecl) {
	boolean returnFlag = false;
	for (FieldDeclaration fd : typeDecl.getFields()) {
		// Skip over primitive types
		if (fd.getType().isPrimitiveType() ) {
			continue;
		}
		if (fd.fragments().size() > 0)
			if (fd.fragments().get(0) instanceof VariableDeclarationFragment) {
				VariableDeclarationFragment vdf = (VariableDeclarationFragment) fd.fragments().get(0);
				if (vdf.getInitializer() != null)
					returnFlag = true;
			}
	}
	return returnFlag;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:17,代碼來源:AuxJudgements.java

示例2: visit

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
@Override
public boolean visit(TypeDeclaration node) {
	System.out.println(node.getParent().getClass());
	if(info == null)
		info = new ClassInfo(node.resolveBinding().getQualifiedName(), VisibilityInfo.from(node));
	
	
	for(FieldDeclaration f : node.getFields()) {
		if(!Modifier.isStatic(f.getModifiers())) {
			for(Object o : f.fragments()) {
				VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
				info.addField(new FieldInfo(frag.getName().toString()));
			}
		}

	}

	return true;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:20,代碼來源:Visitor.java

示例3: populateMethodDeclarations

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
private void populateMethodDeclarations(TypeDeclaration declaration){
	
	TypeDeclaration[] nestedTypes = declaration.getTypes();
	for (int i = 0; i < nestedTypes.length; i++) {
		TypeDeclaration nestedType = nestedTypes[i];
		populateMethodDeclarations(nestedType);
	}
	
	FieldDeclaration[] fields = declaration.getFields();
	for (FieldDeclaration fieldDeclaration : fields) {
		fieldDeclaration.accept(new HeuristicOwnedVisitor());
	}
	
	MethodDeclaration[] methods = declaration.getMethods();
	for (MethodDeclaration methodDeclaration : methods) {
		methodDeclaration.accept(new HeuristicOwnedVisitor());
		methodDeclaration.accept(new HeuristicOwnedLocalsVisitor());
		this.methodDecls.add(methodDeclaration);
	}
}
 
開發者ID:aroog,項目名稱:code,代碼行數:21,代碼來源:RefinementAnalysis.java

示例4: fieldBody

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
/**
 * returns all field bodies declared in a type, and its supertype,
 * recursively TODO: actual/formal substitution
 * */
public static Set<FieldDeclaration> fieldBody(TypeDeclaration typeDecl, TypeHierarchy hierarchy,
		Map<ast.Type, TypeDeclaration> types, QualifiedClassName cThis) {
	Set<FieldDeclaration> returnSet = new HashSet<FieldDeclaration>();
	for (FieldDeclaration fd : typeDecl.getFields())
		returnSet.add(fd);
	Type superclassType = typeDecl.getSuperclassType();
	if (superclassType == null)
		return returnSet;
	if (superclassType.resolveBinding().getQualifiedName().equals(Utils.JAVA_LANG_OBJECT))
		return returnSet;

	TypeDeclaration superTypeDecl = types.get(new QualifiedClassName(superclassType.resolveBinding(), cThis)
			.getType());
	if (superTypeDecl != null) {
		Set<FieldDeclaration> auxSet = fieldBody(superTypeDecl, hierarchy, types, cThis);
		returnSet.addAll(auxSet);
	}
	return returnSet;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:24,代碼來源:AuxJudgements.java

示例5: getEnclosingType

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
/**
 * @param methodBinding
 * @return
 *//*
private ast.TypeDeclaration getEnclosingType(IMethodBinding methodBinding) {
	ast.TypeDeclaration typeDeclaration = getTypeDeclaration(methodBinding.getDeclaringClass());
	return typeDeclaration;
}*/

public static List<ast.FieldDeclaration> getDeclaredFields(
		TypeDeclaration td) {
	List<ast.FieldDeclaration> fieldList = new ArrayList<ast.FieldDeclaration>();
	for(FieldDeclaration fieldDec: td.getFields()){
		List<VariableDeclarationFragment> fragments = fieldDec.fragments();
		for(VariableDeclarationFragment varDecFrag: fragments){
			fieldList.add(getFieldDeclaration(varDecFrag));
		}
	}
	return fieldList;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:21,代碼來源:TraceabilityFactory.java

示例6: populateMethodDeclarations

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
private void populateMethodDeclarations(TypeDeclaration declaration){
		
		TypeDeclaration[] nestedTypes = declaration.getTypes();
		for (int i = 0; i < nestedTypes.length; i++) {
			TypeDeclaration nestedType = nestedTypes[i];
			populateMethodDeclarations(nestedType);
		}
		
		FieldDeclaration[] fields = declaration.getFields();
//		for (FieldDeclaration fieldDeclaration : fields) {
//			fieldDeclaration.accept(new HeuristicOwnedVisitor());
//		}
		
		MethodDeclaration[] methods = declaration.getMethods();
		for (MethodDeclaration methodDeclaration : methods) {
//			methodDeclaration.accept(new HeuristicOwnedVisitor());
//			methodDeclaration.accept(new HeuristicOwnedLocalsVisitor());
			this.methodDecls.add(methodDeclaration);
		}
	}
 
開發者ID:aroog,項目名稱:code,代碼行數:21,代碼來源:RefinementAnalysis.java

示例7: visitInterface

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
private boolean visitInterface(TypeDeclaration node) {

        InterfaceInfo interfaceInfo = new InterfaceInfo();
        interfaceInfo.name = node.getName().getFullyQualifiedName();
        interfaceInfo.fullName = NameResolver.getFullName(node);
        interfaceInfo.visibility = getVisibility(node);
        List<Type> superInterfaceList = node.superInterfaceTypes();
        for (Type superInterface : superInterfaceList)
            interfaceInfo.superInterfaceTypeList.add(NameResolver.getFullName(superInterface));
        if (node.getJavadoc() != null)
            interfaceInfo.comment = sourceContent.substring(node.getJavadoc().getStartPosition(), node.getJavadoc().getStartPosition() + node.getJavadoc().getLength());
        interfaceInfo.content = sourceContent.substring(node.getStartPosition(), node.getStartPosition() + node.getLength());
        elementInfoPool.interfaceInfoMap.put(interfaceInfo.fullName, interfaceInfo);

        MethodDeclaration[] methodDeclarations = node.getMethods();
        for (MethodDeclaration methodDeclaration : methodDeclarations) {
            MethodInfo methodInfo = createMethodInfo(methodDeclaration, interfaceInfo.fullName);
            elementInfoPool.methodInfoMap.put(methodInfo.hashName(), methodInfo);
        }

        FieldDeclaration[] fieldDeclarations = node.getFields();
        for (FieldDeclaration fieldDeclaration : fieldDeclarations) {
            List<FieldInfo> fieldInfos = createFieldInfos(fieldDeclaration, interfaceInfo.fullName);
            for (FieldInfo fieldInfo : fieldInfos)
                elementInfoPool.fieldInfoMap.put(fieldInfo.hashName(), fieldInfo);
        }
        return true;
    }
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:29,代碼來源:JavaASTVisitor.java

示例8: visitClass

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
private boolean visitClass(TypeDeclaration node) {

        ClassInfo classInfo = new ClassInfo();
        classInfo.name = node.getName().getFullyQualifiedName();
        classInfo.fullName = NameResolver.getFullName(node);
        classInfo.visibility = getVisibility(node);
        classInfo.isAbstract = isAbstract(node);
        classInfo.isFinal = isFinal(node);
        classInfo.superClassType = node.getSuperclassType() == null ? "java.lang.Object" : NameResolver.getFullName(node.getSuperclassType());
        List<Type> superInterfaceList = node.superInterfaceTypes();
        for (Type superInterface : superInterfaceList)
            classInfo.superInterfaceTypeList.add(NameResolver.getFullName(superInterface));
        if (node.getJavadoc() != null)
            classInfo.comment = sourceContent.substring(node.getJavadoc().getStartPosition(), node.getJavadoc().getStartPosition() + node.getJavadoc().getLength());
        classInfo.content = sourceContent.substring(node.getStartPosition(), node.getStartPosition() + node.getLength());
        elementInfoPool.classInfoMap.put(classInfo.fullName, classInfo);

        MethodDeclaration[] methodDeclarations = node.getMethods();
        for (MethodDeclaration methodDeclaration : methodDeclarations) {
            MethodInfo methodInfo = createMethodInfo(methodDeclaration, classInfo.fullName);
            elementInfoPool.methodInfoMap.put(methodInfo.hashName(), methodInfo);
        }

        FieldDeclaration[] fieldDeclarations = node.getFields();
        for (FieldDeclaration fieldDeclaration : fieldDeclarations) {
            List<FieldInfo> fieldInfos = createFieldInfos(fieldDeclaration, classInfo.fullName);
            for (FieldInfo fieldInfo : fieldInfos)
                elementInfoPool.fieldInfoMap.put(fieldInfo.hashName(), fieldInfo);
        }
        return true;
    }
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:32,代碼來源:JavaASTVisitor.java

示例9: findBuilderFieldsRecursively

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
public List<? extends BuilderField> findBuilderFieldsRecursively(TypeDeclaration originalOwnerClasss, TypeDeclaration currentOwnerClass) {
    List<BuilderField> builderFields = new ArrayList<>();

    if (preferencesManager.getPreferenceValue(INCLUDE_VISIBLE_FIELDS_FROM_SUPERCLASS)) {
        builderFields.addAll(getFieldsFromSuperclass(currentOwnerClass));
    }

    FieldDeclaration[] fields = currentOwnerClass.getFields();
    for (FieldDeclaration field : fields) {
        List<VariableDeclarationFragment> fragments = field.fragments();
        builderFields.addAll(getFilteredDeclarations(field, fragments));
    }
    return builderFields;
}
 
開發者ID:helospark,項目名稱:SparkBuilderGenerator,代碼行數:15,代碼來源:ClassFieldCollector.java

示例10: insertMethodToFirstPlace

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
public void insertMethodToFirstPlace(TypeDeclaration originalType, ListRewrite listRewrite, MethodDeclaration privateConstructor) {
    FieldDeclaration[] fields = originalType.getFields();
    if (fields == null || fields.length == 0) {
        listRewrite.insertFirst(privateConstructor, null);
    } else {
        listRewrite.insertAfter(privateConstructor, fields[fields.length - 1], null);
    }
}
 
開發者ID:helospark,項目名稱:SparkBuilderGenerator,代碼行數:9,代碼來源:PrivateConstructorInsertionFragment.java

示例11: annotateFieldDeclarations

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
private void annotateFieldDeclarations(ASTRewrite rewrite, TypeDeclaration declaration) {

		FieldDeclaration[] fieldDeclarations = declaration.getFields();
		for (int i = 0; i < fieldDeclarations.length; i++) {
			FieldDeclaration fieldDeclaration = fieldDeclarations[i];
			ITypeBinding type = fieldDeclaration.getType().resolveBinding();

			if (!type.isPrimitive()) {
				String annotation = "";

				if (HARD_CODE_STATICS && Modifier.isStatic(fieldDeclaration.getModifiers())) {
					// XXX. Avoid unique fields. Use shared. 
					annotation = "shared<shared>";
				}
				else {
					annotation = strategy.getAnnotationForFieldDeclaration(fieldDeclaration);
				}

				SingleMemberAnnotation currentAnnotation = getCurrentAnnotation(fieldDeclaration.modifiers());
				if (currentAnnotation == null) {
					setFieldAnnotation(rewrite, fieldDeclaration, annotation);
				}
				else {
					updateFieldAnnotation(rewrite, fieldDeclaration, annotation, currentAnnotation);
				}		
				
				String srcType = type.getQualifiedName();
				String dstType = declaration.getName().getFullyQualifiedName();
				// XXX. Come up with a better key
				trackChanges(fieldDeclaration.toString(), annotation, getValue(currentAnnotation), CSVConst.FIELD, srcType, dstType);
			}
		}
	}
 
開發者ID:aroog,項目名稱:code,代碼行數:34,代碼來源:SaveAnnotations.java

示例12: annotateFieldDeclarations

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
private void annotateFieldDeclarations(ASTRewrite rewrite, TypeDeclaration declaration) {

		FieldDeclaration[] fieldDeclarations = declaration.getFields();
		for (int i = 0; i < fieldDeclarations.length; i++) {
			FieldDeclaration fieldDeclaration = fieldDeclarations[i];
			ITypeBinding type = fieldDeclaration.getType().resolveBinding();
			if (type == null) {
				continue;
			}
			if (!type.isPrimitive()) {
				String annotation = "";

				if (HARD_CODE_STATICS && Modifier.isStatic(fieldDeclaration.getModifiers())) {
					// XXX. Avoid unique fields. Use shared. 
					annotation = "shared<shared>";
				}
				else {
					annotation = strategy.getAnnotationForFieldDeclaration(fieldDeclaration);
				}

				SingleMemberAnnotation currentAnnotation = getCurrentAnnotation(fieldDeclaration.modifiers());
				if (currentAnnotation == null) {
					setFieldAnnotation(rewrite, fieldDeclaration, annotation);
				}
				else {
					updateFieldAnnotation(rewrite, fieldDeclaration, annotation, currentAnnotation);
				}		
				
				String srcType = type.getQualifiedName();
				String dstType = declaration.getName().getFullyQualifiedName();
				// XXX. Come up with a better key
				trackChanges(fieldDeclaration.toString(), annotation, getValue(currentAnnotation), CSVConst.FIELD, srcType, dstType);
			}
		}
	}
 
開發者ID:aroog,項目名稱:code,代碼行數:36,代碼來源:SaveAnnotations.java

示例13: traverseFields

import org.eclipse.jdt.core.dom.TypeDeclaration; //導入方法依賴的package包/類
private void traverseFields(TypeDeclaration declaration) {
	FieldDeclaration[] fieldDeclarations = declaration.getFields();
	for (int i = 0; i < fieldDeclarations.length; i++) {
		FieldDeclaration fieldDeclaration = fieldDeclarations[i];
		ITypeBinding type = fieldDeclaration.getType().resolveBinding();

		if (hasAnnotation(fieldDeclaration.modifiers()) && !type.isPrimitive()) {

			List ff = fieldDeclaration.fragments();
			for (Object ff1 : ff) {
				VariableDeclaration V = (VariableDeclaration) ff1;
				String key = V.resolveBinding().getKey();
				String name = V.getName().getIdentifier();
				String objectType = fieldDeclaration.getType().resolveBinding().getQualifiedName();
				
				String enclosingType = declaration.resolveBinding().getQualifiedName();
			
				String ast = fieldDeclaration.getAST().toString();
				boolean isStatic = Modifier.isStatic(fieldDeclaration.getModifiers());
				//					
				SingleMemberAnnotation annotation = getAnnotation(fieldDeclaration.modifiers());
				Expression value = annotation.getValue();
				if (value instanceof StringLiteral) { //@Domain("D")
					StringLiteral annotValue = (StringLiteral)value;
					String parserInput = annotValue.getLiteralValue();
					AnnotationInfo annotInfo = AnnotationInfo.parseAnnotation(parserInput); 
					DomainParams annot = annotInfo.getAnnotation();	
				
					boolean isDomainParam = isDomainParams(declaration.resolveBinding(), annot);
					boolean isDomain = isDomain(declaration.resolveBinding(), annot);
					ObjectMetricItem archMetricItem = new ObjectMetricItem(key,name,
							objectType,
							parserInput,
							enclosingType,
							ast,
							isStatic,
							"Field",
							type.isArray(),
							type.isEnum(),
							type.isParameterizedType(),
							isDomain,
							isDomainParam,
							annot.isObjectPublicDomain()
					);
					// TODO: Do we need the following two lines?
					archMetricItem.setDomainParams(isDomainParam);
					archMetricItem.setDomain(isDomain);
					if (!objectsHashtable.containsKey(archMetricItem.toString())) {							
						objectsHashtable.put(archMetricItem.toString(), archMetricItem);
					}
					
					// TODO: src.triplets for Field
				}

				else
				{
					//this should not happen
					System.out.println("Error in field declaration: "+ value);
				}
			}
		}
	}
}
 
開發者ID:aroog,項目名稱:code,代碼行數:64,代碼來源:AnnotatMetrics.java


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