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


Java ASTNode類代碼示例

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


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

示例1: ClassModel

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
ClassModel(ASTNodeFactory astNodeFactory, String className, Type superClassType, PackageDeclaration packageDeclaration,
           List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
           List<TypeModel> innerTypes, List<ASTNode> modifiers) {
    groovism = provide();

    this.className = className;
    this.packageDeclaration = packageDeclaration;
    this.fields = fieldDeclarations(fields);
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.modifiers = unmodifiableList(new LinkedList<>(modifiers));
    this.imports = imports;
    this.innerTypes = unmodifiableList(new LinkedList<>(innerTypes));
    if (isTestClass(methods)) {
        this.superClassType = Optional.of(astNodeFactory.simpleType(Specification.class.getSimpleName()));
        imports.add(0, astNodeFactory.importDeclaration(Specification.class));
    } else {
        this.superClassType = Optional.ofNullable(superClassType);
    }
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:20,代碼來源:ClassModel.java

示例2: visit

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
@Override
      public boolean visit(VariableDeclarationFragment param) {

	ASTNode parent = param.getParent();
	if (parent instanceof VariableDeclarationStatement) {
		VariableDeclarationStatement statement = (VariableDeclarationStatement) parent;

		ASTNode annotation = getAnnotation(statement.modifiers(), "Domain");
		if (annotation != null) {
			ListRewrite paramRewrite = rewrite.getListRewrite(statement,
			        VariableDeclarationStatement.MODIFIERS2_PROPERTY);
			paramRewrite.remove(annotation, null);
		}
	}
	return super.visit(param);
}
 
開發者ID:aroog,項目名稱:code,代碼行數:17,代碼來源:RemoveAnnotations.java

示例3: InterfaceModel

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
InterfaceModel(String typeName, Type superClassType, PackageDeclaration packageDeclaration,
               List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
               List<ASTNode> modifiers) {
    groovism = provide();

    LinkedList<ImportDeclaration> importDeclarations = new LinkedList<>(imports);

    this.superClassType = Optional.ofNullable(superClassType).map(Object::toString);

    this.typeName = typeName;
    this.packageDeclaration = packageDeclaration;
    this.fields = unmodifiableList(new LinkedList<>(fields));
    this.methods = unmodifiableList(new LinkedList<>(methods));
    this.imports = unmodifiableList(importDeclarations);
    this.modifiers = unmodifiableList(modifiers);
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:17,代碼來源:InterfaceModel.java

示例4: handleTypeBinding

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
private void handleTypeBinding(ASTNode node, ITypeBinding typeBinding, boolean includeTypeParameters) {
	if (typeBinding == null) {
		StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
		//System.out.println(locationInParent.getId() + " has no type binding");
	} else {
		List<ITypeBinding> rawTypes = new ArrayList<ITypeBinding>();
		Set<String> dejavu = new HashSet<String>();
		this.appendRawTypes(rawTypes, dejavu, typeBinding, includeTypeParameters);
		for (ITypeBinding rawType : rawTypes) {
			if (!this.ignoreType(rawType)) {
				this.onTypeAccess(node, rawType);
			}
		}
		
	}
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:17,代碼來源:DependenciesAstVisitor.java

示例5: getBlockType

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
private BlockInfo.Type getBlockType(ASTNode node) {
	if(node instanceof TypeDeclaration)
		return BlockInfo.Type.TYPE;

	else if(node instanceof MethodDeclaration)
		return BlockInfo.Type.METHOD;

	else if(node instanceof WhileStatement)
		return BlockInfo.Type.WHILE;

	else if(node instanceof ForStatement)
		return BlockInfo.Type.FOR;

	else if(node instanceof IfStatement)
		return BlockInfo.Type.IF;
	else
		return BlockInfo.Type.OTHER;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:19,代碼來源:VarParser.java

示例6: visit

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration node) {
	List fragments = node.fragments();
	for(Object o : fragments) {
		VariableDeclarationFragment frag = (VariableDeclarationFragment) o;
		String varName = frag.getName().getIdentifier();
		int line = cunit.getLineNumber(frag.getStartPosition());
		ASTNode parent = node.getParent();
		Scope scope = new Scope(cunit.getLineNumber(parent.getStartPosition()), getEndLine(parent, cunit));
		TypeDeclaration dec = (TypeDeclaration) node.getParent();
		String qName = dec.getName().getFullyQualifiedName();
		PackageDeclaration packageDec = cunit.getPackage();
		if(packageDec != null)
			qName = packageDec.getName().getFullyQualifiedName() + "." + qName;
		String type = !Modifier.isStatic(node.getModifiers()) ? qName : null; 
		VariableTags tags = new VariableTags(varName, type, line, scope, true);
		variables.add(tags);
	}
	return false;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:21,代碼來源:TagParser.java

示例7: visit

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
@Override
public boolean visit(ArrayAccess node) {
	String arrayName = node.getArray().toString();
	List<String> iterators = iteratorsByArray.get(arrayName);
	if(iterators == null) {
		iterators= new ArrayList<>(); 
	}
	
	String iteratorName = node.getIndex().getNodeType() == ASTNode.INFIX_EXPRESSION ?
			filterIteratorName((InfixExpression) node.getIndex()) : node.getIndex().toString();
	if(!iterators.contains(iteratorName)) {
		isArrayPrimitiveFigure = true;
		iterators.add(iteratorName);
		allIterators.add(iteratorName);
		iteratorsByArray.put(arrayName, iterators);
		System.out.println("A variavel " + iteratorName + " est� a iterar sobre a array: " + node.getArray().toString());
	}
	
	return super.visit(node);
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:21,代碼來源:TestParser.java

示例8: serializePosition

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
private void serializePosition(CompilationUnit cu, ASTNode node, JsonGenerator jG) throws IOException {
    final int startPosition = node.getStartPosition();
    jG.writeFieldName("startPosition");
    jG.writeNumber(startPosition);
    jG.writeFieldName("startLine");
    jG.writeNumber(cu.getLineNumber(startPosition));
    jG.writeFieldName("startColumn");
    jG.writeNumber(cu.getColumnNumber(startPosition) + 1); // 1-based numbering

    final int endPosition = startPosition + node.getLength();
    jG.writeFieldName("endPosition");
    jG.writeNumber(endPosition);
    jG.writeFieldName("endLine");
    jG.writeNumber(cu.getLineNumber(endPosition));
    jG.writeFieldName("endColumn");
    jG.writeNumber(cu.getColumnNumber(endPosition) + 1); // 1-based numbering
}
 
開發者ID:bblfsh,項目名稱:java-driver,代碼行數:18,代碼來源:CompilationUnitSerializer.java

示例9: structuralPropertyNamesOf

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
private static List<String> structuralPropertyNamesOf(final List<Class<? extends ASTNode>> nodes) {
    final List<String> names = new ArrayList<>();
    for (final Class<? extends ASTNode> node : nodes) {
        try {
            final Method m = node.getDeclaredMethod("propertyDescriptors", int.class);
            final List l = (List) m.invoke(null, AST.JLS8);
            for (final Object o : l) {
                final StructuralPropertyDescriptor d = (StructuralPropertyDescriptor) o;
                names.add(d.getId());
            }
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
            throw new RuntimeException("unexpected exception", ex);
        }
    }
    return names;
}
 
開發者ID:bblfsh,項目名稱:java-driver,代碼行數:17,代碼來源:GoGen.java

示例10: EclipseParser

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
/**
 * Creates a new EclipseParser
 *
 * @param sourceFile String of source file to read
 * @param outJ       JSON parsed out
 * @throws IOException when file can't be opened or errors in reading/writing
 */
public EclipseParser(String sourceFile, PrintStream outJ, boolean prettyprint) throws IOException {

    File file = new File(sourceFile);
    final BufferedReader reader = new BufferedReader(new FileReader(file));
    char[] source = IOUtils.toCharArray(reader);
    reader.close();
    this.parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(source);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);

    final JsonFactory jsonF = new JsonFactory();
    jG = jsonF.createGenerator(outJ);
    if (prettyprint) {
        jG.setPrettyPrinter(new DefaultPrettyPrinter());
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
    SimpleModule module = new SimpleModule();
    module.addSerializer(ASTNode.class, new NodeSerializer());
    mapper.registerModule(module);
}
 
開發者ID:bblfsh,項目名稱:java-driver,代碼行數:31,代碼來源:eclipseParser.java

示例11: serialize

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
@Override
public void serialize(ASTNode node, JsonGenerator jG, SerializerProvider provider) throws IOException {
    List<StructuralPropertyDescriptor> descriptorList = node.structuralPropertiesForType();
    nCount++;
    jG.writeStartObject();

    for (StructuralPropertyDescriptor descriptor : descriptorList) {
        Object child = node.getStructuralProperty(descriptor);
        if (child instanceof List) {
            serializeChildList((List<ASTNode>) child, descriptor, provider);
        } else if (child instanceof ASTNode) {
            serializeChild((ASTNode) child, descriptor, provider);
        } else if (child != null) {
            jG.writeFieldName(descriptor.getId());
            jG.writeString(child.toString());
        }
    }
    jG.writeEndObject();
}
 
開發者ID:bblfsh,項目名稱:java-driver,代碼行數:20,代碼來源:eclipseParser.java

示例12: endVisit

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
@Override
public void endVisit(CompilationUnit node) {
	ASTNode enclosingNode = null;
	if (!getStatus().hasFatalError() && hasSelectedNodes()) {
		enclosingNode= getEnclosingNode(getFirstSelectedNode());
	}

	super.endVisit(node);
	if (enclosingNode != null && !getStatus().hasFatalError()) {
		fExceptions = ExceptionAnalyzer.perform(enclosingNode, getSelection());
		if (fExceptions == null || fExceptions.length == 0) {
			if (enclosingNode instanceof MethodReference) {
				invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain);
			} else {
				fExceptions = new ITypeBinding[] { node.getAST().resolveWellKnownType("java.lang.Exception") }; //$NON-NLS-1$
			}
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:20,代碼來源:SurroundWithTryCatchAnalyzer.java

示例13: createFrom

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
public static LoadLiteral createFrom(ASTNode node) {
	LoadLiteral retNode = null;
	
	Adapter factory = Adapter.getInstance();

	// XXX. Check compatible types

	AstNode astNode = factory.get(node);
	if ( astNode instanceof LoadLiteral ) {
		retNode = (LoadLiteral)astNode;
	}
	else {
		retNode = LoadLiteral.create();
		
		retNode.complexExpression = node.toString();
		factory.map(node, retNode);
	}
	
	return retNode;
}
 
開發者ID:aroog,項目名稱:code,代碼行數:21,代碼來源:LoadLiteral.java

示例14: getNodeToInsertBefore

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
/**
 * Evaluates the insertion position of a new node.
 *
 * @param listRewrite The list rewriter to which the new node will be added
 * @param sibling The Java element before which the new element should be added.
 * @return the AST node of the list to insert before or null to insert as last.
 * @throws JavaModelException thrown if accessing the Java element failed
 */

public static ASTNode getNodeToInsertBefore(ListRewrite listRewrite, IJavaElement sibling) throws JavaModelException {
	if (sibling instanceof IMember) {
		ISourceRange sourceRange= ((IMember) sibling).getSourceRange();
		if (sourceRange == null) {
			return null;
		}
		int insertPos= sourceRange.getOffset();

		List<? extends ASTNode> members= listRewrite.getOriginalList();
		for (int i= 0; i < members.size(); i++) {
			ASTNode curr= members.get(i);
			if (curr.getStartPosition() >= insertPos) {
				return curr;
			}
		}
	}
	return null;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:28,代碼來源:StubUtility2.java

示例15: selectionChanged

import org.eclipse.jdt.core.dom.ASTNode; //導入依賴的package包/類
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
	if (selection instanceof ITextSelection) {
		ASTNode node = ASTUtils.getASTNode((ITextSelection) selection);
		if (node != null) {
			String string = node.toString();
			CharSequence subSequence = string.subSequence(0,
					string.length() > 100 ? 100 : string.length());
			RelatedObjectsEdges.this.setContentDescription(subSequence.toString()
					.trim());
			RelatedObjectsEdges.this.fTreeViewer.setInput(node);
			RelatedObjectsEdges.this.fTreeViewer.expandAll();
			RelatedObjectsEdges.this.tableViewer.setInput(null);
		}
	}

}
 
開發者ID:aroog,項目名稱:code,代碼行數:18,代碼來源:RelatedObjectsEdges.java


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