Example usage for org.eclipse.jdt.core.dom QualifiedName getLength

List of usage examples for org.eclipse.jdt.core.dom QualifiedName getLength

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom QualifiedName getLength.

Prototype

public final int getLength() 

Source Link

Document

Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.

Usage

From source file:com.windowtester.eclipse.ui.convert.WTConvertAPIContextNodeCreationTest.java

License:Open Source License

public void testNewName2() throws Exception {
    String source = getSource("original", "NewContactSwingTest.txt");
    WTConvertAPIContext context = new WTConvertAPIContextBuilder().buildContext(source);
    Name actual = context.newName("fully.qualified.TestClass", 83);
    assertTrue(actual instanceof QualifiedName);
    QualifiedName name = (QualifiedName) actual;
    assertEquals(83, name.getStartPosition());
    assertEquals(25, name.getLength());
    Name qualifier = name.getQualifier();
    assertEquals(83, qualifier.getStartPosition());
    assertEquals(15, qualifier.getLength());
    assertEquals(99, name.getName().getStartPosition());
    assertEquals(9, name.getName().getLength());
}

From source file:org.bundlemaker.core.ui.editor.sourceviewer.referencedetail.JdtAstVisitor.java

License:Open Source License

@Override
public boolean visit(QualifiedName node) {

    // access to static fields
    IBinding binding = node.resolveBinding();
    if (binding != null) {
        if (binding.getKind() == IBinding.VARIABLE) {
            IVariableBinding variableBinding = (IVariableBinding) binding;
            if (Flags.isStatic(variableBinding.getModifiers()) && variableBinding.getDeclaringClass() != null) {
                resolveTypeBinding(variableBinding.getDeclaringClass(), node.getStartPosition(),
                        node.getLength());
            }/*from   ww w  .j a  v  a2s  .c o m*/
            resolveTypeBinding(variableBinding.getType(), node.getStartPosition(), node.getLength());
        }
    }

    return true;
}

From source file:org.eclipse.wb.tests.designer.core.util.ast.AstEditorTest.java

License:Open Source License

public void test_ASTParser_parseQualifiedName() throws Exception {
    createTypeDeclaration_TestC("");
    AstParser parser = m_lastEditor.getParser();
    ////w  w  w  . jav  a2  s.  c  o  m
    QualifiedName qualifiedName = parser.parseQualifiedName(10, "a.b.c");
    assertEquals(10, qualifiedName.getStartPosition());
    assertEquals(5, qualifiedName.getLength());
    //
    check_SimpleName(qualifiedName.getName(), "c", 14, 1);
    qualifiedName = (QualifiedName) qualifiedName.getQualifier();
    //
    check_SimpleName(qualifiedName.getName(), "b", 12, 1);
    check_SimpleName((SimpleName) qualifiedName.getQualifier(), "a", 10, 1);
}

From source file:org.springframework.ide.vscode.boot.java.requestmapping.WebfluxMethodFinder.java

License:Open Source License

@Override
public boolean visit(MethodInvocation node) {
    boolean visitChildren = true;

    if (node != this.root) {
        IMethodBinding methodBinding = node.resolveMethodBinding();

        try {//ww w  .  j a va  2s. c om
            if (WebfluxUtils.REQUEST_PREDICATES_TYPE
                    .equals(methodBinding.getDeclaringClass().getBinaryName())) {
                String name = methodBinding.getName();
                if (name != null && WebfluxUtils.REQUEST_PREDICATE_HTTPMETHOD_METHODS.contains(name)) {
                    Range range = doc.toRange(node.getStartPosition(), node.getLength());
                    methods.add(new WebfluxRouteElement(name, range));
                } else if (name != null && WebfluxUtils.REQUEST_PREDICATE_METHOD_METHOD.equals(name)) {
                    QualifiedName qualifiedName = WebfluxUtils.extractQualifiedNameArgument(node);
                    if (qualifiedName.getName() != null) {
                        Range range = doc.toRange(qualifiedName.getStartPosition(), qualifiedName.getLength());
                        methods.add(new WebfluxRouteElement(qualifiedName.getName().toString(), range));
                    }
                }
            }
        } catch (BadLocationException e) {
            // ignore
        }

        if (WebfluxUtils.isRouteMethodInvocation(methodBinding)) {
            visitChildren = false;
        }
    }
    return visitChildren;
}

From source file:org.springframework.ide.vscode.boot.java.requestmapping.WebfluxRouterSymbolProvider.java

License:Open Source License

private WebfluxRouteElement[] extractMethods(MethodInvocation routerInvocation, TextDocument doc) {
    WebfluxMethodFinder methodFinder = new WebfluxMethodFinder(routerInvocation, doc);
    List<?> arguments = routerInvocation.arguments();
    for (Object argument : arguments) {
        if (argument != null && argument instanceof ASTNode) {
            ((ASTNode) argument).accept(methodFinder);
        }/*from w w w. j  a v a 2 s  .  c  o  m*/
    }

    final List<WebfluxRouteElement> methods = methodFinder.getMethods();

    extractNestedValue(routerInvocation, methods, (methodInvocation) -> {
        IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
        String methodName = methodBinding.getName();

        try {
            if (WebfluxUtils.REQUEST_PREDICATE_METHOD_METHOD.equals(methodName)) {
                QualifiedName qualifiedName = WebfluxUtils.extractQualifiedNameArgument(methodInvocation);
                if (qualifiedName.getName() != null) {
                    Range range = doc.toRange(qualifiedName.getStartPosition(), qualifiedName.getLength());
                    return new WebfluxRouteElement(qualifiedName.getName().toString(), range);
                }
            }
        } catch (BadLocationException e) {
            // ignore
        }

        return null;
    });

    return (WebfluxRouteElement[]) methods.toArray(new WebfluxRouteElement[methods.size()]);
}